/* ============================================================
   sidebar.css — Sidebar layout + Auth overlay
   Ported from market/sidebar.css — ProgInsight design system
   AI-specific additions: recents list, chat topbar, tier row
   ============================================================ */

/* ── Theme definitions ─────────────────────────────────────── */

:root,
[data-theme="light"] {
    --app-bg:            #F5F5F7;
    --surface-primary:   #FFFFFF;
    --surface-secondary: #F5F5F7;
    --surface-tertiary:  #E8E8ED;
    --text-primary:      #1D1D1F;
    --text-secondary:    #6E6E73;
    --text-tertiary:     #AEAEB2;
    --accent-color:      #111111;
    --accent-secondary:  #3A3A3C;
    --border-color:      #D2D2D7;
    --hover-bg:          #EBEBF0;
    --card-bg:           #FFFFFF;
    --card-image-bg:     #F5F5F7;
    --nav-bg:            rgba(255,255,255,0.88);
    --shadow-color:      rgba(0,0,0,0.08);
    --sidebar-bg:        #FFFFFF;
    --sidebar-border:    #E5E5EA;
    --sidebar-active-bg: #F0F0F5;
}

[data-theme="rose"] {
    --app-bg:            #FFF5F5;
    --surface-primary:   #FFFFFF;
    --surface-secondary: #FFF0F0;
    --surface-tertiary:  #FFE4E4;
    --text-primary:      #2D1515;
    --text-secondary:    #8B5E5E;
    --text-tertiary:     #C4A0A0;
    --accent-color:      #E84393;
    --accent-secondary:  #FF8FAB;
    --border-color:      #FACCCC;
    --hover-bg:          #FDEAEA;
    --card-bg:           #FFFFFF;
    --card-image-bg:     #FFF0F0;
    --nav-bg:            rgba(255,255,255,0.88);
    --shadow-color:      rgba(232,67,147,0.12);
    --sidebar-bg:        #FFFFFF;
    --sidebar-border:    #FACCCC;
    --sidebar-active-bg: #FFF0F0;
}

[data-theme="dracula"] {
    --app-bg:            #282a36;
    --surface-primary:   #21222c;
    --surface-secondary: #343746;
    --surface-tertiary:  #44475a;
    --text-primary:      #f8f8f2;
    --text-secondary:    #8b8fa8;
    --text-tertiary:     #6272a4;
    --accent-color:      #bd93f9;
    --accent-secondary:  #50fa7b;
    --border-color:      #44475a;
    --hover-bg:          #343746;
    --card-bg:           rgba(33,34,44,0.9);
    --card-image-bg:     #343746;
    --nav-bg:            rgba(40,42,54,0.88);
    --shadow-color:      rgba(0,0,0,0.5);
    --sidebar-bg:        #21222c;
    --sidebar-border:    #44475a;
    --sidebar-active-bg: #343746;
}

[data-theme="dark"] {
    --app-bg:            #000000;
    --surface-primary:   #1C1C1E;
    --surface-secondary: #2C2C2E;
    --surface-tertiary:  #3A3A3C;
    --text-primary:      #FFFFFF;
    --text-secondary:    rgba(235,235,245,0.6);
    --text-tertiary:     rgba(235,235,245,0.3);
    --accent-color:      #0A84FF;
    --accent-secondary:  #30D158;
    --border-color:      #38383A;
    --hover-bg:          #2C2C2E;
    --card-bg:           rgba(28,28,30,0.8);
    --card-image-bg:     #2C2C2E;
    --nav-bg:            rgba(0,0,0,0.7);
    --shadow-color:      rgba(0,0,0,0.6);
    --sidebar-bg:        #1C1C1E;
    --sidebar-border:    #38383A;
    --sidebar-active-bg: #2C2C2E;
}

[data-theme="midnight"] {
    --app-bg:            #0D1117;
    --surface-primary:   #161B22;
    --surface-secondary: #21262D;
    --surface-tertiary:  #30363D;
    --text-primary:      #E6EDF3;
    --text-secondary:    #7D8590;
    --text-tertiary:     #484F58;
    --accent-color:      #58A6FF;
    --accent-secondary:  #3FB950;
    --border-color:      #30363D;
    --hover-bg:          #21262D;
    --card-bg:           rgba(22,27,34,0.85);
    --card-image-bg:     #21262D;
    --nav-bg:            rgba(13,17,23,0.88);
    --shadow-color:      rgba(0,0,0,0.6);
    --sidebar-bg:        #161B22;
    --sidebar-border:    #30363D;
    --sidebar-active-bg: #21262D;
}

/* ── App Shell Layout ──────────────────────────────────────── */

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--app-bg);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

.app-shell {
    display: flex;
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

/* ── Sidebar ───────────────────────────────────────────────── */

.sidebar {
    width: 220px;
    min-width: 220px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 50;
    padding: 20px 12px;
    gap: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px 20px;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
}

.sidebar-logo-text {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-height: 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    width: 100%;
    text-decoration: none;
    transition: color 0.15s, background 0.15s;
    font-family: inherit;
    letter-spacing: -0.01em;
    min-height: 36px;
    flex-shrink: 0;
}

.sidebar-link:hover {
    color: var(--text-primary);
    background: var(--sidebar-active-bg);
}

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

/* Accent "New Chat" button */
.sidebar-link--accent {
    color: var(--accent-color);
    font-weight: 600;
}

.sidebar-link--accent:hover {
    color: var(--accent-color);
    background: var(--sidebar-active-bg);
}

.sidebar-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-link.active .sidebar-icon,
.sidebar-link:hover .sidebar-icon,
.sidebar-link--accent .sidebar-icon {
    opacity: 1;
}

.sidebar-link--muted {
    font-size: 12px;
    color: var(--text-tertiary);
}

.sidebar-link--muted:hover {
    color: var(--text-secondary);
}

.sidebar-bottom {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: auto;
    padding-top: 12px;
    flex-shrink: 0;
}

.sidebar-divider {
    height: 1px;
    background: var(--sidebar-border);
    margin: 8px 0;
    flex-shrink: 0;
}

/* ── Section label ─────────────────────────────────────────── */

.sidebar-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-tertiary);
    padding: 8px 12px 4px;
}

/* ── Recents list ──────────────────────────────────────────── */

.sidebar-recents {
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow-y: auto;
    max-height: 340px;
    flex: 1;
}

.sidebar-recents::-webkit-scrollbar { width: 3px; }
.sidebar-recents::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 2px; }

.recent-chat-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    width: 100%;
    font-family: inherit;
    transition: color 0.15s, background 0.15s;
    min-height: 32px;
}

.recent-chat-btn:hover {
    color: var(--text-primary);
    background: var(--sidebar-active-bg);
}

.recent-chat-btn.active {
    color: var(--accent-color);
    background: var(--sidebar-active-bg);
}

.recent-chat-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recent-chat-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text-tertiary);
    flex-shrink: 0;
    opacity: 0.5;
}

.recent-chat-delete {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-tertiary);
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.12s, color 0.12s;
    flex-shrink: 0;
    padding: 0;
    font-family: inherit;
}

.recent-chat-btn:hover .recent-chat-delete {
    opacity: 1;
}

.recent-chat-delete:hover {
    color: var(--text-primary);
}

.sidebar-recents-empty {
    padding: 6px 12px;
    font-size: 11px;
    color: var(--text-tertiary);
    font-style: italic;
}

/* ── Tier row ──────────────────────────────────────────────── */

.sidebar-tier-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    gap: 8px;
}

.sidebar-tier-badge {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    padding: 2px 7px;
    border-radius: 4px;
    background: var(--surface-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.sidebar-tier-badge.prem {
    color: #f59e0b;
    background: rgba(245,158,11,0.1);
    border-color: rgba(245,158,11,0.3);
}

.sidebar-tier-badge.pro {
    color: #a78bfa;
    background: rgba(167,139,250,0.1);
    border-color: rgba(167,139,250,0.3);
}

.sidebar-upgrade-link {
    font-size: 11px;
    font-weight: 500;
    color: var(--accent-color);
    text-decoration: none;
}

.sidebar-upgrade-link:hover { opacity: 0.75; }

/* ── Customize Panel ───────────────────────────────────────── */

.sidebar-settings-wrap {
    position: relative;
}

/* ── Main Content ──────────────────────────────────────────── */

.main-content {
    margin-left: 220px;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: var(--app-bg);
}

/* ── Chat Topbar ───────────────────────────────────────────── */

.chat-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 52px;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface-primary);
    flex-shrink: 0;
}

.chat-topbar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 60%;
}

.chat-topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-pill {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--border-color);
    transition: background 0.3s;
}

.status-dot.ready   { background: #30D158; }
.status-dot.loading { background: var(--accent-color); animation: dot-pulse 1s infinite; }
.status-dot.error   { background: #FF453A; }

@keyframes dot-pulse {
    0%,100% { opacity: 1; }
    50%      { opacity: 0.3; }
}

.status-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

.topbar-tier-badge {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    padding: 2px 8px;
    border-radius: 4px;
}

.tier-free { color: var(--text-tertiary); background: var(--surface-secondary); border: 1px solid var(--border-color); }
.tier-pro  { color: #a78bfa; background: rgba(167,139,250,0.1); border: 1px solid rgba(167,139,250,0.3); }
.tier-prem { color: #f59e0b; background: rgba(245,158,11,0.1);  border: 1px solid rgba(245,158,11,0.3); }
.tier-byok { color: #30D158; background: rgba(48,209,88,0.1);   border: 1px solid rgba(48,209,88,0.3); }

/* ── Auth Overlay (Market-style) ───────────────────────────── */

.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.auth-overlay--open {
    opacity: 1;
    pointer-events: auto;
}

.auth-shell {
    background: var(--surface-primary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    width: 100%;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.auth-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px 14px;
    border-bottom: 1px solid var(--border-color);
}

.auth-logo-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.auth-title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.auth-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-tertiary);
    font-size: 14px;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    transition: background 0.12s, color 0.12s;
}

.auth-close:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.auth-tabs {
    display: flex;
    gap: 0;
    padding: 12px 24px 0;
}

.auth-tab {
    flex: 1;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-family: inherit;
    transition: color 0.15s, border-color 0.15s;
    text-align: center;
}

.auth-tab--active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
    font-weight: 600;
}

.auth-body {
    padding: 20px 24px 0;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-reason {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    line-height: 1.5;
}

.auth-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.auth-input {
    width: 100%;
    background: var(--surface-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    color: var(--text-primary);
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

.auth-input:focus {
    border-color: var(--accent-color);
}

.auth-input::placeholder {
    color: var(--text-tertiary);
}

.auth-submit {
    width: 100%;
    padding: 12px 16px;
    border-radius: 10px;
    background: var(--accent-color);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.15s, transform 0.12s;
    margin-top: 4px;
}

.auth-submit:hover { opacity: 0.88; transform: scale(1.01); }
.auth-submit:active { transform: scale(0.98); }

.auth-forgot {
    font-size: 12px;
    color: var(--accent-color);
    text-decoration: none;
    text-align: center;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 4px 0;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.auth-divider span {
    font-size: 11px;
    color: var(--text-tertiary);
}

.auth-oauth-btn {
    width: 100%;
    padding: 10px 16px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--surface-secondary);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-family: inherit;
    transition: border-color 0.15s, background 0.15s;
}

.auth-oauth-btn:hover:not(:disabled) {
    border-color: var(--accent-color);
}

.auth-oauth-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.auth-msg {
    font-size: 12px;
    padding: 9px 12px;
    border-radius: 8px;
    margin-bottom: 4px;
    line-height: 1.5;
    display: none;
}

.auth-msg.error   { background: rgba(255,69,58,0.08);  border: 1px solid rgba(255,69,58,0.3);  color: #FF453A;  display: block; }
.auth-msg.loading { background: color-mix(in srgb, var(--accent-color) 8%, transparent); border: 1px solid color-mix(in srgb, var(--accent-color) 30%, transparent); color: var(--accent-color); display: block; }
.auth-msg.success { background: rgba(48,209,88,0.08);  border: 1px solid rgba(48,209,88,0.3);  color: #30D158;  display: block; }

.auth-otp-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}

.auth-otp-hint {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    margin: 0;
}

.auth-otp-input {
    letter-spacing: 0.3em;
    text-align: center;
    font-size: 18px;
}

.auth-ghost-btn {
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: color 0.15s;
    text-align: center;
    margin-top: 4px;
}

.auth-ghost-btn:hover { color: var(--text-primary); }

.auth-footer {
    font-size: 11px;
    color: var(--text-tertiary);
    text-align: center;
    padding: 16px 24px 20px;
    line-height: 1.8;
}

.auth-footer a {
    color: var(--accent-color);
    text-decoration: none;
}

/* ── Responsive ─────────────────────────────────────────────── */

@media (max-width: 768px) {
    .sidebar {
        width: 56px;
        min-width: 56px;
        padding: 16px 8px;
    }

    .sidebar-logo-text,
    .sidebar-link span,
    .sidebar-link--muted span,
    .sidebar-section-label,
    .sidebar-recents,
    .sidebar-tier-row {
        display: none;
    }

    .sidebar-logo {
        justify-content: center;
        padding: 8px 0 20px;
    }

    .sidebar-link {
        justify-content: center;
        padding: 10px;
    }

    .main-content {
        margin-left: 56px;
    }
}
