/* Libani – Data Logging · dark theme */
:root {
    --bg: #0a1020;
    --bg-2: #0e1628;
    --surface: #121b30;
    --surface-2: #17223b;
    --border: #243152;
    --border-2: #2e3d63;
    --text: #e7ecf6;
    --muted: #8f9cb8;
    --accent: #e8742a;          /* Libani leaf orange */
    --accent-2: #f39a5b;
    --accent-soft: rgba(232, 116, 42, .14);
    --ok: #22c55e;
    --warn: #f59e0b;
    --bad: #ef4444;
    --ph-r: #ef4444;
    --ph-y: #eab308;
    --ph-b: #3b82f6;
    --radius: 12px;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(1200px 500px at 90% -10%, rgba(232, 116, 42, .08), transparent 60%),
        radial-gradient(900px 500px at -10% 0%, rgba(59, 130, 246, .07), transparent 60%),
        var(--bg);
    color: var(--text);
    font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: .95rem; font-weight: 600; margin-top: 1.4em; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; letter-spacing: .02em; }
.upper { text-transform: uppercase; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }

/* ---------- top bar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 10px 24px;
    background: rgba(10, 16, 32, .85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand:hover { text-decoration: none; }
.brand img { height: 46px; width: auto; display: block; }
.brand-sub {
    color: var(--muted); font-weight: 600; font-size: .8rem;
    text-transform: uppercase; letter-spacing: .14em;
    padding-left: 14px; border-left: 1px solid var(--border-2);
}
.profile { position: relative; }
.profile-btn {
    display: flex; align-items: center; gap: 10px;
    background: var(--surface); border: 1px solid var(--border); color: var(--text);
    border-radius: 999px; padding: 5px 12px 5px 5px; cursor: pointer; font: inherit;
}
.profile-btn:hover { border-color: var(--border-2); }
.avatar {
    width: 30px; height: 30px; border-radius: 50%;
    display: grid; place-items: center;
    background: linear-gradient(135deg, var(--accent), #c2410c); color: #fff; font-weight: 700;
}
.pname { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu {
    position: absolute; right: 0; top: calc(100% + 8px); min-width: 250px;
    background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 6px; z-index: 30;
}
.menu-head { padding: 10px 12px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; display: grid; gap: 3px; }
.menu-head small { color: var(--muted); word-break: break-all; }
.menu-head .badge { justify-self: start; margin-top: 4px; }
.menu a, .menu-logout {
    display: block; width: 100%; text-align: left; padding: 9px 12px; border-radius: 8px;
    color: var(--text); background: none; border: 0; font: inherit; cursor: pointer;
}
.menu a:hover, .menu-logout:hover { background: var(--surface-2); text-decoration: none; }
.menu-logout { color: #fca5a5; }

/* ---------- layout ---------- */
.container { width: 100%; max-width: 1400px; margin: 0 auto; padding: 24px; flex: 1; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 18px; border-top: 1px solid var(--border); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { opacity: .5; }

.card {
    background: linear-gradient(180deg, var(--surface), var(--bg-2));
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; margin-bottom: 18px;
}
.card.narrow { max-width: 620px; }
.card.notice { max-width: 680px; }
.card.notice.bad { border-color: rgba(239, 68, 68, .45); }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.empty { color: var(--muted); text-align: center; padding: 24px; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border-2);
    background: var(--surface-2); color: var(--text); font: inherit; font-weight: 500;
    cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: #1d2a48; border-color: #3a4c78; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #d4641d; border-color: #d4641d; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: #fca5a5; border-color: rgba(239, 68, 68, .5); }
.btn.danger:hover { background: rgba(239, 68, 68, .12); }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }
.btn-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 6px; }

/* ---------- forms ---------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: .85rem; font-weight: 500; color: #c7d0e3; }
.field small { font-weight: 400; color: var(--muted); }
input, select {
    width: 100%; padding: 10px 12px; border-radius: 8px;
    background: var(--bg); border: 1px solid var(--border-2); color: var(--text); font: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled { opacity: .6; }
input[type=date] { color-scheme: dark; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
.filter { max-width: 360px; margin-bottom: 14px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.toolbar .filter { margin-bottom: 14px; }
form.inline select { width: auto; min-width: 220px; }
.danger-zone { display: flex; gap: 10px; flex-wrap: wrap; justify-content: space-between; margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--border-2); }

/* ---------- flash & badges ---------- */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; font-size: .92rem; }
.flash.success { background: rgba(34, 197, 94, .1); border-color: rgba(34, 197, 94, .4); color: #bbf7d0; }
.flash.error { background: rgba(239, 68, 68, .1); border-color: rgba(239, 68, 68, .45); color: #fecaca; }
.flash.warn { background: rgba(245, 158, 11, .1); border-color: rgba(245, 158, 11, .45); color: #fde68a; }
.flash.info { background: rgba(59, 130, 246, .1); border-color: rgba(59, 130, 246, .45); color: #bfdbfe; }
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600;
    border: 1px solid var(--border-2); background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.ok { color: #86efac; border-color: rgba(34, 197, 94, .4); background: rgba(34, 197, 94, .1); }
.badge.warn { color: #fcd34d; border-color: rgba(245, 158, 11, .4); background: rgba(245, 158, 11, .1); }
.badge.bad { color: #fca5a5; border-color: rgba(239, 68, 68, .4); background: rgba(239, 68, 68, .1); }
.badge.accent { color: var(--accent-2); border-color: rgba(232, 116, 42, .45); background: var(--accent-soft); }
.badge.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.st-queued { color: #fcd34d; border-color: rgba(245, 158, 11, .4); }
.badge.st-sent { color: #93c5fd; border-color: rgba(59, 130, 246, .45); }
.badge.st-applied { color: #86efac; border-color: rgba(34, 197, 94, .4); }

/* ---------- login ---------- */
body.guest .container { display: grid; place-items: center; }
.auth-wrap { width: 100%; display: grid; place-items: center; padding: 30px 0; }
.auth-card {
    width: 100%; max-width: 420px; padding: 32px;
    background: linear-gradient(180deg, var(--surface), var(--bg-2));
    border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
}
.auth-logo { display: block; width: 190px; max-width: 70%; margin: 0 auto 22px; }
.auth-card h1 { font-size: 1.35rem; text-align: center; margin-bottom: 4px; }
.auth-card > .muted { text-align: center; margin: 0 0 20px; }
.auth-card .btn-row .btn { flex: 1; }
.hint { font-size: .82rem; color: var(--muted); text-align: center; margin: 18px 0 0; }

/* ---------- home ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat span { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.stat b { display: block; font-size: 1.8rem; font-weight: 700; margin-top: 4px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.tile {
    display: grid; gap: 8px; padding: 22px; min-height: 150px;
    background: linear-gradient(160deg, var(--surface-2), var(--surface));
    border: 1px solid var(--border); border-radius: 14px; color: var(--text);
    transition: transform .15s, border-color .15s, box-shadow .15s;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 8px 24px rgba(232, 116, 42, .15); text-decoration: none; }
.tile svg { width: 30px; height: 30px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tile strong { font-size: 1.05rem; }
.tile span { color: var(--muted); font-size: .88rem; }

/* ---------- pick lists ---------- */
.pick-list { display: grid; gap: 8px; }
.pick {
    display: grid; grid-template-columns: minmax(160px, 1.2fr) 1fr auto; gap: 12px; align-items: center;
    padding: 13px 16px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--border); color: var(--text);
}
.pick:hover { border-color: var(--accent); text-decoration: none; background: var(--surface-2); }
.pick-badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; max-height: 70vh; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.table thead th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; z-index: 1; white-space: nowrap; }
.table tbody tr:nth-child(even) { background: rgba(255, 255, 255, .015); }
.table tbody tr:hover { background: rgba(232, 116, 42, .06); }
.table.data td { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.table.data th { text-align: right; }
.table.data .c-ts, .table.data .c-dev_id { text-align: left; }
.table.data thead tr:first-child th { top: 0; border-bottom: 0; padding-bottom: 2px; }
.table.data thead tr.units th { top: 30px; font-weight: 400; color: var(--muted); font-size: .75rem; padding-top: 0; }
.table.data td.ok { color: var(--ok); font-weight: 600; }
.table.data td.bad { color: var(--bad); font-weight: 600; }
.table.compact td, .table.compact th { padding: 7px 10px; }
.table-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.table-meta.end { justify-content: flex-end; margin-bottom: 0; }

.pager { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pg { padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border); color: var(--text); font-size: .85rem; }
a.pg:hover { border-color: var(--accent); text-decoration: none; }
.pg.current { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.pg.disabled { opacity: .35; }
.pg-info { color: var(--muted); font-size: .85rem; margin-left: 8px; }

/* ---------- column chooser ---------- */
.col-chooser { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.chip {
    display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none;
    padding: 5px 10px; border-radius: 999px; font-size: .8rem; font-weight: 500;
    border: 1px solid var(--border-2); background: var(--bg-2); color: var(--muted);
}
.chip:has(input:checked) { color: var(--text); border-color: rgba(232, 116, 42, .6); background: var(--accent-soft); }

/* ---------- device page ---------- */
.device-head { display: grid; gap: 18px; }
.device-meta { display: flex; flex-wrap: wrap; gap: 14px 32px; }
.device-meta > div { display: grid; gap: 4px; }
.device-meta span.muted { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; }
.live { display: flex; flex-wrap: wrap; gap: 14px; padding-top: 16px; border-top: 1px solid var(--border); }
.live-group { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; display: grid; gap: 6px; }
.live-group > span { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; }
.phases { display: flex; gap: 14px; }
.phases b { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; display: flex; align-items: baseline; gap: 4px; }
.phases small { font-size: .7rem; font-weight: 600; opacity: .8; }
.ph-r small { color: var(--ph-r); }
.ph-y small { color: var(--ph-y); }
.ph-b small { color: var(--ph-b); }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin: 14px 0; }
.setting input { font-size: 1.1rem; font-weight: 600; }
.setting input.changed { border-color: var(--accent); background: rgba(232, 116, 42, .08); }

/* ---------- dialog ---------- */
.dialog {
    width: min(520px, calc(100vw - 32px)); padding: 24px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border-2); border-radius: 14px; box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(3, 7, 18, .7); backdrop-filter: blur(3px); }
.dialog form { display: grid; gap: 14px; }
.formats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.format { cursor: pointer; }
.format input { position: absolute; opacity: 0; pointer-events: none; }
.format span {
    display: block; text-align: center; padding: 14px 8px; border-radius: 10px; font-weight: 600;
    border: 1px solid var(--border-2); background: var(--bg-2);
}
.format input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-2); }
.format input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- graphs ---------- */
.range-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.graph-note { margin-left: auto; }
.chart-box { position: relative; height: 320px; }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
    .container { padding: 16px; }
    .topbar { padding: 8px 16px; }
    .brand img { height: 36px; }
    .brand-sub, .pname { display: none; }
    .pick { grid-template-columns: 1fr; }
    .pick-badges { justify-content: flex-start; }
    .card { padding: 16px; }
    .chart-box { height: 260px; }
    .graph-note { margin-left: 0; }
}
