/* ============================================================
   NoteApp - Giao diện hiện đại, nhất quán, chuẩn Responsive & Accessibility
   ============================================================ */

:root {
    --sidebar-width: 260px;
    --navbar-height: 64px;
    --user-note-color: #ffffff;
    --note-radius: 14px;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    overflow-x: hidden;
    background-color: var(--bs-tertiary-bg);
}

/* --- Accessibility: Skip link & Focus visible --- */
.skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 2000;
    padding: 8px 16px;
    background: var(--bs-primary);
    color: #fff;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
}

:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
}

/* --- Thang chữ theo vai trò (Operate): tiêu đề trang > tiêu đề thẻ > nội dung > metadata --- */
.app-main h1 {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.015em;
    text-wrap: balance;
}

.app-main h2.h6,
.app-main h2.h5 {
    text-wrap: balance;
}

.note-card-content,
.ai-summary-text,
.ai-answer-content {
    text-wrap: pretty;
}

/* Số liệu thời gian canh thẳng hàng giữa các thẻ */
.note-card-footer,
.badge {
    font-variant-numeric: tabular-nums;
}

/* Bôi chọn văn bản theo bảng màu của ứng dụng */
::selection {
    background-color: rgba(var(--bs-primary-rgb), 0.22);
    color: var(--bs-emphasis-color);
}

textarea,
input {
    caret-color: var(--bs-primary);
}

/* --- Cỡ chữ tùy chọn của người dùng --- */
.font-size-small { font-size: 0.9rem; }
.font-size-medium { font-size: 1rem; }
.font-size-large { font-size: 1.125rem; }

.font-size-small .note-card-content,
.font-size-small .note-textarea { font-size: 0.875rem; }

.font-size-large .note-card-title { font-size: 1.25rem; }
.font-size-large .note-card-content,
.font-size-large .note-textarea { font-size: 1.12rem; }

/* --- Navbar --- */
.app-navbar {
    min-height: var(--navbar-height);
    position: sticky;
    top: 0;
    z-index: 1030;
    background-color: var(--bs-body-bg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.app-search-wrap {
    max-width: 520px;
}

.search-input-group .input-group-text,
.search-input-group .form-control {
    border-radius: 999px;
}

.search-input-group .input-group-text {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    padding-left: 14px;
}

.search-input-group .form-control {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.search-input-group .form-control:focus {
    box-shadow: none;
    border-color: var(--bs-border-color);
}

/* Đảm bảo vùng chạm tối thiểu trên thiết bị cảm ứng */
.btn-icon {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--bs-body-color);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.btn-icon:hover {
    background-color: var(--bs-secondary-bg);
}

.btn-icon.btn-sm {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
}

.avatar-sm {
    width: 36px;
    height: 36px;
    object-fit: cover;
}

/* --- Bố cục Sidebar + Nội dung chính --- */
.app-layout {
    display: flex;
    min-height: calc(100vh - var(--navbar-height));
}

.app-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    padding: 16px 10px;
    background-color: var(--bs-body-bg);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 12px;
    color: var(--bs-body-color);
    text-decoration: none;
    min-height: 44px;
    font-weight: 500;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-link:hover {
    background-color: var(--bs-secondary-bg);
}

.sidebar-link.active {
    background-color: var(--bs-primary-bg-subtle);
    color: var(--bs-primary);
    font-weight: 600;
}

.sidebar-section {
    margin-top: 20px;
}

.sidebar-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--bs-secondary-color);
    margin-bottom: 6px;
}

.app-main {
    flex: 1;
    padding: 24px;
    min-width: 0;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1040;
    backdrop-filter: blur(2px);
}

/* --- Responsive: Tablet & Smartphone --- */
@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        top: var(--navbar-height);
        left: 0;
        bottom: 0;
        z-index: 1045;
        transform: translateX(-100%);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }

    .app-sidebar.show {
        transform: translateX(0);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .app-main {
        padding: 18px 16px;
    }
}

@media (max-width: 575.98px) {
    .app-main {
        padding: 14px 12px;
    }

    .app-search-wrap .form-control::placeholder {
        font-size: 0.85rem;
    }

    .btn, .form-control, .form-select {
        min-height: 44px;
    }
}

/* --- Trang khách (Auth) --- */
.guest-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bs-tertiary-bg) 0%, var(--bs-secondary-bg) 100%);
    padding: 20px 14px;
}

.guest-wrapper {
    width: 100%;
    max-width: 440px;
}

.guest-card {
    background: var(--bs-body-bg);
    border-radius: 18px;
    padding: 32px 28px;
    border: 1px solid var(--bs-border-color-translucent);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}

@media (max-width: 575.98px) {
    .guest-card {
        padding: 24px 18px;
    }
}

.guest-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 20px;
    justify-content: center;
}

.letter-spacing-otp {
    letter-spacing: 0.35em;
}

/* --- Danh sách ghi chú: Lưới (Grid) & Danh sách (List) --- */
.notes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    align-items: stretch;
}

@media (max-width: 575.98px) {
    .notes-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

.notes-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 880px;
}

/* Thẻ ghi chú + Áp dụng màu ghi chú của người dùng */
.note-card {
    position: relative;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--note-radius);
    background-color: var(--bs-body-bg);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    overflow: hidden;
}

[data-bs-theme="light"] body.has-custom-note-color .note-card,
[data-bs-theme="light"] body.has-custom-note-color .note-editor-surface {
    background-color: var(--user-note-color);
}

/* Chế độ tối: pha màu ghi chú vào nền thay vì viền trên (tránh xung đột với góc bo) */
[data-bs-theme="dark"] body.has-custom-note-color .note-card,
[data-bs-theme="dark"] body.has-custom-note-color .note-editor-surface {
    background-color: color-mix(in srgb, var(--user-note-color) 14%, var(--bs-body-bg));
    border-color: color-mix(in srgb, var(--user-note-color) 35%, var(--bs-border-color));
}

.note-card-pinned {
    border-color: rgba(var(--bs-primary-rgb), 0.45);
}

.note-card:hover,
.note-card:has(.note-card-link:focus-visible) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
    border-color: rgba(var(--bs-primary-rgb), 0.5);
}

.note-card-link {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: 16px 16px 56px;
    color: inherit;
    text-decoration: none;
}

.shared-note-card .note-card-link {
    padding-bottom: 16px;
}

.notes-list .note-card-link {
    padding: 14px 18px 54px;
}

.note-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
}

.note-card-title {
    font-size: 1.0625rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

.note-card-icons {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    font-size: 0.95rem;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Icon trạng thái: dùng token chữ đậm của Bootstrap để đạt tương phản >= 3:1 ở cả hai giao diện */
.status-badge.text-warning { color: var(--bs-warning-text-emphasis) !important; }
.status-badge.text-success { color: var(--bs-success-text-emphasis) !important; }
.status-badge.text-primary { color: var(--bs-primary-text-emphasis) !important; }

/* Thẻ ghi chú khóa là <button> (không phải link giả href="#"): đặt lại kiểu mặc định của nút */
button.note-card-link {
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    font: inherit;
    cursor: pointer;
}

#notesContainer:focus {
    outline: none;
}

.note-card-content {
    font-size: 0.92rem;
    color: var(--bs-secondary-color);
    margin: 0 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    white-space: pre-line;
    word-break: break-word;
    flex-grow: 1;
}

.notes-list .note-card-content {
    -webkit-line-clamp: 2;
}

.note-card-labels {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.note-label-badge {
    background-color: var(--bs-secondary-bg);
    color: var(--bs-emphasis-color);
    border: 1px solid var(--bs-border-color);
    font-weight: 500;
    font-size: 0.75rem;
}

.note-card-footer {
    font-size: 0.8rem;
    margin-top: auto;
}

/* Nút Ghim / Xóa trên thẻ: vùng chạm tối thiểu 44x44px, tách khỏi vùng bấm mở ghi chú */
.note-card-actions {
    position: absolute;
    bottom: 4px;
    right: 6px;
    display: flex;
    gap: 4px;
}

.note-card-actions .btn-icon.btn-sm {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
}

.note-card-actions .btn-icon:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: 1px;
}

/* --- Trình soạn thảo ghi chú --- */
.note-editor-surface {
    border-radius: 16px;
}

#noteTitle:focus,
#noteContent:focus {
    box-shadow: none;
}

.note-textarea {
    resize: vertical;
    min-height: 260px;
    line-height: 1.65;
}

.label-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1px solid var(--bs-border-color);
    border-radius: 999px;
    background-color: var(--bs-body-bg);
    cursor: pointer;
    font-size: 0.85rem;
    user-select: none;
    transition: all 0.15s ease;
}

.label-chip:has(input:checked) {
    background-color: var(--bs-primary-bg-subtle);
    border-color: var(--bs-primary);
    color: var(--bs-primary-text-emphasis);
    font-weight: 600;
}

/* --- Khu vực Tệp đính kèm (Ảnh, Video, File) --- */
.attachment-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.attachment-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--bs-border-color);
    border-radius: 12px;
    background-color: var(--bs-body-bg);
    text-align: center;
}

.attachment-thumb {
    width: 100%;
    height: 110px;
    object-fit: cover;
    border-radius: 8px;
}

.attachment-video {
    width: 100%;
    max-height: 120px;
    border-radius: 8px;
    background: #000;
}

.attachment-file-icon {
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attachment-name {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: inherit;
    text-decoration: none;
}

.attachment-name:hover {
    text-decoration: underline;
    color: var(--bs-primary);
}

.btn-remove-attachment {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    background: var(--bs-danger);
    color: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.btn-remove-attachment:hover {
    background: #bb2d3b;
    color: #fff;
}

/* --- WebSocket Realtime Presence Dot --- */
.collab-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #198754;
    display: inline-block;
}

/* --- AI Summary & AI Q&A --- */
.ai-summary-text,
.ai-answer-content {
    white-space: pre-line;
    line-height: 1.65;
}

.ai-ref-card {
    display: block;
    padding: 12px 14px;
    border: 1px solid var(--bs-border-color);
    border-radius: 10px;
    background-color: var(--bs-body-bg);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s ease, transform 0.15s ease;
    height: 100%;
}

.ai-ref-card:hover {
    border-color: var(--bs-primary);
    transform: translateY(-1px);
}

/* --- Bảng chọn màu ghi chú trong Tùy chọn --- */
.color-swatch-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--bs-border-color);
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.color-swatch-btn:hover {
    transform: scale(1.08);
}

.color-swatch-btn.active {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), 0.25);
}

.empty-state {
    background: var(--bs-body-bg);
    border: 1px dashed var(--bs-border-color);
    border-radius: 16px;
    padding: 48px 20px;
}
