:root {
    --bg:         #0f1117;
    --surface:    #1a1d27;
    --surface-2:  #222535;
    --border:     #2d3044;
    --text:       #e4e6f1;
    --text-muted: #8b8fa8;
    --accent:     #6366f1;
    --accent-h:   #4f46e5;
    --success:    #10b981;
    --warning:    #f59e0b;
    --error:      #ef4444;
    --radius:     6px;
    --mono:       'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Navbar ─────────────────────────────────────── */
.navbar {
    display: flex;
    align-items: center;
    gap: 2rem;
    padding: 0 1.5rem;
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
}

.navbar-menu { display: flex; gap: 0.25rem; flex: 1; }

.nav-link {
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text-muted);
    font-size: 13px;
    transition: color 0.15s, background 0.15s;
}
.nav-link:hover, .nav-link.active {
    color: var(--text);
    background: var(--surface-2);
}

.navbar-user { display: flex; align-items: center; gap: 0.75rem; }
.username { color: var(--text-muted); font-size: 13px; }

/* ── Layout ──────────────────────────────────────── */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.page-title { font-size: 20px; font-weight: 600; }

/* ── Alerts ──────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    border: 1px solid;
}
.alert-success {
    background: rgba(16,185,129,.1);
    border-color: rgba(16,185,129,.3);
    color: #34d399;
}
.alert-error-flash {
    background: rgba(239,68,68,.1);
    border-color: rgba(239,68,68,.3);
    color: #f87171;
}
.alert-key {
    background: rgba(99,102,241,.1);
    border-color: rgba(99,102,241,.3);
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.api-key-display {
    font-family: var(--mono);
    font-size: 12px;
    background: var(--bg);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    color: #a5b4fc;
    flex: 1;
    word-break: break-all;
}

/* ── Buttons ─────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    transition: all .15s;
    line-height: 1;
    background: none;
    color: inherit;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn-ghost { color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-danger { color: var(--error); border-color: rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.1); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 12px; }
.w-full { width: 100%; justify-content: center; }

/* ── Cards ───────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.mb-3 { margin-bottom: 1.5rem; }

/* ── Stats ───────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; margin-bottom: 0.25rem; }
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-total .stat-value  { color: var(--accent); }
.stat-errors .stat-value { color: var(--error); }
.stat-warnings .stat-value { color: var(--warning); }

/* ── Section title ───────────────────────────────── */
.section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-bottom: 0.75rem;
}

/* ── Data table (dashboard) ──────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left;
    padding: .6rem .75rem;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: .6rem .75rem;
    border-bottom: 1px solid rgba(45,48,68,.5);
    font-size: 13px;
}

/* ── Log table ───────────────────────────────────── */
.log-table-wrapper { overflow-x: auto; }
.log-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12px; }
.log-table th {
    text-align: left;
    padding: .5rem .75rem;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 52px;
    background: var(--surface);
    z-index: 10;
    font-family: system-ui, sans-serif;
}
.log-table td {
    padding: .35rem .75rem;
    border-bottom: 1px solid rgba(45,48,68,.4);
    vertical-align: middle;
}
.log-row.expandable { cursor: pointer; }
.log-row:hover td { background: var(--surface-2); }
.log-row.expanded td { background: var(--surface-2); }

.log-time    { color: var(--text-muted); white-space: nowrap; font-size: 11px; }
.log-channel { color: var(--text-muted); font-size: 11px; }
.log-message { max-width: 700px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }

/* ── Log detail (expandable) ─────────────────────── */
.log-detail-row td { padding-top: 0; padding-bottom: .5rem; }
.log-detail-row { display: none; }
.log-detail-row.open { display: table-row; }

.log-detail {
    background: var(--bg);
    border-radius: 4px;
    border: 1px solid var(--border);
    padding: .75rem;
}
.log-detail-msg {
    color: var(--text);
    font-family: var(--mono);
    font-size: 12px;
    margin-bottom: .5rem;
    word-break: break-all;
}
.log-detail-section {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-bottom: .25rem;
    margin-top: .5rem;
}
.log-detail-pre {
    font-family: var(--mono);
    font-size: 11px;
    color: #a5b4fc;
    overflow-x: auto;
    white-space: pre;
}

/* ── Level badges ────────────────────────────────── */
.level-badge {
    display: inline-block;
    padding: .12rem .35rem;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .04em;
    font-family: var(--mono);
    white-space: nowrap;
}
.level-debug     { background: rgba(107,114,128,.2); color: #9ca3af; }
.level-info      { background: rgba(59,130,246,.2);  color: #60a5fa; }
.level-notice    { background: rgba(6,182,212,.2);   color: #22d3ee; }
.level-warning   { background: rgba(245,158,11,.2);  color: #fbbf24; }
.level-error     { background: rgba(239,68,68,.2);   color: #f87171; }
.level-critical  { background: rgba(220,38,38,.3);   color: #fca5a5; }
.level-alert     { background: rgba(249,115,22,.2);  color: #fb923c; }
.level-emergency { background: rgba(124,58,237,.25); color: #a78bfa; }

/* ── Project badge ───────────────────────────────── */
.project-badge {
    display: inline-block;
    padding: .12rem .4rem;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    font-family: system-ui, sans-serif;
}

/* ── Env badge ───────────────────────────────────── */
.env-badge {
    display: inline-block;
    padding: .1rem .3rem;
    border-radius: 3px;
    font-size: 10px;
    font-family: var(--mono);
    background: rgba(139,143,168,.15);
    color: var(--text-muted);
}

/* ── Filter bar ──────────────────────────────────── */
.filter-bar {
    display: flex;
    gap: .6rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .6rem .75rem;
}
.filter-bar input,
.filter-bar select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: .35rem .6rem;
    border-radius: 4px;
    font-size: 12px;
    outline: none;
    height: 28px;
}
.filter-bar input:focus,
.filter-bar select:focus { border-color: var(--accent); }
.filter-bar input[type="text"] { width: 180px; }
.filter-bar input::placeholder { color: var(--text-muted); }

/* ── Live tail controls ──────────────────────────── */
.tail-controls { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
.tail-indicator { display: inline-flex; align-items: center; gap: .4rem; font-size: 12px; color: var(--text-muted); }
.tail-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--success);
    animation: blink 2s infinite;
}
.tail-dot.paused { background: var(--text-muted); animation: none; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

.new-count-badge {
    background: var(--accent);
    color: #fff;
    border-radius: 9999px;
    font-size: 10px;
    padding: .1rem .4rem;
    font-weight: 700;
}

/* ── Pagination ──────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
    padding: .6rem .75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.pagination-info { font-size: 12px; color: var(--text-muted); }
.pagination-links { display: flex; gap: .5rem; }

/* ── Projects grid ───────────────────────────────── */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 1rem;
}
.project-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.project-card-header { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.project-color-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.project-name { font-weight: 600; font-size: 15px; }
.project-slug { color: var(--text-muted); font-size: 12px; font-family: var(--mono); }
.project-meta { display: flex; gap: 1rem; margin-bottom: 1rem; }
.project-meta-item { font-size: 12px; color: var(--text-muted); }
.project-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Login ───────────────────────────────────────── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 360px;
}
.login-title { font-size: 22px; font-weight: 700; margin-bottom: 1.5rem; text-align: center; }

/* ── Forms ───────────────────────────────────────── */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 500px;
}
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: .4rem; }
.form-control {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: .6rem .75rem;
    border-radius: 4px;
    font-size: 14px;
    outline: none;
}
.form-control:focus { border-color: var(--accent); }
.color-picker {
    width: 50px; height: 30px; padding: 2px;
    cursor: pointer; border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg);
}

/* ── Utility ─────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-mono  { font-family: var(--mono); }
