/* panelcms design system — tokens + components.
   Direction (ui-ux-pro-max): dense ops/dashboard, slate base, green = "running/ok", Fira Sans + Fira Code.
   Plain CSS on purpose (Tailwind Play CDN is used only for layout utilities). */

:root {
    --font-sans: 'Fira Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --muted: #64748b;
    --accent: #15803d;          /* white text on it: 5.0:1 */
    --accent-hover: #166534;
    --ring: #15803d;

    --ok-bg: #dcfce7;   --ok-fg: #166534;
    --info-bg: #dbeafe; --info-fg: #1e40af;
    --warn-bg: #fef3c7; --warn-fg: #92400e;
    --err-bg: #fee2e2;  --err-fg: #991b1b;
    --neutral-bg: #e2e8f0; --neutral-fg: #334155;

    --sidebar-bg: #0b1220;
    --sidebar-fg: #cbd5e1;
    --sidebar-muted: #64748b;
    --sidebar-active: #172033;
    --sidebar-width: 15rem;

    --radius: 0.625rem;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
    --ease: cubic-bezier(.2, .7, .2, 1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #020617;
        --surface: #0f172a;
        --surface-2: #111c33;
        --border: #1e293b;
        --border-strong: #334155;
        --text: #f1f5f9;
        --muted: #94a3b8;
        --accent: #22c55e;
        --accent-hover: #4ade80;
        --ring: #4ade80;

        --ok-bg: #052e16;   --ok-fg: #86efac;
        --info-bg: #172554; --info-fg: #93c5fd;
        --warn-bg: #451a03; --warn-fg: #fcd34d;
        --err-bg: #450a0a;  --err-fg: #fca5a5;
        --neutral-bg: #1e293b; --neutral-fg: #cbd5e1;

        --sidebar-bg: #020617;
        --sidebar-active: #0f172a;
        --shadow: 0 0 0 1px rgba(148, 163, 184, .06);
    }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
.font-mono, code, kbd, pre { font-family: var(--font-mono); }
a { color: inherit; }

:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: 4px; }

.skip-link {
    position: absolute; left: .75rem; top: -3rem; z-index: 100;
    background: var(--accent); color: #fff; padding: .5rem .75rem; border-radius: .5rem; text-decoration: none;
}
.skip-link:focus { top: .75rem; }

/* ---------- shell ---------- */
.shell { min-height: 100vh; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width); z-index: 40;
    display: flex; flex-direction: column;
    background: var(--sidebar-bg); color: var(--sidebar-fg);
    transform: translateX(-100%); transition: transform .2s var(--ease);
}
.sidebar.open { transform: none; }
.sidebar-backdrop {
    position: fixed; inset: 0; z-index: 30; background: rgba(2, 6, 23, .55);
    opacity: 0; pointer-events: none; transition: opacity .2s var(--ease);
}
.sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
.brand { display: flex; align-items: center; gap: .625rem; padding: 1rem 1.125rem; color: #f8fafc; text-decoration: none; font-weight: 600; letter-spacing: -.01em; }
.brand-mark {
    width: 1.875rem; height: 1.875rem; border-radius: .5rem; display: grid; place-items: center;
    background: var(--accent); color: #fff; flex: none;
}
.brand-text { font-size: 1rem; line-height: 1.2; }
.nav { padding: .25rem .625rem; display: flex; flex-direction: column; gap: .125rem; flex: 1; overflow-y: auto; }
.nav-label { padding: .875rem .625rem .25rem; font-size: .6875rem; text-transform: uppercase; letter-spacing: .08em; color: var(--sidebar-muted); }
.nav-link {
    display: flex; align-items: center; gap: .625rem; min-height: 2.5rem; padding: .5rem .625rem;
    border-radius: .5rem; color: var(--sidebar-fg); text-decoration: none; font-size: .9rem;
    transition: background-color .15s var(--ease), color .15s var(--ease);
}
.nav-link:hover { background: var(--sidebar-active); color: #fff; }
.nav-link[aria-current="page"] { background: var(--sidebar-active); color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.sidebar-foot { padding: .75rem .625rem 1rem; border-top: 1px solid rgba(148, 163, 184, .12); }
.user-box { display: flex; align-items: center; gap: .625rem; padding: .5rem .625rem; }
.avatar {
    width: 2rem; height: 2rem; border-radius: 999px; display: grid; place-items: center; flex: none;
    background: var(--sidebar-active); color: #e2e8f0; font-weight: 600; font-size: .8125rem; text-transform: uppercase;
}
.user-name { font-size: .875rem; color: #e2e8f0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: .75rem; color: var(--sidebar-muted); }

.topbar {
    position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem;
    padding: .5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.icon-btn {
    display: inline-grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: .5rem; border: 0;
    background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.main { padding: 1.25rem 1rem 3rem; max-width: 80rem; margin: 0 auto; }

@media (min-width: 1024px) {
    .sidebar { transform: none; }
    .sidebar-backdrop { display: none; }
    .topbar { display: none; }
    .content-wrap { margin-left: var(--sidebar-width); }
    .main { padding: 1.75rem 2rem 3rem; }
}

/* ---------- page + cards ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.page-title { margin: 0; font-size: 1.5rem; line-height: 1.2; font-weight: 600; letter-spacing: -.02em; }
.page-sub { margin: .25rem 0 0; color: var(--muted); font-size: .875rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .875rem 1.125rem; border-bottom: 1px solid var(--border); }
.card-title { margin: 0; font-size: .9375rem; font-weight: 600; }
.card-body { padding: 1.125rem; }
.divide > * + * { border-top: 1px solid var(--border); }

.stat { padding: 1rem 1.125rem; }
.stat-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .8125rem; }
.stat-value { margin-top: .375rem; font-size: 1.875rem; line-height: 1.1; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-icon { display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: .5rem; background: var(--surface-2); color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 2.5rem; padding: .5rem 1rem;
    border-radius: .5rem; border: 1px solid transparent; font: inherit; font-size: .875rem; font-weight: 500; cursor: pointer; text-decoration: none;
    transition: background-color .15s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-block { width: 100%; }
.btn-side { width: 100%; justify-content: flex-start; background: transparent; color: var(--sidebar-fg); border: 0; }
.btn-side:hover { background: var(--sidebar-active); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #052e16; } }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: .375rem; }
.label { font-size: .8125rem; font-weight: 500; color: var(--text); }
.input, .select {
    width: 100%; min-height: 2.5rem; padding: .5rem .75rem; border-radius: .5rem; border: 1px solid var(--border-strong);
    background: var(--surface); color: var(--text); font: inherit; font-size: .9rem;
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.input::placeholder { color: var(--muted); opacity: .8; }
.input:hover, .select:hover { border-color: var(--muted); }
.input:focus, .select:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 25%, transparent); }
.help { font-size: .75rem; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: .5rem; font-size: .875rem; cursor: pointer; min-height: 1.75rem; }
.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
.mask { font-family: var(--font-mono); font-size: .75rem; color: var(--muted); }
.form-grid { display: grid; gap: 1rem; }
.form-grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }

/* ---------- badges + alerts ---------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .125rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 500; white-space: nowrap; }
.badge::before { content: ''; width: .375rem; height: .375rem; border-radius: 999px; background: currentColor; opacity: .85; }
.b-ok { background: var(--ok-bg); color: var(--ok-fg); }
.b-info { background: var(--info-bg); color: var(--info-fg); }
.b-warn { background: var(--warn-bg); color: var(--warn-fg); }
.b-err { background: var(--err-bg); color: var(--err-fg); }
.b-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }
.alert { display: flex; gap: .625rem; align-items: flex-start; padding: .75rem .875rem; border-radius: .5rem; font-size: .875rem; margin-bottom: 1rem; }
.alert svg { flex: none; margin-top: .125rem; }
.a-ok { background: var(--ok-bg); color: var(--ok-fg); }
.a-warn { background: var(--warn-bg); color: var(--warn-fg); }
.a-err { background: var(--err-bg); color: var(--err-fg); }
.alert ul { margin: 0; padding-left: 1.1rem; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th { text-align: left; padding: .625rem 1rem; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.cell-strong { font-weight: 500; }
.cell-muted { color: var(--muted); }

/* ---------- misc ---------- */
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
.empty-icon { display: inline-grid; place-items: center; width: 3rem; height: 3rem; border-radius: 999px; background: var(--surface-2); margin-bottom: .75rem; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: .75rem; padding: .625rem 1.125rem; }
.timeline li + li { border-top: 1px solid var(--border); }
.dot { width: .5rem; height: .5rem; border-radius: 999px; background: var(--border-strong); margin-top: .5rem; flex: none; }
pre.json { margin: .25rem 0 0; padding: .625rem; border-radius: .5rem; background: var(--surface-2); border: 1px solid var(--border); font-size: .75rem; overflow-x: auto; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.pager { display: flex; align-items: center; justify-content: space-between; margin-top: 1rem; font-size: .875rem; color: var(--muted); }
.grid-auto { display: grid; gap: 1rem; }
.grid-auto.c4 { grid-template-columns: repeat(2, 1fr); gap: .75rem; }
@media (min-width: 640px) { .grid-auto.c2 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .grid-auto.c4 { grid-template-columns: repeat(4, 1fr); } .grid-auto.c3 { grid-template-columns: repeat(3, 1fr); } .grid-auto.c2 { grid-template-columns: repeat(2, 1fr); } }

/* ---------- login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 24rem; padding: 1.75rem; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
