/* === Foundation Design Tokens (Phase 10) === */
:root {
    /* Z-index scale — backdrop < drawer < hamburger < toast */
    --z-backdrop:     900;
    --z-drawer:      1050;   /* trên drafting loading-overlay (1000) */
    --z-hamburger:   1051;
    --z-toast:       9999;
    /* Tap target */
    --tap-target-min: 44px;
    /* Canonical breakpoints — quy ước: mobile <768 / tablet 768-1023 / desktop >=1024 */
    --bp-mobile:  768px;
    --bp-tablet: 1024px;
    /* Sidebar */
    --sidebar-width: 280px;
    /* Safe-area helpers — trả 0px nếu thiết bị không có safe-area */
    --sa-top:    env(safe-area-inset-top,    0px);
    --sa-bottom: env(safe-area-inset-bottom, 0px);
    --sa-left:   env(safe-area-inset-left,   0px);
    --sa-right:  env(safe-area-inset-right,  0px);
}

/* Navigation Sidebar */
#sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;   /* fallback browser cũ */
    height: 100dvh;  /* dvh: không bị browser chrome thu nhỏ */
    background: #f7f7f8;
    border-right: 1px solid #ebebeb;
    padding: calc(14px + var(--sa-top)) 12px calc(14px + var(--sa-bottom)) calc(12px + var(--sa-left));
    display: flex;
    flex-direction: column;
    z-index: var(--z-drawer);
    transition: transform 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.nav-brand {
    padding: 6px 8px 16px 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-icon {
    font-size: 24px;
}

.nav-title {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
    color: #1a1a1a;
}

.nav-section {
    padding: 6px 0;
    border-bottom: none;
    flex-shrink: 0;
}

.nav-section-title {
    padding: 10px 8px 6px;
    font-size: 12px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    min-height: var(--tap-target-min);
    color: #1f2937;
    text-decoration: none;
    transition: background 0.15s;
    border-left: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 400;
    line-height: 1.4;
}

/* De-emphasize admin nav section */
.nav-section + .nav-section {
    padding: 4px 0;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.nav-section + .nav-section:hover {
    opacity: 1;
}

.nav-section + .nav-section .nav-item {
    color: #9ca3af;
    font-size: 14px;
    padding: 6px 10px;
    font-weight: 400;
}

.nav-section + .nav-section .nav-section-title {
    font-size: 11px;
    padding: 4px 8px 4px;
    color: #9ca3af;
}

.nav-item:hover {
    background: #ececec;
}

/* Temporarily disabled nav items — hover still works, click does nothing */
.nav-item--disabled {
    opacity: 0.45;
    cursor: default !important;
}

.nav-item--disabled:hover {
    background: #ececec;
    cursor: default !important;
}

.nav-item.active {
    background: #ececec;
    font-weight: 500;
}

.nav-item-icon {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-item-icon svg {
    width: 18px;
    height: 18px;
    stroke: #6e6e80;
    fill: none;
    stroke-width: 1.5;
}

.nav-item-text {
    font-size: 15px;
    line-height: 1.4;
}

.nav-section + .nav-section .nav-item-text {
    font-size: 14px;
    line-height: 1.4;
}

.nav-footer {
    margin-top: 0;
    flex-shrink: 0;
    padding: 12px 8px;
    border-top: 1px solid #ebebeb;
}

.nav-user {
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
}

.nav-logout {
    width: 100%;
    padding: 8px;
    min-height: var(--tap-target-min);
    background: transparent;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: #353740;
    transition: background 0.15s;
}

.nav-logout:hover {
    background: #ececec;
}

/* --- New Chat button --- */
.new-chat-btn {
    width: 100%;
    margin: 0 0 10px 0;
    padding: 10px 12px;
    background: transparent;
    color: #1a1a1a;
    border: 1px solid #e5e5e5;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    font-size: 15px;
    font-weight: 500;
    transition: background 0.15s;
}

.new-chat-btn:hover { background: #ececec; }

.new-chat-btn svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2; fill: none; }

/* Three-zone: middle zone grows and scrolls */
#conversation-list {
    flex: 1 1 0;
    overflow-y: auto;
    min-height: 0;
    max-height: 35vh;
    padding: 4px 0;
}

/* --- Conversation list items --- */
.date-group-label {
    font-size: 12px;
    color: #9ca3af;
    padding: 12px 8px 6px;
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f7f7f8;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.conversation-item {
    height: 44px;
    padding: 0 10px;
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.conversation-item:hover { background: #ececec; }

.conversation-item.active { background: #e8e8e8; color: #1a1a1a; font-weight: normal; }

.conversation-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 400; line-height: 1.4; color: #1a1a1a; }

.conversation-actions { display: none; gap: 4px; }
.conversation-item:hover .conversation-actions { display: flex; }

.action-icon { width: 16px; height: 16px; cursor: pointer; padding: 4px; border-radius: 3px; }
.action-icon:hover { background: #d5d5d5; }
.action-icon svg { width: 100%; height: 100%; stroke: #666; stroke-width: 2; fill: none; }

/* Inline rename input (ChatGPT-style) */
.conversation-rename-input {
    flex: 1;
    min-width: 0;
    height: 28px;
    padding: 2px 8px;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.4;
    font-family: inherit;
    color: #1a1a1a;
    background: #ffffff;
    border: 1px solid #c5c5d2;
    border-radius: 6px;
    outline: none;
    box-sizing: border-box;
}

.conversation-rename-input:focus {
    border-color: #10a37f;
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.15);
}

/* Hamburger Button */
.hamburger {
    display: none;
    position: fixed;
    top: calc(15px + var(--sa-top));
    left: calc(15px + var(--sa-left));
    z-index: var(--z-hamburger);
    background: #2196F3;
    color: white;
    border: none;
    min-width: var(--tap-target-min);
    min-height: var(--tap-target-min);
    padding: 10px 15px;
    font-size: 20px;
    cursor: pointer;
    border-radius: 4px;
}

/* Drawer backdrop — injected by utils.js at runtime (Phase 10) */
.backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-backdrop);
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}
.backdrop.visible {
    display: block;
    opacity: 1;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #sidebar {
        transform: translateX(-100%);
    }

    #sidebar.open {
        transform: translateX(0);
    }

    .hamburger {
        display: block;
    }
}

/* Loading Indicators */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #2196F3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-message {
    height: 60px;
    margin: 10px 0;
    border-radius: 8px;
}

.skeleton-chart {
    height: 300px;
    border-radius: 8px;
}

/* Toast Notifications */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 5px;
    color: white;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s;
    z-index: 9999;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast-success {
    background: #4caf50;
}

.toast-error {
    background: #f44336;
}

.toast-info {
    background: #2196f3;
}

/* Phase 23 — Trash badge (sidebar menu) */
.nav-item .trash-badge {
    margin-left: auto;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}
.nav-item .trash-badge[hidden] {
    display: none !important;
}
