:root {
  --bg: #f3f1ec; --panel: #ffffff; --panel-2: #f8f7f3; --ink: #1d1f1c; --muted: #6b6f66; --line: #e2dfd6;
  --accent: #2f7d4f; --accent-ink: #ffffff; --warn: #b7791f; --bad: #b83a2e; --info: #2b6cb0;
  --ok-bg: #e3f1e8; --warn-bg: #fbefd9; --bad-bg: #f8e1de; --info-bg: #e2ecf7;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121411; --panel: #1b1e1a; --panel-2: #222620; --ink: #e8eae4; --muted: #9aa094; --line: #2e332c;
    --accent: #5cc285; --accent-ink: #0d1a12; --warn: #e2a84b; --bad: #ec6b5e; --info: #74a9e8;
    --ok-bg: #1e3326; --warn-bg: #3a2f1a; --bad-bg: #3d2220; --info-bg: #1d2b3d;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.hidden { display: none !important; }

/* top bar */
header { position: sticky; top: 0; z-index: 10; background: var(--panel); border-bottom: 1px solid var(--line); }
.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; max-width: 1200px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand svg { color: var(--accent); }
.bar .spacer { flex: 1; }
nav { display: flex; gap: 2px; overflow-x: auto; max-width: 1200px; margin: 0 auto; padding: 0 10px; scrollbar-width: none; }
nav button { background: none; border: 0; padding: 10px 12px; color: var(--muted); font: inherit; font-weight: 600;
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
nav button.active { color: var(--ink); border-bottom-color: var(--accent); }

main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
@media (max-width: 520px) { .grid.two { grid-template-columns: 1fr; } main { padding: 12px; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card > h2 { margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.span-all { grid-column: 1 / -1; }

/* hero */
.hero { display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center; }
@media (max-width: 700px) { .hero { grid-template-columns: 1fr; } }
.hero .mode { font-size: 24px; font-weight: 750; }
.hero .sub { color: var(--muted); }
.light { width: 46px; height: 46px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 6px var(--panel-2); }
.light.ok { background: var(--accent); } .light.warn { background: var(--warn); } .light.bad { background: var(--bad); }
.light.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px var(--panel-2); } }
.kpis { display: flex; gap: 22px; flex-wrap: wrap; }
.kpi .v { font-size: 22px; font-weight: 700; font-family: var(--mono); }
.kpi .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.progress { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--warn); transition: width .5s; }

dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px; font-size: 12px;
  font-weight: 650; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--accent); } .chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); } .chip.info { background: var(--info-bg); color: var(--info); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
.table-wrap { overflow-x: auto; }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }

button.btn, a.btn { font: inherit; font-weight: 600; border-radius: 9px; padding: 8px 14px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; gap: 6px; align-items: center; }
button.btn:hover { border-color: var(--muted); }
button.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.btn.danger { color: var(--bad); }
button.btn.small { padding: 4px 10px; font-size: 13px; }
button.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-weight: 500; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 10px; }
.note { background: var(--panel-2); border-radius: 9px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }
.note.warn { background: var(--warn-bg); } .note.bad { background: var(--bad-bg); }

/* clients */
.client-name { font-weight: 650; }
.client-sub { color: var(--muted); font-size: 13px; }

/* sky plot */
.sky { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: start; }
@media (max-width: 560px) { .sky { grid-template-columns: 1fr; } .sky svg { max-width: 260px; margin: 0 auto; } }
.sky svg { width: 100%; height: auto; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 120px; border-bottom: 1px solid var(--line); }
.bars div { flex: 1; min-width: 3px; border-radius: 3px 3px 0 0; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; background: var(--c); }

/* events */
.events { max-height: 520px; overflow: auto; font-size: 14px; }
.event { display: grid; grid-template-columns: 130px 90px 1fr; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
@media (max-width: 560px) { .event { grid-template-columns: 1fr; gap: 2px; } }
.event .t { color: var(--muted); font-family: var(--mono); font-size: 12px; }

/* modal + toast */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; padding: 18px; width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; }
.modal h3 { margin-bottom: 12px; }
.cred { background: var(--panel-2); border-radius: 10px; padding: 12px; font-family: var(--mono); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 60; max-width: 90vw; }
#toast.err { background: var(--bad); color: #fff; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; padding: 24px; }
.login h1 { font-size: 22px; margin: 12px 0 4px; }
