/* ── Fizzo Dashboard — Dark Theme ─────────────────────────────────────── */

:root {
    --bg: #07070c;
    --surface: #0e0e16;
    --surface2: #16161f;
    --surface3: #1e1e2a;
    --border: #252535;
    --border-light: #2a2a3d;
    --text: #e8e8f0;
    --text-dim: #7878a0;
    --text-muted: #505070;
    --accent: #6c5ce7;
    --accent-light: #a29bfe;
    --accent2: #fd79a8;
    --accent3: #00cec9;
    --success: #00b894;
    --warning: #fdcb6e;
    --error: #d63031;
    --error-dim: #2d1015;
    --glow: rgba(108, 92, 231, 0.15);
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 2px 20px rgba(0,0,0,0.3);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 15px; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

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

/* ── Top Navigation ──────────────────────────────────────────────────── */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 0.6rem; }
.logo {
    font-weight: 700;
    font-size: 1.1rem;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.topbar-label { font-size: 0.8rem; color: var(--text-dim); }
.topbar-divider { width: 1px; height: 16px; background: var(--border); }
.kbd-hint {
    padding: 2px 6px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--text-dim);
}
.mono { font-family: var(--mono); font-size: 0.75rem; }
.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(0,184,148,0.4); }
    50% { opacity: 0.6; box-shadow: 0 0 0 6px rgba(0,184,148,0); }
}

/* ── Navigation Buttons ──────────────────────────────────────────────── */
.nav-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}
.nav-btn:hover { border-color: var(--accent); color: var(--accent); }
.hidden { display: none !important; }

/* ── Container ───────────────────────────────────────────────────────── */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem 2rem;
}

/* ── View Header ─────────────────────────────────────────────────────── */
.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.view-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
}
.view-subtitle {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-top: 0.2rem;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn-primary, .btn-secondary, .btn-accent, .btn-sm {
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font);
    font-weight: 600;
    transition: all 0.2s;
}
.btn-primary {
    background: var(--accent);
    color: #fff;
    padding: 0.6rem 1.2rem;
    font-size: 0.85rem;
}
.btn-primary:hover { background: var(--accent-light); }
.btn-secondary {
    background: var(--surface2);
    color: var(--text-dim);
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--text); }
.btn-accent {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff;
    padding: 0.6rem 1.2rem;
    font-size: 0.85rem;
}
.btn-accent:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-sm {
    background: var(--surface3);
    color: var(--text-dim);
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    border: 1px solid var(--border);
}
.btn-sm:hover { border-color: var(--accent); color: var(--text); }

/* ── Agent Banner ────────────────────────────────────────────────────── */
.agent-banner {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
}
.agent-status { display: flex; align-items: center; gap: 0.8rem; }
.agent-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-muted);
}
.agent-dot.running { background: var(--success); animation: pulse 2s infinite; }
.agent-dot.error { background: var(--error); }
.agent-dot.idle { background: var(--warning); }
.agent-label { font-weight: 600; font-size: 0.95rem; }
.agent-detail { font-size: 0.8rem; color: var(--text-dim); }
.agent-stats { display: flex; gap: 1.5rem; flex: 1; }
.agent-stat { display: flex; flex-direction: column; }
.agent-stat span:first-child { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.agent-stat span:last-child { font-weight: 600; font-size: 0.9rem; }

/* ── Story Grid ──────────────────────────────────────────────────────── */
.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 1rem;
}
.story-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.3rem;
    cursor: pointer;
    transition: all 0.25s;
    position: relative;
    overflow: hidden;
}
.story-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    opacity: 0;
    transition: opacity 0.25s;
}
.story-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 24px rgba(108, 92, 231, 0.1);
}
.story-card:hover::before { opacity: 1; }
.story-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.8rem; }
.story-card-title { font-weight: 700; font-size: 1.05rem; line-height: 1.3; }
.story-card-meta { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.tag {
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--surface3);
    color: var(--text-dim);
    border: 1px solid var(--border);
}
.tag-genre { background: rgba(108, 92, 231, 0.15); color: var(--accent-light); border-color: rgba(108, 92, 231, 0.3); }
.story-card-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }
.story-stat { text-align: center; }
.story-stat-value { font-weight: 700; font-size: 1.1rem; }
.story-stat-label { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.story-card-progress { margin-top: 0.8rem; }

/* ── Status Badge ────────────────────────────────────────────────────── */
.status-badge {
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.status-setup { background: rgba(253, 203, 110, 0.2); color: var(--warning); }
.status-writing { background: rgba(0, 184, 148, 0.2); color: var(--success); }
.status-paused { background: rgba(120, 120, 160, 0.2); color: var(--text-dim); }
.status-complete { background: rgba(108, 92, 231, 0.2); color: var(--accent-light); }
.status-error { background: var(--error-dim); color: var(--error); }

/* ── Progress Bar ────────────────────────────────────────────────────── */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--surface3);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    transition: width 0.6s ease;
}
.progress-section { margin: 1rem 0; }
.progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 0.4rem;
}

/* ── Hero Section ────────────────────────────────────────────────────── */
.hero {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    position: relative;
    overflow: hidden;
}
.hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), var(--accent2), var(--accent3));
}
.hero h1 { font-size: 1.5rem; font-weight: 700; }
.hero-meta { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.6rem; }

/* ── Stats Row ───────────────────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}
.stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.stat-value { display: block; font-size: 1.5rem; font-weight: 700; margin-top: 0.3rem; }

/* ── Tabs ────────────────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 0.3rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
    overflow-x: auto;
    padding-bottom: 0;
}
.tab {
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 0.7rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
    font-family: var(--font);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-light); border-bottom-color: var(--accent); }
.tab-content { display: none; animation: fadeIn 0.3s; }
.tab-content.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Cards ───────────────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.3rem;
    margin-bottom: 1rem;
}
.card h3 {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.8rem;
}

/* ── Chart Grid ──────────────────────────────────────────────────────── */
.chart-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

/* ── Data Table ──────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.data-table th {
    text-align: left;
    padding: 0.7rem 1rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}
.data-table td {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
.data-table tr:hover td { background: var(--surface2); }
.data-table .score-high { color: var(--success); font-weight: 700; }
.data-table .score-mid { color: var(--warning); font-weight: 600; }
.data-table .score-low { color: var(--error); font-weight: 600; }

/* ── Character Grid ──────────────────────────────────────────────────── */
.char-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1rem;
}
.char-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem;
}
.char-card h4 { font-size: 0.95rem; font-weight: 700; margin-bottom: 0.5rem; }
.char-card p { font-size: 0.85rem; color: var(--text-dim); line-height: 1.6; }

/* ── Health Grid ─────────────────────────────────────────────────────── */
.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}
.health-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem 1rem;
    background: var(--surface2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.health-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.health-dot.ok { background: var(--success); }
.health-dot.missing { background: var(--error); }
.health-label { font-size: 0.85rem; }

/* ── Tracker Grid ────────────────────────────────────────────────────── */
.tracker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 1rem;
}
.tracker-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem;
}
.tracker-card h4 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.6rem;
    color: var(--accent-light);
}
.tracker-card pre {
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--text-dim);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
    line-height: 1.5;
}

/* ── Live Monitor ────────────────────────────────────────────────────── */
.live-badge {
    padding: 0.3rem 0.8rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--error-dim);
    color: var(--error);
}
.live-badge.connected { background: rgba(0,184,148,0.2); color: var(--success); }

.live-banner {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}
.live-stage { display: flex; align-items: center; gap: 1rem; }
.stage-icon { font-size: 2rem; }
.stage-name { font-weight: 700; font-size: 1.1rem; }
.stage-detail { font-size: 0.8rem; color: var(--text-dim); }
.live-stats { display: flex; gap: 1.5rem; }
.live-stat { display: flex; flex-direction: column; text-align: center; }
.live-stat span:first-child { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.live-stat span:last-child { font-weight: 700; font-size: 1rem; }

/* ── Pipeline Visualization ──────────────────────────────────────────── */
.pipeline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.pipe-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--surface2);
    border: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-dim);
    transition: all 0.3s;
    min-width: 80px;
}
.pipe-stage span { font-size: 0.7rem; }
.pipe-stage.active { border-color: var(--accent); color: var(--accent-light); background: rgba(108,92,231,0.1); box-shadow: 0 0 12px rgba(108,92,231,0.2); }
.pipe-stage.done { border-color: var(--success); color: var(--success); background: rgba(0,184,148,0.08); }
.pipe-arrow { color: var(--text-muted); font-size: 1.2rem; }

/* ── Log ─────────────────────────────────────────────────────────────── */
.log-card { padding: 0; }
.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1.2rem;
    border-bottom: 1px solid var(--border);
}
.log-header h3 { margin-bottom: 0; }
.log-controls { display: flex; gap: 0.5rem; align-items: center; }
.log-controls input {
    background: var(--surface3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    font-family: var(--mono);
    width: 150px;
}
.log-controls input:focus { outline: none; border-color: var(--accent); }
.log-container {
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem;
    font-family: var(--mono);
    font-size: 0.75rem;
    line-height: 1.6;
}
.log-line {
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    color: var(--text-dim);
    white-space: pre-wrap;
    word-break: break-word;
}
.log-line:hover { background: var(--surface2); }
.log-line .log-time { color: var(--text-muted); margin-right: 0.5rem; }
.log-line.error { color: var(--error); }
.log-line.success { color: var(--success); }
.log-line.info { color: var(--accent-light); }

/* ── Activity List ───────────────────────────────────────────────────── */
.activity-list { max-height: 350px; overflow-y: auto; }
.activity-item {
    display: flex;
    gap: 0.8rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
    align-items: flex-start;
}
.activity-item:last-child { border-bottom: none; }
.activity-time { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; min-width: 120px; font-family: var(--mono); }
.activity-event { font-size: 0.82rem; }
.activity-error { color: var(--error); }
.activity-success { color: var(--success); }

/* ── Token Stats ─────────────────────────────────────────────────────── */
.token-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.8rem;
    margin-bottom: 1rem;
}
.token-stat { text-align: center; }
.token-stat-value { font-weight: 700; font-size: 1.1rem; }
.token-stat-label { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; }

/* ── Reader ──────────────────────────────────────────────────────────── */
.reader-content {
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 1rem;
    line-height: 1.9;
    color: var(--text);
    max-height: 600px;
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--surface2);
    border-radius: var(--radius);
    white-space: pre-wrap;
}

/* ── System Grid ─────────────────────────────────────────────────────── */
.system-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

/* ── Empty State ─────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-dim);
}
.empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h3 { font-size: 1.2rem; color: var(--text); margin-bottom: 0.5rem; }

/* ── Toast ───────────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.8rem 1.2rem;
    font-size: 0.85rem;
    color: var(--text);
    box-shadow: var(--shadow);
    animation: slideIn 0.3s ease;
    max-width: 350px;
}
.toast.error { border-color: var(--error); background: var(--error-dim); }
.toast.success { border-color: var(--success); }
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Markdown Body ───────────────────────────────────────────────────── */
.markdown-body {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text);
}
.markdown-body h1, .markdown-body h2, .markdown-body h3 {
    margin: 1rem 0 0.5rem;
    color: var(--text);
}
.markdown-body p { margin-bottom: 0.6rem; }
.markdown-body code {
    background: var(--surface3);
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 0.85em;
}
.markdown-body pre {
    background: var(--surface3);
    padding: 1rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
}
.markdown-body blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 1rem;
    color: var(--text-dim);
    margin: 0.8rem 0;
}

/* ── Live Grid ───────────────────────────────────────────────────────── */
.live-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ── Error Banner ────────────────────────────────────────────────────── */
.error-banner {
    background: var(--error-dim);
    border: 1px solid var(--error);
    border-radius: var(--radius-sm);
    padding: 0.8rem 1.2rem;
    margin-bottom: 1rem;
    color: var(--error);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

/* ── Fade In ─────────────────────────────────────────────────────────── */
.fade-in { animation: fadeIn 0.3s ease; }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .container { padding: 1rem; }
    .story-grid { grid-template-columns: 1fr; }
    .chart-grid { grid-template-columns: 1fr; }
    .live-grid { grid-template-columns: 1fr; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .agent-banner { flex-direction: column; }
    .hero { flex-direction: column; text-align: center; }
    .pipeline { flex-direction: column; }
    .pipe-arrow { transform: rotate(90deg); }
}
