/* Kobu management console – "Organic Sage & Warm Sand", same tokens as the app (ui/theme/Color.kt). */

:root {
    color-scheme: light;
    --bg: #F7F6F1;
    --surface: #FFFFFF;
    --surface-2: #E5E8DE;
    --surface-3: #D9DED0;
    --border: #D9DED0;
    --text: #29352E;
    --muted: #5A685E;
    --subtle: #87977D;
    --primary: #29352E;
    --on-primary: #F7F6F1;
    --accent: #D8B994;
    --accent-soft: #F1E6D6;
    --accent-ink: #4A3A26;
    --ok: #4F7A5A;
    --ok-soft: #E5E8DE;
    --warn: #8A6A3F;
    --warn-soft: #F1E6D6;
    --danger: #B4533C;
    --danger-soft: #F6E1DA;
    --chart-1: #29352E;
    --chart-2: #C89C66;
    --chart-3: #87977D;
    --chart-4: #E0907A;
    --grid: #E5E8DE;
    --shadow: 0 1px 2px rgb(41 53 46 / 6%), 0 4px 16px rgb(41 53 46 / 5%);
    --radius: 14px;
    --radius-sm: 9px;
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --bg: #121815;
        --surface: #1B241F;
        --surface-2: #222D27;
        --surface-3: #2A362F;
        --border: #2A362F;
        --text: #EEF0EA;
        --muted: #A3B1A8;
        --subtle: #87977D;
        --primary: #D8B994;
        --on-primary: #121815;
        --accent: #D8B994;
        --accent-soft: #2A362F;
        --accent-ink: #D8B994;
        --ok: #8FB79A;
        --ok-soft: #1F2E25;
        --warn: #D8B994;
        --warn-soft: #2E2A20;
        --danger: #E0907A;
        --danger-soft: #3A160D;
        --chart-1: #D8B994;
        --chart-2: #87977D;
        --chart-3: #A3B1A8;
        --chart-4: #E0907A;
        --grid: #222D27;
        --shadow: none;
    }
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 600; color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---- Shell ----------------------------------------------------------------------------------------------- */

.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; gap: 4px;
    padding: 20px 14px;
    background: var(--surface-2);
    border-right: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11.5px; color: var(--muted); line-height: 1.2; }

.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: var(--radius-sm);
    text-decoration: none; color: var(--muted); font-weight: 500;
}
.nav-link:hover { background: var(--surface-3); color: var(--text); }
.nav-link.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.nav-link svg { width: 18px; height: 18px; flex: none; }

.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); }
.sidebar-foot .who { font-size: 12.5px; color: var(--muted); word-break: break-all; margin-bottom: 8px; }

.main { min-width: 0; padding: 28px 32px 48px; max-width: 1440px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.crumb { font-size: 12.5px; color: var(--muted); text-decoration: none; display: inline-block; margin-bottom: 6px; }
.crumb:hover { color: var(--text); }

/* ---- Building blocks ------------------------------------------------------------------------------------ */

.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.section { margin-top: 22px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head .hint { font-size: 12px; color: var(--muted); }

.kpi .label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.accent { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.kpi.accent .label, .kpi.accent .sub { color: var(--on-primary); opacity: 0.75; }

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 9px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600; white-space: nowrap;
    background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent-ink); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 36px; padding: 0 14px;
    border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: var(--surface); color: var(--text);
    font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.google { height: 44px; width: 100%; gap: 10px; font-size: 15px; }
.btn.google svg { width: 18px; height: 18px; }

.input, .select {
    height: 36px; padding: 0 12px;
    border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: var(--surface); min-width: 0;
}
.input:focus, .select:focus, .btn:focus-visible, .nav-link:focus-visible, textarea:focus {
    outline: 2px solid var(--accent); outline-offset: 1px;
}
.input.search { width: 320px; max-width: 100%; }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; width: 100%; }

/* ---- Tables ---------------------------------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; margin: 0 -18px -18px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 18px; text-align: left; vertical-align: middle; border-top: 1px solid var(--border); }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface); border-top: none; white-space: nowrap; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--surface-2); }
td .primary-text { font-weight: 600; }
td .secondary-text { font-size: 12.5px; color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; color: var(--muted); font-size: 12.5px; }

/* ---- Key/value lists ------------------------------------------------------------------------------------- */

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
.kv dt { color: var(--muted); font-size: 12.5px; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---- Charts ---------------------------------------------------------------------------------------------- */

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .line { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: 0.12; }
.chart .bar { rx: 2; }
.chart .cursor { stroke: var(--subtle); stroke-width: 1; stroke-dasharray: 3 3; }
.c1 { stroke: var(--chart-1); fill: var(--chart-1); }
.c2 { stroke: var(--chart-2); fill: var(--chart-2); }
.c3 { stroke: var(--chart-3); fill: var(--chart-3); }
.c4 { stroke: var(--chart-4); fill: var(--chart-4); }
.line.c1, .line.c2, .line.c3, .line.c4 { fill: none; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch.c1 { background: var(--chart-1); } .swatch.c2 { background: var(--chart-2); }
.swatch.c3 { background: var(--chart-3); } .swatch.c4 { background: var(--chart-4); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.tooltip {
    position: absolute; pointer-events: none; z-index: 2;
    background: var(--text); color: var(--bg);
    padding: 7px 10px; border-radius: 8px; font-size: 12px; line-height: 1.45;
    white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
}
.tooltip .t-head { font-weight: 600; margin-bottom: 2px; }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 140px) 1fr 56px; align-items: center; gap: 10px; font-size: 13px; }
.bar-track { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--chart-1); }
.bar-fill.c2 { background: var(--chart-2); } .bar-fill.c3 { background: var(--chart-3); } .bar-fill.c4 { background: var(--chart-4); }

.gauge { display: flex; flex-direction: column; gap: 6px; }
.gauge-top { display: flex; justify-content: space-between; font-size: 13px; }
.gauge-track { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.gauge-fill { height: 100%; background: var(--ok); border-radius: 999px; transition: width 0.4s ease; }
.gauge-fill.warn { background: var(--warn); }
.gauge-fill.danger { background: var(--danger); }

.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.status-dot.down { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }

/* ---- Logs ------------------------------------------------------------------------------------------------ */

.log { display: grid; grid-template-columns: 150px 70px 1fr; gap: 6px 14px; padding: 10px 0; border-top: 1px solid var(--border); }
.log:first-child { border-top: none; }
.log .msg { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
.log .exc { grid-column: 3; font-family: var(--mono); font-size: 12px; color: var(--danger); overflow-wrap: anywhere; }

/* ---- Login ----------------------------------------------------------------------------------------------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; padding: 32px 28px; text-align: center; }
.login img { width: 64px; height: 64px; border-radius: 16px; }
.login h1 { margin-top: 16px; }
.login p { color: var(--muted); margin: 6px 0 26px; }
.login .error { margin-top: 16px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); font-size: 13px; text-align: left; }
.login .foot { margin-top: 22px; font-size: 12px; color: var(--muted); }

/* ---- Dialog & toast -------------------------------------------------------------------------------------- */

dialog {
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text);
    padding: 22px; width: min(460px, calc(100vw - 32px));
    box-shadow: 0 20px 60px rgb(0 0 0 / 25%);
}
dialog::backdrop { background: rgb(18 24 21 / 45%); }
dialog h2 { font-size: 17px; margin-bottom: 8px; }
dialog p { color: var(--muted); margin: 0 0 14px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
dialog label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
dialog .input { width: 100%; }

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 50; }
.toast { background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgb(0 0 0 / 20%); max-width: 380px; font-size: 13.5px; }
.toast.error { background: var(--danger); color: #fff; }

.loading { padding: 40px; text-align: center; color: var(--muted); }
.error-box { padding: 14px 16px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); }

/* ---- Responsive ------------------------------------------------------------------------------------------ */

@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; }
    .brand { padding: 0 8px 0 0; }
    .brand-sub { display: none; }
    .sidebar-foot { margin: 0 0 0 auto; border: none; padding: 0; display: flex; align-items: center; gap: 8px; }
    .sidebar-foot .who { display: none; }
    .nav-link span { display: none; }
    .main { padding: 20px 16px 40px; }
    .grid.two, .grid.three { grid-template-columns: 1fr; }
    .log { grid-template-columns: 1fr; }
    .log .exc { grid-column: 1; }
}
