/* ================================================
   TREND CO-PILOT — Dashboard Styles
   Dark, premium, publisher-facing UI
   ================================================ */

/* ---------- Design Tokens ---------- */
:root {
    --bg-primary: #06060f;
    --bg-secondary: #0c0c1a;
    --bg-card: #111125;
    --bg-elevated: #16163a;
    --border-color: rgba(148,148,184,0.08);
    --border-active: rgba(139,92,246,0.3);
    --text-primary: #f0f0f8;
    --text-secondary: #9494b8;
    --text-muted: #5a5a7a;
    --accent-blue: #3b82f6;
    --accent-violet: #8b5cf6;
    --accent-emerald: #34d399;
    --accent-amber: #fbbf24;
    --accent-rose: #f472b6;
    --accent-cyan: #22d3ee;
    --gradient-primary: linear-gradient(135deg, #3b82f6, #8b5cf6);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --shadow-card: 0 4px 24px rgba(0,0,0,0.3), 0 0 1px rgba(139,92,246,0.15);
    --sidebar-width: 260px;
    --topbar-height: 60px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    height: 100%;
}

a { text-decoration: none; color: inherit; }
img { max-width: 100%; display: block; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.25s ease;
    white-space: nowrap;
}

.btn-primary {
    background: var(--gradient-primary);
    color: #fff;
    padding: 10px 20px;
    font-size: 0.85rem;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    font-size: 0.85rem;
}

.btn-outline:hover {
    border-color: var(--accent-violet);
    color: var(--text-primary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    padding: 10px 20px;
    font-size: 0.85rem;
}

.btn-ghost:hover { color: var(--text-primary); }
.btn-sm { padding: 8px 14px; font-size: 0.8rem; }

/* Slice 3.5 — authed session chip in topbar */
.dash-session {
    display: flex; align-items: center; gap: 6px;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.10);
    border-radius: 999px;
    padding: 4px 6px 4px 14px;
    margin-left: 8px;
}
.dash-session-email {
    color: #34d399;
    font-size: 0.78rem;
    font-weight: 600;
    margin-right: 6px;
    white-space: nowrap;
}
.dash-session-email::before { content: "● "; }
.dash-session .btn-ghost.btn-sm {
    padding: 4px 10px;
    font-size: 0.72rem;
    border-radius: 999px;
}
/* The [hidden] attribute normally sets display:none, but .btn's display:
   inline-flex wins on specificity. Restore the hide explicitly so the
   Admin link stays invisible for non-super-admin users. */
.dash-session [hidden] { display: none !important; }

/* Slice 4 — Compose meta row (Language + Country directly in the form) */
.compose-meta-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 10px 0 4px;
}
.compose-meta-field { display: flex; flex-direction: column; gap: 4px; }
@media (max-width: 640px) {
    .compose-meta-row { grid-template-columns: 1fr; }
}
.btn-block { width: 100%; justify-content: center; }
.btn-glow { box-shadow: 0 0 20px rgba(59,130,246,0.2), 0 0 50px rgba(139,92,246,0.1); }
.btn-glow:hover { box-shadow: 0 0 30px rgba(59,130,246,0.3), 0 0 70px rgba(139,92,246,0.15); }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ---------- Top Bar ---------- */
.dash-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: rgba(6, 6, 15, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.dash-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dash-logo-img {
    width: 30px;
    height: 30px;
    border-radius: 6px;
}

.dash-logo-text {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.02em;
}

.dash-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 3px 10px;
    border-radius: 100px;
    background: rgba(139, 92, 246, 0.12);
    color: var(--accent-violet);
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.topbar-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.topbar-stat-number {
    font-size: 1.1rem;
    font-weight: 800;
    font-family: 'JetBrains Mono', monospace;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.topbar-stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* ---------- Main Layout ---------- */
.dash-main {
    display: flex;
    margin-top: var(--topbar-height);
    min-height: calc(100vh - var(--topbar-height));
}

/* ---------- Sidebar ---------- */
.dash-sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-height);
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 20px;
    overflow-y: auto;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sidebar-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.filter-label input[type="checkbox"] {
    accent-color: var(--accent-violet);
}

.filter-select {
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    outline: none;
    transition: border-color 0.2s ease;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%239494b8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

.filter-select:focus {
    border-color: var(--accent-violet);
}

.filter-select option {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* ---------- Content Area ---------- */
.dash-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 20px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Tabs */
.dash-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 4px;
    width: fit-content;
}

.dash-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.dash-tab:hover { color: var(--text-secondary); }
.dash-tab.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.tab-count {
    font-size: 0.7rem;
    font-weight: 700;
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-violet);
    padding: 1px 7px;
    border-radius: 100px;
    font-family: 'JetBrains Mono', monospace;
}

/* Search */
.dash-search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: border-color 0.2s ease;
}

.dash-search-bar:focus-within {
    border-color: var(--accent-violet);
}

.dash-search-bar svg { color: var(--text-muted); flex-shrink: 0; }

.dash-search-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    outline: none;
}

.dash-search-input::placeholder { color: var(--text-muted); }

/* ---------- Trend Feed ---------- */
.trend-feed {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.trend-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.trend-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--gradient-primary);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.trend-card:hover {
    border-color: var(--border-active);
    transform: translateY(-3px);
    box-shadow: var(--shadow-card);
}

.trend-card:hover::before { opacity: 1; }

.trend-card.bookmarked {
    border-color: rgba(251, 191, 36, 0.3);
}

.trend-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.trend-card-title {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.4;
    flex: 1;
}

.trend-bookmark-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.trend-bookmark-btn:hover { color: var(--accent-amber); }
.trend-bookmark-btn.active { color: var(--accent-amber); }

.trend-card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.trend-meta-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 0.7rem;
    font-weight: 600;
}

.badge-country {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-blue);
}

.badge-velocity {
    background: rgba(52, 211, 153, 0.1);
    color: var(--accent-emerald);
}

.badge-velocity-peaked {
    background: rgba(251, 191, 36, 0.1);
    color: var(--accent-amber);
}

.badge-velocity-falling {
    background: rgba(244, 114, 182, 0.1);
    color: var(--accent-rose);
}

.badge-source {
    background: rgba(139, 92, 246, 0.1);
    color: var(--accent-violet);
}

.badge-traffic {
    font-size: 0.7rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-muted);
}

/* Feed states */
.feed-loading,
.feed-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.feed-empty svg { opacity: 0.3; margin-bottom: 16px; }
.feed-empty h3 { font-size: 1.2rem; color: var(--text-secondary); margin-bottom: 8px; }
.feed-empty p { font-size: 0.9rem; }

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-violet);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Detail Panel ---------- */
.detail-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.detail-overlay.open { opacity: 1; pointer-events: all; }

.detail-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 560px;
    max-width: 100vw;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    z-index: 210;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.detail-panel.open { transform: translateX(0); }

.detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 24px 28px 16px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 5;
}

.detail-title {
    font-size: 1.3rem;
    font-weight: 800;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.detail-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.detail-close:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}

.detail-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    flex-wrap: wrap;
}

.detail-body {
    padding: 20px 28px;
    flex: 1;
}

.detail-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
}

/* Generated Article */
.generated-article {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 28px;
    animation: fadeInUp 0.5s ease;
}

.gen-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.gen-title {
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.3;
}

.gen-badge {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 3px 10px;
    border-radius: 100px;
    white-space: nowrap;
    flex-shrink: 0;
}

.gen-badge-gemini { background: rgba(59,130,246,0.12); color: var(--accent-blue); }
.gen-badge-claude { background: rgba(244,114,182,0.12); color: var(--accent-rose); }
.gen-badge-openai { background: rgba(52,211,153,0.12); color: var(--accent-emerald); }

/* Auto-fallback notice — shown when the publisher's chosen LLM failed and
   another provider in the chain answered. Surfaces both the actual provider
   that wrote the article AND the reason the original one failed. */
.gen-fallback-notice {
    background: rgba(245,158,11,0.10);
    color: rgba(252,211,77,0.95);
    border: 1px solid rgba(245,158,11,0.25);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.82rem;
    line-height: 1.45;
    margin: 8px 0 14px;
}
.gen-fallback-notice strong { color: rgba(252,211,77,1); }

.gen-excerpt {
    font-size: 0.95rem;
    color: var(--accent-violet);
    font-style: italic;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    line-height: 1.6;
}

.gen-body {
    font-size: 0.92rem;
    color: var(--text-secondary);
    line-height: 1.8;
    white-space: normal;
    max-height: 500px;
    overflow-y: auto;
}

/* Rendered article HTML (headers, bold, lists, tables, inline item images) */
.gen-body img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 12px 0;
}
.gen-body h2,
.gen-body h3 {
    color: var(--text-primary);
    margin: 1.2em 0 0.4em;
    line-height: 1.3;
}
.gen-body p { margin: 0 0 0.9em; }
.gen-body ul,
.gen-body ol { margin: 0 0 0.9em; padding-left: 1.4em; }
.gen-body li { margin: 0.2em 0; }
.gen-body strong { color: var(--text-primary); }
.gen-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 0 0 1em;
    font-size: 0.88rem;
}
.gen-body th,
.gen-body td {
    border: 1px solid var(--border-color, #2a2a3a);
    padding: 6px 10px;
    text-align: left;
}

.gen-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.gen-tag {
    font-size: 0.7rem;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 100px;
    background: rgba(139, 92, 246, 0.08);
    color: var(--accent-violet);
    border: 1px solid rgba(139, 92, 246, 0.12);
}

.gen-loading {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.gen-loading-sub {
    font-size: 0.8rem;
    margin-top: 8px;
    opacity: 0.7;
}

/* ---------- Toast ---------- */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    color: var(--text-primary);
    box-shadow: var(--shadow-card);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 3.5s forwards;
    max-width: 360px;
}

.toast-success { border-left: 3px solid var(--accent-emerald); }
.toast-error { border-left: 3px solid var(--accent-rose); }
.toast-info { border-left: 3px solid var(--accent-blue); }

@keyframes toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; transform: translateX(40px); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
    .dash-sidebar {
        width: 220px;
    }
    .dash-content {
        margin-left: 220px;
    }
}

@media (max-width: 768px) {
    .dash-sidebar {
        position: fixed;
        left: -280px;
        width: 260px;
        transition: left 0.3s ease;
    }

    .dash-sidebar.open {
        left: 0;
    }

    .dash-content {
        margin-left: 0;
        padding: 16px;
    }

    .detail-panel {
        width: 100%;
    }

    .trend-feed {
        grid-template-columns: 1fr;
    }
}


/* ================================================================
   PUBLISH SECTION (inside detail panel after generated article)
   ================================================================ */

.publish-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #1f1f1f;
}

.publish-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.publish-label {
    font-size: 13px;
    color: #9ca3af;
    font-weight: 500;
    flex-shrink: 0;
}

.publish-conn-select {
    flex: 1;
    min-width: 180px;
}

.conn-delete-btn {
    background: transparent;
    border: 1px solid #2a2a2a;
    color: #9ca3af;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.conn-delete-btn:hover {
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.4);
    background: rgba(239, 68, 68, 0.08);
}

.conn-delete-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.publish-add-link {
    display: inline-block;
    margin-top: 8px;
    color: #a78bfa;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
}

.publish-add-link:hover {
    text-decoration: underline;
}

.publish-result {
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 14px;
    display: none;
}

.publish-result.loading {
    background: rgba(139, 92, 246, 0.08);
    color: #c4b5fd;
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.publish-result.success {
    background: rgba(34, 197, 94, 0.08);
    color: #86efac;
    border: 1px solid rgba(34, 197, 94, 0.25);
}

.publish-result.error {
    background: rgba(239, 68, 68, 0.08);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.publish-success a {
    margin-left: 12px;
    color: #86efac;
    text-decoration: underline;
    font-weight: 600;
}


/* ================================================================
   CMS CONNECTION MODAL
   ================================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 200;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.96);
    width: min(480px, 92vw);
    max-height: 90vh;
    overflow-y: auto;
    background: #0f0f0f;
    border: 1px solid #1f1f1f;
    border-radius: 16px;
    box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 201;
    color: #ffffff;
}

.modal.open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #1f1f1f;
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
}

.modal-close {
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: #1a1a1a;
    color: #fff;
}

.modal-body {
    padding: 20px 24px;
}

.modal-field {
    margin-bottom: 14px;
}

.modal-field label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #d1d5db;
    margin-bottom: 6px;
}

.modal-field input {
    width: 100%;
    padding: 10px 12px;
    background: #050505;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    font-family: inherit;
    box-sizing: border-box;
}

.modal-field input:focus {
    outline: none;
    border-color: #8b5cf6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

.modal-hint {
    margin-top: 6px;
    font-size: 12px;
    color: #6b7280;
}

.modal-password-wrap {
    position: relative;
}

.modal-password-wrap input {
    padding-right: 42px;
}

.modal-password-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease, background 0.15s ease;
}

.modal-password-toggle:hover {
    color: #fff;
    background: #1a1a1a;
}

.modal-password-toggle:focus-visible {
    outline: 2px solid #8b5cf6;
    outline-offset: 1px;
}

.modal-test-result {
    margin-top: 14px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    display: none;
}

.modal-test-result.success {
    background: rgba(34, 197, 94, 0.08);
    color: #86efac;
    border: 1px solid rgba(34, 197, 94, 0.25);
}

.modal-test-result.error {
    background: rgba(239, 68, 68, 0.08);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.modal-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid #1f1f1f;
}

.modal-footer-spacer {
    flex: 1;
}

/* ---------- Generation Top Bar (AI Model controls + Mode toggle) ---------- */
.dash-genbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    flex-wrap: wrap;
}

.genbar-controls {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}

.genbar-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 130px;
    flex: 1 1 130px;
}

.genbar-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.genbar-toggle {
    display: inline-flex;
    gap: 2px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 3px;
    align-self: flex-end;
}

.mode-toggle-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 7px 14px;
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: calc(var(--radius-sm) - 2px);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.mode-toggle-btn:hover { color: var(--text-primary); }

.mode-toggle-btn.active {
    background: var(--gradient-primary);
    color: #fff;
}

/* ---------- Compose Panel (User Given mode) ---------- */
.compose-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 22px 22px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.compose-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.compose-sub {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin: 0 0 6px;
    line-height: 1.45;
}

.compose-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.compose-input {
    flex: 1 1 280px;
    min-width: 0;
    padding: 11px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.15s ease;
}

.compose-input:focus { border-color: var(--accent-violet); }

#composeGenerateBtn {
    padding: 11px 22px;
    font-size: 0.86rem;
}

.compose-hint {
    margin: 4px 0 0;
    font-size: 0.78rem;
    color: var(--text-muted);
    min-height: 1em;
}

.compose-hint.error { color: #fca5a5; }
.compose-hint.success { color: #86efac; }

/* Mode-switching: hide trends-only blocks when body is in User Given mode */
body.mode-user-given .trends-only { display: none !important; }
