/* ===== CSS Variables ===== */
:root {
    --bg: #0d1117;
    --bg-card: #161b22;
    --bg-sidebar: #0f0f1a;
    --bg-secondary: #161b22;
    --bg-input: #21262d;
    --bg-primary: #161b22;
    --text: #e6edf3;
    --text-secondary: #c9d1d9;
    --text-muted: #8b949e;
    --green-primary: #2ecc71;
    --green-hover: #27ae60;
    --primary: #2ea44f;
    --primary-hover: #3fb950;
    --accent: #58a6ff;
    --accent-secondary: #a78bfa;
    --danger: #f85149;
    --danger-hover: #c0392b;
    --warning: #f0ad4e;
    --border: #30363d;
    --border-color: #333;
    --on-primary: #ffffff;
    --radius: 8px;
    --sidebar-width: 280px;
}

/* ===== Light Theme Override ===== */
/* Activated via data-theme="light" attribute on <html>, or automatically
   via prefers-color-scheme when no explicit preference is stored. */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg: #f6f8fa;
        --bg-card: #ffffff;
        --bg-sidebar: #f0f2f5;
        --bg-secondary: #ffffff;
        --bg-input: #e9eaee;
        --bg-primary: #ffffff;
        --text: #1f2328;
        --text-secondary: #424a53;
        --text-muted: #636c76;
        --green-primary: #1a7f37;
        --green-hover: #16834a;
        --primary: #2da44e;
        --primary-hover: #218838;
        --accent: #0969da;
        --accent-secondary: #7c3aed;
        --danger: #cf222e;
        --danger-hover: #a40c1a;
        --warning: #bf8700;
        --border: #d0d7de;
        --border-color: #d8dee4;
        --on-primary: #ffffff;
    }
}

:root[data-theme="light"] {
    --bg: #f6f8fa;
    --bg-card: #ffffff;
    --bg-sidebar: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-input: #e9eaee;
    --bg-primary: #ffffff;
    --text: #1f2328;
    --text-secondary: #424a53;
    --text-muted: #636c76;
    --green-primary: #1a7f37;
    --green-hover: #16834a;
    --primary: #2da44e;
    --primary-hover: #218838;
    --accent: #0969da;
    --accent-secondary: #7c3aed;
    --danger: #cf222e;
    --danger-hover: #a40c1a;
    --warning: #bf8700;
    --border: #d0d7de;
    --border-color: #d8dee4;
    --on-primary: #ffffff;
}

/* Theme toggle button */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text);
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.theme-toggle:hover { border-color: var(--text-muted); }
.theme-toggle .theme-icon-dark { display: none; }
:root[data-theme="light"] .theme-toggle .theme-icon-dark { display: inline; }
:root[data-theme="light"] .theme-toggle .theme-icon-light { display: none; }

/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
}
body {
    overscroll-behavior-y: contain;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

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

a:hover {
    text-decoration: underline;
}

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-decoration: none;
    line-height: 1.5;
}
.btn-primary {
    background: var(--primary);
    color: var(--on-primary);
}
.btn-primary:hover {
    background: var(--primary-hover);
    text-decoration: none;
}
.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-outline:hover {
    border-color: var(--text-muted);
    text-decoration: none;
}
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-full { display: block; text-align: center; width: 100%; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

/* ===== Flash Messages ===== */
.flash-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.flash {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    animation: flashIn 0.3s ease;
}
.flash-success { background: rgba(46, 204, 113, 0.15); border: 1px solid var(--green-primary); color: var(--green-primary); }
.flash-error { background: rgba(248, 81, 73, 0.15); border: 1px solid var(--danger); color: var(--danger); }
.flash-info { background: rgba(88, 166, 255, 0.15); border: 1px solid var(--accent); color: var(--accent); }
@keyframes flashIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Landing Page ===== */
.landing {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.landing-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border);
}
.landing-nav .nav-brand {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}
.landing-nav .nav-links {
    display: flex;
    gap: 0.75rem;
}

/* Hero Section */
.hero {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    gap: 3rem;
    max-width: 1100px;
    margin: 0 auto;
    flex: 1;
}
.hero-content {
    max-width: 540px;
}
.hero-content h1 {
    font-size: 3rem;
    line-height: 1.2;
    margin-bottom: 1rem;
}
.hero-content .highlight {
    color: var(--green-primary);
}
.hero-content p {
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    line-height: 1.7;
}

/* Hero Graphic */
.hero-graphic {
    position: relative;
    width: 280px;
    height: 280px;
    flex-shrink: 0;
}
.eco-orb {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, rgba(46, 204, 113, 0.3), rgba(46, 204, 113, 0.05));
    animation: orbPulse 4s ease-in-out infinite;
}
.eco-orb-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
}
@keyframes orbPulse {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.05); opacity: 1; }
}

/* Features */
.features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    padding: 3rem 2rem;
    max-width: 1100px;
    margin: 0 auto;
}
.feature-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
}
.feature-icon {
    font-size: 2rem;
    margin-bottom: 1rem;
}
.feature-card h3 {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}
.feature-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Landing Footer */
.landing-footer {
    text-align: center;
    padding: 2rem;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: auto;
}
.landing-footer a {
    color: var(--text-muted);
    text-decoration: none;
}
.landing-footer a:hover {
    color: var(--text);
    text-decoration: underline;
}
.landing-footer p {
    margin-top: 0.5rem;
}

/* ===== Auth Pages ===== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}
.auth-brand {
    display: block;
    text-align: center;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--green-primary);
    text-decoration: none;
    margin-bottom: 1rem;
}
.auth-card h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 1.3rem;
}
.auth-flash {
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.85rem;
}
.auth-flash-error { background: rgba(248, 81, 73, 0.15); border: 1px solid var(--danger); color: var(--danger); }
.auth-flash-success { background: rgba(46, 204, 113, 0.15); border: 1px solid var(--green-primary); color: var(--green-primary); }

/* Form Groups */
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.form-group input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}
.form-group input:focus {
    border-color: var(--green-primary);
}
.hp-field {
    position: absolute;
    left: -9999px;
    opacity: 0;
    height: 0;
    overflow: hidden;
}
.auth-switch {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.auth-switch a {
    color: var(--accent);
}

/* ===== App Layout (Dashboard + Chat) ===== */
.app-layout {
    display: flex;
    height: 100%;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}
.sidebar-header {
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 56px;
    box-sizing: border-box;
}
.sidebar-brand {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--green-primary);
    text-decoration: none;
    padding: 16px 0 16px 16px;
}
.sidebar-brand:hover {
    text-decoration: none;
}
.sidebar-actions {
    padding: 12px 16px;
}

/* Sidebar Search */
.sidebar-search {
    padding: 8px 12px;
    position: relative;
}
.sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
}
.sidebar-search input:focus {
    border-color: var(--green-primary);
}
.sidebar-search-results {
    display: none;
    position: absolute;
    left: 12px;
    right: 12px;
    top: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
}
.sidebar-search-results.active {
    display: block;
}
.search-result {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}
.search-result:hover {
    background: var(--bg-input);
    text-decoration: none;
}
.search-result-icon {
    flex-shrink: 0;
}
.search-result-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.search-empty {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.search-locked {
    text-align: center;
    padding: 12px;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    background: var(--bg-input);
    border-radius: var(--radius);
    margin: 4px 12px;
}
.search-locked:hover {
    color: var(--accent);
}
.sidebar-search-locked {
    padding: 0 12px;
}

/* Sidebar Threads */
.sidebar-threads {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}
.thread-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.15s;
}
.thread-item:hover {
    background: rgba(255,255,255,0.03);
    text-decoration: none;
}
.thread-item.active {
    background: rgba(46, 204, 113, 0.08);
    color: var(--text);
}
.thread-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-right: 8px;
}
.thread-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
}
/* Pulsing dot on threads with an in-flight generation (driven by /jobs/active). */
.thread-item.generating .thread-title::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent, #2ecc71);
    margin-right: 6px;
    vertical-align: middle;
    animation: dotPulse 1.4s infinite ease-in-out;
}
.thread-rename-input {
    flex: 1;
    margin-right: 8px;
    background: var(--bg-primary);
    border: 2px solid var(--accent, #2ea44f);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.85rem;
    padding: 2px 6px;
    outline: none;
    box-shadow: 0 0 0 2px rgba(46, 164, 79, 0.15);
}
.sidebar-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 1rem;
    font-size: 0.85rem;
}

/* Loading skeletons (#155) */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-secondary, #161b22) 25%,
        var(--bg-tertiary, #21262d) 50%,
        var(--bg-secondary, #161b22) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 6px;
}
.skeleton-text { height: 1rem; margin-bottom: 0.5rem; }
.skeleton-card {
    height: 80px;
    border-radius: 12px;
    margin-bottom: 1rem;
}
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Toast notification system (#154) */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--on-primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
    animation: toastIn 0.25s ease-out;
    max-width: 360px;
}
.toast.toast-success { background: var(--accent, #2ea44f); }
.toast.toast-error { background: var(--danger); }
.toast.toast-info { background: var(--bg-secondary, #161b22); border: 1px solid var(--border); }
@keyframes toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes toastOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* Billing page classes (#140) */
.billing-api-credits {
    margin-top: 1.5rem;
}
.billing-api-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.billing-api-desc {
    font-size: 0.85rem;
    opacity: 0.8;
    margin: 0.25rem 0 0;
}

/* Workspace modal disabled button (#131) */
.ws-modal .btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.user-name {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.admin-link {
    font-size: 0.8rem;
    color: var(--accent);
    text-decoration: none;
    margin-bottom: 4px;
}
.admin-link:hover {
    text-decoration: underline;
}
/* Sidebar footer icon buttons (Issue #60) */
.sidebar-footer-actions {
    display: flex;
    gap: 4px;
}
.sidebar-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    color: var(--text-muted);
    text-decoration: none;
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.sidebar-icon-btn:hover {
    background: var(--bg-hover, rgba(0,0,0,0.05));
    color: var(--text);
}
.sidebar-icon-btn svg {
    width: 18px;
    height: 18px;
}


/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ===== Dashboard ===== */
.dashboard-main {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.dashboard-header h2 {
    font-size: 1.3rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.dashboard-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Search Bar */
.search-bar {
    display: flex;
    gap: 8px;
    align-items: center;
}
.search-bar input {
    padding: 6px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
}
.search-bar input:focus {
    border-color: var(--green-primary);
}
.search-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 16px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}
.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 4px;
}
.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.stat-link {
    text-decoration: none;
    color: inherit;
}
.stat-link:hover {
    text-decoration: none;
}
.stat-card.highlight {
    border-color: var(--green-primary);
}
.stat-card.error-highlight {
    border-color: var(--danger);
}

/* Tier Badge */
.tier-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}
.tier-free {
    background: rgba(139, 148, 158, 0.15);
    color: var(--text-muted);
}
.tier-premium {
    background: rgba(46, 204, 113, 0.15);
    color: var(--green-primary);
}
.tier-badge-sm {
    font-size: 0.65rem;
    padding: 1px 6px;
}

/* Thread Grid */
.thread-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
    gap: 16px;
}
.thread-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    position: relative;
    transition: border-color 0.2s;
    overflow: hidden;
    max-width: 100%;
    min-width: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.thread-card:hover {
    border-color: var(--text-muted);
}
.thread-card a {
    color: inherit;
    text-decoration: none;
}
.thread-card a:hover {
    text-decoration: none;
}
.thread-card h3 {
    font-size: 1rem;
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.thread-card-meta {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
    overflow-wrap: break-word;
    min-width: 0;
}
.thread-card-snippet {
    margin-top: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.btn-delete {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    opacity: 0;
    transition: opacity 0.2s;
}
.thread-card:hover .btn-delete {
    opacity: 1;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}
.empty-state p {
    margin-bottom: 1rem;
}

/* ===== Chat ===== */
.chat-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* Chat Header */
.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 56px;
    gap: 12px;
}
.chat-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}
.chat-model {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.chat-header-title {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s;
    overflow: hidden;
}
.chat-header-title:hover {
    background: var(--bg-secondary, #161b22);
}
.header-title-text {
    font-size: 1.1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary, #e6edf3);
}
.header-title-edit-icon {
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity 0.15s;
    color: var(--text-muted, #8b949e);
    flex-shrink: 0;
}
.chat-header-title:hover .header-title-edit-icon {
    opacity: 1;
}
.header-title-input {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 600;
    background: var(--bg-secondary, #161b22);
    color: var(--text-primary, #e6edf3);
    border: 2px solid var(--accent, #2ea44f) !important;
    border-radius: 6px;
    padding: 4px 8px;
    box-shadow: 0 0 0 3px rgba(46, 164, 79, 0.2);
    outline: none;
    border: 1px solid var(--accent, #2ecc71);
    border-radius: 4px;
    padding: 2px 6px;
    outline: none;
    min-width: 100px;
}
.chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.model-select {
    outline: none;
    background: var(--bg-secondary, #161b22);
    color: var(--text-muted, #8b949e);
    border: 1px solid var(--border, #30363d);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.8rem;
    cursor: pointer;
    min-width: 140px;
}
.model-select:hover {
    border-color: var(--accent, #2ecc71);
}
.model-select:focus {
    border-color: var(--accent, #2ecc71);
    box-shadow: 0 0 0 2px rgba(46, 204, 113, 0.15);
}

/* Rate Limit */
.rate-limit-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 2px 8px;
    background: var(--bg-input);
    border-radius: 10px;
}
.rate-limit-bar {
    height: 3px;
    background: var(--bg-input);
    overflow: hidden;
}
.rate-limit-fill {
    height: 100%;
    background: var(--green-primary);
    transition: width 0.3s;
}
.rate-limit-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}
.rate-limit-modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    max-width: 400px;
    text-align: center;
}
.rate-limit-modal-content h3 {
    margin-bottom: 1rem;
}
.rate-limit-modal-content p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}
.rate-limit-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

/* Chat Messages */
.chat-messages {
    touch-action: pan-y;
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Messages */
.message {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    position: relative;
}
.message-content {
    flex: 1;
    min-width: 0;
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
}
.message-avatar {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.2rem;
}
.message-text {
    line-height: 1.7;
    font-size: 0.95rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.message-text p {
    margin-bottom: 0.8em;
}
.message-text p:last-child {
    margin-bottom: 0;
}
.message-text pre {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    overflow-x: auto;
    margin: 0.8em 0;
    font-size: 0.85rem;
}
.message-text code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
}
.message-text pre code {
    background: none;
    padding: 0;
}
.message-text ul, .message-text ol {
    padding-left: 1.5em;
    margin: 0.5em 0;
}
.message-text blockquote {
    border-left: 3px solid var(--border);
    padding-left: 1em;
    color: var(--text-muted);
    margin: 0.5em 0;
}
.message-text a {
    color: var(--accent);
}
.message-text table {
    border-collapse: collapse;
    margin: 0.8em 0;
    width: 100%;
}
.message-text th, .message-text td {
    border: 1px solid var(--border);
    padding: 6px 12px;
    text-align: left;
}
.message-text th {
    background: var(--bg-input);
}


/* Token Warning/Danger */
.message-tokens-warning .message-content {
    border-left: 3px solid var(--warning);
}
.message-tokens-danger .message-content {
    border-left: 3px solid var(--danger);
}

/* Tinted user card + assistant avatar ring (turn differentiation) */
.message-user .message-content {
    background: rgba(46, 204, 113, 0.08);
    border-color: rgba(46, 204, 113, 0.28);
}
.message-avatar {
    border-radius: 50%;
    background: var(--bg-input);
    border: 1px solid var(--border);
}
.message-assistant .message-avatar {
    border-color: var(--green-primary);
    box-shadow: 0 0 0 1px rgba(46, 204, 113, 0.35);
}

/* Error message card */
.message-error .message-content {
    background: rgba(248, 81, 73, 0.08);
    border-color: rgba(248, 81, 73, 0.4);
}

/* Code blocks: language label + copy button */
.message-text pre { position: relative; }
.code-copy {
    position: absolute;
    top: 6px;
    right: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    color: var(--text-secondary);
}
.message-text pre:hover .code-copy,
.code-copy:focus-visible { opacity: 1; }
.code-lang {
    position: absolute;
    top: 6px;
    left: 10px;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    pointer-events: none;
}

/* Long-answer collapsing */
.message.collapsible.collapsed .message-text {
    max-height: 640px;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(to bottom, #000 78%, transparent);
            mask-image: linear-gradient(to bottom, #000 78%, transparent);
}
.collapse-toggle {
    margin-top: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.78rem;
    padding: 4px 10px;
}
.collapse-toggle:hover { color: var(--text); }

/* Card enter animation */
@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}
.message { animation: msgIn 0.18s ease-out; }
@media (prefers-reduced-motion: reduce) {
    .message { animation: none; }
}

/* Stop-generating button (mirrors #send-btn sizing) */
#stop-btn {
    align-items: center;
    justify-content: center;
    background: var(--danger);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: var(--on-primary);
    width: 32px;
    height: 32px;
    display: flex;
    flex-shrink: 0;
    transition: background 0.2s;
}
#stop-btn:hover {
    background: var(--danger-hover);
}
#stop-btn svg {
    width: 16px;
    height: 16px;
}

/* Image lightbox */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    cursor: zoom-out;
    padding: 24px;
}
.lightbox-overlay img {
    max-width: 95vw;
    max-height: 95vh;
    border-radius: var(--radius);
}
.message-text img { cursor: zoom-in; }

/* Generated-image caption + download */
.image-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
    font-size: 0.7rem;
    color: var(--text-muted);
}
.image-download {
    text-decoration: none;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1px 7px;
}
.image-download:hover { color: var(--text); background: var(--bg-input); }

/* Thinking Indicator */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.thinking-dots {
    display: flex;
    gap: 4px;
}
.thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: dotPulse 1.4s infinite ease-in-out;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* Collapsed reasoning chip — how many "thinking" tokens were spent before
   the answer. The reasoning text itself is never shown or stored. */
.thinking-chip {
    display: inline-block;
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg-muted, rgba(127, 127, 127, 0.12));
    border-radius: 10px;
    padding: 2px 8px;
    margin-bottom: 6px;
    user-select: none;
}

/* Streaming Cursor */
.streaming-cursor::after {
    content: '▊';
    animation: blink 0.7s infinite;
    color: var(--green-primary);
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ===== Context Wheel ===== */
.context-wheel {
    position: relative;
    width: 36px;
    height: 36px;
    cursor: pointer;
    flex-shrink: 0;
}
.context-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}
.context-ring-bg {
    fill: none;
    stroke: var(--bg-input);
    stroke-width: 3;
}
.context-ring-fill {
    fill: none;
    stroke: var(--green-primary);
    stroke-width: 3;
    stroke-dasharray: 97.39;
    stroke-dashoffset: 97.39;
    transition: stroke-dashoffset 0.3s, stroke 0.3s;
    stroke-linecap: round;
}
.context-ring-fill.warn {
    stroke: var(--warning);
}
.context-ring-fill.danger {
    stroke: var(--danger);
}
.context-pct {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.55rem;
    font-weight: 600;
    color: var(--text-muted);
    pointer-events: none;
}
.context-pct.warn { color: var(--warning); }
.context-pct.danger { color: var(--danger); }

/* Context Menu */
.ctx-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 0;
    min-width: 260px;
    z-index: 200;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    margin-top: 4px;
}
.ctx-menu.open {
    display: block;
}
.ctx-menu-title {
    padding: 8px 14px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.ctx-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 0.85rem;
}
.ctx-menu-item:hover {
    background: var(--bg-input);
}
.ctx-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}
.ctx-label {
    display: block;
    font-weight: 500;
}
.ctx-desc {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.ctx-menu-sep {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* ===== Chat Input Area ===== */
.chat-input-area {
    border-top: 1px solid var(--border);
    padding: 12px 24px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
}
#chat-form {
    max-width: 800px;
    margin: 0 auto;
}
.image-preview-area {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.image-preview-item {
    position: relative;
    width: 60px;
    height: 60px;
}
.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.image-preview-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--danger);
    color: var(--on-primary);
    border: none;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 12px;
}
.chat-input-row textarea {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-size: 1rem;
    resize: vertical;max-height:200px;
    outline: none;
    max-height: 200px;
    line-height: 1.5;
    font-family: inherit;
}
.chat-input-row textarea::placeholder {
    color: var(--text-muted);
}
.btn-attach {
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    padding: 4px;
}
.btn-attach:hover {
    color: var(--text);
}
.btn-attach svg {
    width: 20px;
    height: 20px;
}
.btn-attach input {
    display: none;
}
.send-stop-wrapper {
    position: relative;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}
.send-stop-wrapper #send-btn,
.send-stop-wrapper #stop-btn {
    position: absolute;
    inset: 0;
    width: 32px;
    height: 32px;
}
#send-btn {
    background: var(--green-primary);
    border: none;
    border-radius: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
}
#send-btn:hover {
    background: var(--green-hover);
}
#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
#send-btn svg {
    width: 16px;
    height: 16px;
    stroke: var(--on-primary);
}

/* Message Images */
.message-images {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.message-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

/* Edit Area */
.edit-area {
    margin-top: 4px;
}
.edit-textarea {
    width: 100%;
    min-height: 60px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 8px 12px;
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    outline: none;
}
.edit-textarea:focus {
    border-color: var(--green-primary);
}
.edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* ===== Image Generation Progress ===== */
.gen-progress-container {
    width: 100%;
    max-width: 300px;
}
.gen-progress-bar-bg {
    width: 100%;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}
.gen-progress-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--green-primary);
    border-radius: 3px;
    transition: width 0.3s;
}
.gen-progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ===== Reconnection Banner ===== */
.reconnect-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(248, 81, 73, 0.9);
    color: var(--on-primary);
    text-align: center;
    padding: 8px;
    font-size: 0.85rem;
    z-index: 10001;
}

/* ===== Spinner ===== */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: var(--on-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Input Small ===== */
.input-sm {
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
}
.input-sm:focus {
    border-color: var(--green-primary);
}

/* ===== API Flash ===== */
.api-flash {
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.85rem;
}
.api-flash-success { background: rgba(46, 204, 113, 0.15); border: 1px solid var(--green-primary); color: var(--green-primary); }
.api-flash-error { background: rgba(248, 81, 73, 0.15); border: 1px solid var(--danger); color: var(--danger); }

/* ===== API Section ===== */
.api-section {
    margin-bottom: 2rem;
}
.api-section h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}


/* ===== Issue #63: Message Card Header & Consolidated Action Bar ===== */

/* Message header row at top of .message-content */
.msg-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.msg-header-role {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 1px 7px;
    border-radius: 8px;
    line-height: 1.5;
    flex-shrink: 0;
}
.message-user .msg-header-role {
    background: rgba(46, 204, 113, 0.15);
    color: var(--green-primary);
}
.message-assistant .msg-header-role {
    background: rgba(88, 166, 255, 0.12);
    color: var(--accent);
}
.msg-header-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    flex-shrink: 0;
}
.msg-header-tokens {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 3px;
}

/* Consolidated action bar at bottom */
.msg-actions {
    display: flex;
    gap: 2px;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid rgba(255,255,255,0.06);
}
.msg-action {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.15s, background 0.15s;
    padding: 4px 6px;
    border-radius: 6px;
    color: var(--text-muted);
}
.msg-action:hover,
.msg-action:focus-visible {
    opacity: 1;
    background: var(--bg-input);
}
.msg-action.copied { color: var(--green-primary); opacity: 1; }

/* Secondary actions toggle */
.msg-actions-more-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.15s, background 0.15s;
    padding: 4px 6px;
    border-radius: 6px;
    color: var(--text-muted);
}
.msg-actions-more-btn:hover,
.msg-actions-more-btn:focus-visible {
    opacity: 1;
    background: var(--bg-input);
}

/* Secondary dropdown */
.msg-actions-secondary {
    display: none;
    position: absolute;
    bottom: calc(100% + 4px);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    min-width: 140px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 100;
    flex-direction: column;
}
.msg-actions-secondary.open {
    display: flex;
}
.msg-actions-secondary .msg-action {
    width: 100%;
    text-align: left;
    padding: 6px 10px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    white-space: nowrap;
}
.msg-actions-secondary .msg-action:hover {
    opacity: 1;
    background: var(--bg-input);
}
.msg-actions-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
}

/* Hover-reveal on desktop, always visible on touch */
@media (hover: hover) {
    .msg-actions { opacity: 0; transition: opacity 0.15s; }
    .message:hover .msg-actions,
    .message:focus-within .msg-actions { opacity: 1; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Code Block ===== */
.code-block {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    overflow-x: auto;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.85rem;
}

/* ===== Misc ===== */
.mono {
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ===== Biometric Modal ===== */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); display: flex; align-items: center;
    justify-content: center; z-index: 1000;
}
.modal-card {
    background: var(--bg-card); border-radius: 12px; width: 90%; max-width: 420px;
    padding: 24px; box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { margin: 0; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; }
.modal-body h4 { margin: 0 0 8px; }
.webauthn-device {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 12px; background: var(--bg-secondary); border-radius: 8px; margin-bottom: 8px;
}
.webauthn-device-name { font-size: 14px; }
.webauthn-device-date { font-size: 11px; color: var(--text-muted); }
.webauthn-device button { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 16px; }

/* ===== Utility Classes ===== */
.text-muted-sm { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }
.text-error { color: var(--danger); }
.mt-sm { margin-top: 12px; }
.mb-xs { margin-bottom: 4px; }

/* ===== Image Upscale ===== */
.generated-image-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
}
.generated-image {
    transition: opacity 0.3s;
}
.upscale-btn-container {
    margin-top: 6px;
}
.btn-upscale {
    background: var(--accent, #6366f1);
    color: var(--on-primary);
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.85em;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-upscale:hover {
    background: var(--accent-hover, #4f46e5);
}
.upscale-max {
    color: var(--success, #22c55e);
    font-size: 0.85em;
}
.upscale-error {
    color: var(--error, #ef4444);
    font-size: 0.85em;
}

/* Video Generation */
.generated-video-wrapper {
    display: inline-block;
    max-width: 400px;
}
.generated-video-wrapper video {
    max-width: 100%;
    border-radius: 8px;
}

/* Form hint for accessibility */
.form-hint {
  display: block;
  font-size: 0.78rem;
  color: var(--text-secondary, #888);
  margin-top: 4px;
}

/* TTS (Read Aloud) Button */
.btn-tts {
    top: 0;
    right: 2.2rem;
}
.btn-tts:active,
.btn-tts:hover {
    transform: scale(1.2);
}

/* ===== Workspace sidebar styles ===== */
.sidebar-workspaces {
    padding: 0 12px;
    max-height: none;
    overflow: visible;
}

.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 4px 4px;
    margin-top: 4px;
}

.sidebar-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 600;
}

.workspace-group {
    margin-bottom: 2px;
}

.workspace-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 13px;
    color: var(--text);
}

.workspace-header:hover {
    background: rgba(255,255,255,0.05);
}

.workspace-collapse-icon {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.2s;
    width: 12px;
    text-align: center;
}

.workspace-collapse-icon.expanded {
    transform: rotate(90deg);
}

.workspace-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.workspace-thread-count {
    font-size: 11px;
    color: var(--text-muted);
}

.workspace-menu-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1;
}

.workspace-menu-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text);
}

.workspace-threads {
    padding-left: 12px;
}

.workspace-threads .thread-item {
    padding-left: 20px;
}

.ws-new-chat-form {
    padding: 2px 8px 4px 20px;
}

.ws-new-chat-btn {
    width: 100%;
    font-size: 12px;
    color: var(--text-muted);
    opacity: 0.7;
}

.ws-new-chat-btn:hover {
    opacity: 1;
    color: var(--text);
}

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1;
}

.btn-icon:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text);
}

/* Workspace context menu */
.ws-context-menu {
    position: fixed;
    background: var(--bg-card, #1a1a2e);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    min-width: 160px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 1000;
}

.ws-context-menu-item {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: var(--text);
    text-align: left;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.ws-context-menu-item:hover {
    background: rgba(255,255,255,0.05);
}

.ws-context-menu-item.danger {
    color: var(--danger);
}

/* Create workspace modal */
.ws-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ws-modal {
    background: var(--bg-card, #1a1a2e);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
}

.ws-modal h3 {
    margin: 0 0 16px;
    color: var(--text);
}

.ws-modal input, .ws-modal textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg, #0f0f1a);
    color: var(--text);
    margin-bottom: 12px;
    font-size: 14px;
    box-sizing: border-box;
}

.ws-modal textarea {
    min-height: 60px;
    resize: vertical;
}

.ws-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Workspace context badge */
.ws-ctx-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-secondary);
    font-size: 0.72rem;
    font-weight: 500;
    white-space: nowrap;
    margin-left: 8px;
    border: 1px solid rgba(139, 92, 246, 0.25);
}
.ws-ctx-badge[hidden] {
    display: none;
}

/* Delete chat button - Issue #71 */
.delete-chat-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
}
.delete-chat-btn:hover {
    color: var(--danger);
    background: rgba(239,68,68,0.1);
}


/* Accessibility fixes */
.modal-overlay[style*="display:none"] { visibility: hidden; pointer-events: none; }
.skip-link:focus { outline: 2px solid var(--primary,#2ea44f); }
.suggestion-chip { cursor: pointer; }
details summary { cursor: pointer; padding: 8px 0; font-weight: 600; }
details[open] summary { margin-bottom: 8px; }

/* #141: Hide focusable elements in inert modals */
[inert] { pointer-events: none; }
[inert] * { visibility: hidden; }

/* Thread selection / bulk delete (moved from admin.css for dashboard use) */
.thread-card.selected {
  border-color: var(--green-hover);
  box-shadow: 0 0 0 2px rgba(39,174,96,0.3);
}
.thread-card .thread-checkbox {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  cursor: pointer;
  display: none;
  accent-color: var(--green-hover);
}
.thread-card.selectable .thread-checkbox {
  display: block;
}
.thread-card.selectable .btn-delete {
  display: none;
}
.thread-select-btn {
  background: var(--bg-secondary, #16162a);
  border: 1px solid var(--border, #2a2a3e);
  color: var(--text, #e8e8f0);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.thread-select-btn:hover {
  background: var(--border, #2a2a3e);
}
.thread-select-btn.active {
  background: var(--green-hover);
  border-color: var(--green-hover);
  color: var(--on-primary);
}
.bulk-action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary, #16162a);
  border-top: 1px solid var(--border, #2a2a3e);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 200;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
}
.bulk-action-bar.visible {
  transform: translateY(0);
}
.bulk-action-info {
  color: var(--text, #e8e8f0);
  font-size: 0.88rem;
  font-weight: 600;
}
.bulk-action-buttons {
  display: flex;
  gap: 8px;
}
.btn-bulk-delete {
  background: var(--danger);
  color: var(--on-primary);
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-bulk-delete:hover {
  background: var(--danger-hover);
}
.btn-bulk-cancel {
  background: var(--border, #2a2a3e);
  color: var(--text, #e8e8f0);
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn-bulk-cancel:hover {
  background: var(--text-secondary, #8888aa);
}
