/* SDS Jel Takibi. Quiet, document-like UI: white surface, hairline borders, one accent (the dye blue) kept for data. */
:root {
  --bg: #ffffff;
  --subtle: #f7f7f5;
  --hover: #efefed;
  --text: #1f1f1d;
  --muted: #73726e;
  --faint: #a4a39f;
  --border: #e9e9e7;
  --border-strong: #d9d9d5;
  --accent: #2383e2;
  --good: #3f8361;
  --warn: #b7791f;
  --bad: #d1453f;
  --radius: 8px;
  --font: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #191919;
    --subtle: #202020;
    --hover: #2b2b2b;
    --text: #e8e8e6;
    --muted: #9b9a97;
    --faint: #6e6d6a;
    --border: #2e2e2e;
    --border-strong: #3d3d3d;
    --accent: #4f9ee8;
    --good: #5fae87;
    --warn: #d3a04a;
    --bad: #e5625c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

h1, h2 { margin: 0; line-height: 1.3; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 14px; }
p { margin: 0; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--bad); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* --- Top bar --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 48px;
  padding: 0 max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  margin-top: env(safe-area-inset-top);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: -.01em; }
.brand svg, .login-card > svg { color: var(--text); flex: none; }
.brand svg .band, .login-card > svg .band { fill: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.indicator { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.indicator .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.indicator.online .dot { background: var(--good); }
.indicator.offline .dot { background: var(--bad); }

.banner {
  padding: 8px 20px; font-size: 13px; color: var(--muted);
  background: var(--subtle); border-bottom: 1px solid var(--border);
}

/* --- Layout --- */
.layout {
  display: grid; gap: 16px;
  max-width: 1120px; margin: 0 auto;
  padding: 20px 20px max(40px, env(safe-area-inset-bottom));
  grid-template-columns: minmax(0, 1fr);
}
.col { display: grid; gap: 16px; min-width: 0; }
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr); align-items: start; }
}
/* One column on phones, in the order you need during a run: gel, auto mode, power, chart, activity. */
@media (max-width: 899px) {
  .layout { padding: 12px 12px max(32px, env(safe-area-inset-bottom)); gap: 12px; }
  .col { display: contents; }
  .o-live { order: 1; } .o-auto { order: 2; } .o-power { order: 3; } .o-chart { order: 4; } .o-feed { order: 5; }
}

.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 44px; padding: 0 16px;
  border-bottom: 1px solid var(--border);
}
.panel-body { padding: 16px; }

.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.tag.on { color: var(--text); }
.tag.on::before { background: var(--good); }

/* --- Buttons and inputs --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text);
  font: inherit; font-weight: 500; white-space: nowrap; cursor: pointer;
  transition: background .12s;
}
.btn svg { width: 15px; height: 15px; flex: none; color: var(--muted); }
.btn:hover { background: var(--hover); }
.btn:focus-visible, select:focus-visible, input:focus-visible, .link:focus-visible,
.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--bg); }
.btn.primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn.primary:hover { opacity: .88; }
.btn.primary:disabled:hover { background: var(--text); opacity: .4; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.small { height: 28px; padding: 0 8px; font-size: 13px; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy svg { visibility: hidden; }
.btn.busy::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid var(--muted); border-top-color: transparent; animation: spin .8s linear infinite;
}
.btn.primary.busy::after { border-color: var(--bg); border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

.link { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; font-size: 12.5px;
  text-decoration: underline; text-underline-offset: 2px; cursor: pointer; border-radius: 2px; }
.link:hover { color: var(--text); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions.two { display: grid; grid-template-columns: 1fr 1fr; }
.actions.end { justify-content: flex-end; }

select {
  height: 28px; max-width: 60%;
  padding: 0 6px; border-radius: 6px; border: 1px solid transparent;
  background: transparent; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer;
}
select:hover { background: var(--hover); }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; margin-left: auto; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  width: 30px; height: 18px; border-radius: 999px; background: var(--border-strong); position: relative; transition: background .12s;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; transition: transform .12s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(12px); }

/* --- Live panel --- */
.photo { position: relative; aspect-ratio: 5 / 4; background: #111; }
.photo img { width: 100%; height: 100%; object-fit: contain; display: block; cursor: zoom-in; }
.photo-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #777; font-size: 13px; }
.photo-time {
  position: absolute; left: 10px; bottom: 10px;
  padding: 2px 6px; border-radius: 4px; font-size: 12px; font-variant-numeric: tabular-nums;
  background: rgba(0, 0, 0, .6); color: #fff;
}
.photo-zoom {
  position: absolute; right: 10px; bottom: 10px; display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 4px; border: 0; cursor: pointer;
  background: rgba(0, 0, 0, .6); color: #fff;
}

.notice {
  padding: 10px 16px; font-size: 13px; border-bottom: 1px solid var(--border);
  display: flex; gap: 8px; align-items: baseline;
}
.notice::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); flex: none; transform: translateY(-1px); }
.notice.bad::before { background: var(--bad); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0; border-bottom: 1px solid var(--border); }
.stats > div { padding: 12px 16px; border-left: 1px solid var(--border); min-width: 0; }
.stats > div:first-child { border-left: 0; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 20px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats dd.idle { color: var(--faint); font-weight: 500; }
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stats > div:nth-child(3) { border-left: 0; }
  .stats > div:nth-child(n+3) { border-top: 1px solid var(--border); }
  .stats dd { font-size: 18px; }
}

.bar { position: relative; height: 6px; border-radius: 3px; background: var(--hover); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .6s ease; }
.tick { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--bg); }
.bar-labels { display: flex; justify-content: space-between; margin-top: 6px; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.live-actions { margin-top: 16px; }

/* --- Chart --- */
.chart { width: 100%; min-height: 200px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--border); }
.chart .grid text, .chart .axis text { fill: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .finish { stroke: var(--faint); stroke-dasharray: 3 3; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.chart .raw { fill: var(--accent); opacity: .22; }
.chart .snap { fill: var(--bg); stroke: var(--accent); stroke-width: 1.5; cursor: pointer; }
.chart .snap:hover, .chart .snap:focus-visible { fill: var(--accent); outline: none; }
.chart-empty { display: grid; place-items: center; min-height: 200px; color: var(--faint); font-size: 13px; }
.chart-hint { margin-top: 8px; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }

/* --- Auto mode panel --- */
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 10px 16px; }
.row + .row, .row + .check, .check + .row { border-top: 1px solid var(--border); }
.row-label { display: flex; align-items: center; gap: 10px; font-weight: 500; min-width: 0; }
.row-meta { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.step-num {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-size: 11px; font-weight: 600; border: 1px solid var(--border-strong); color: var(--muted);
}
.step-num.done { background: var(--good); border-color: var(--good); color: #fff; }
.panel-foot { padding: 10px 16px; border-top: 1px solid var(--border); }

.check { padding: 12px 16px 14px; background: var(--subtle); }
.check-summary { display: flex; gap: 8px; align-items: baseline; font-weight: 500; font-size: 13px; }
.check-summary::before { content: ""; width: 6px; height: 6px; border-radius: 50%; flex: none; transform: translateY(-1px); background: var(--bad); }
.check-summary.ready::before { background: var(--good); }
.checklist { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 4px; }
.checklist li { display: grid; grid-template-columns: 14px 1fr; gap: 6px; font-size: 12.5px; color: var(--muted); }
.checklist .ico { font-size: 11px; font-weight: 700; line-height: 1.7; }
.ico.ok { color: var(--good); }
.ico.warn { color: var(--warn); }
.ico.fail { color: var(--bad); }
.ico.skip { color: var(--faint); }
.checklist .lbl { color: var(--text); font-weight: 500; }
.check-photo { width: 100%; border-radius: 6px; margin-top: 12px; display: block; cursor: zoom-in; border: 1px solid var(--border); }

/* --- Feed --- */
.feed { list-style: none; margin: 0; padding: 0; max-height: 480px; overflow-y: auto; }
.feed li { display: grid; grid-template-columns: 6px 1fr auto; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--border); }
.feed li:first-child { border-top: 0; }
.feed .k { width: 6px; height: 6px; border-radius: 50%; margin-top: 7px; background: var(--border-strong); }
.feed .k.alert { background: var(--accent); }
.feed .k.warning, .feed .k.expired { background: var(--warn); }
.feed .k.failed { background: var(--bad); }
.feed .k.pending, .feed .k.running { background: var(--bg); border: 1.5px solid var(--muted); }
.feed .t { font-size: 13px; white-space: pre-line; overflow-wrap: anywhere; }
.feed .m { font-size: 12px; color: var(--faint); margin-top: 1px; font-variant-numeric: tabular-nums; }
.feed .thumb { width: 48px; height: 38px; object-fit: cover; border-radius: 4px; cursor: zoom-in; background: var(--subtle); }
.feed-empty { color: var(--faint); font-size: 13px; display: block !important; }

/* --- Login --- */
.login { display: grid; place-items: center; padding: 96px 20px 48px; }
.login-card { width: 100%; max-width: 300px; display: grid; gap: 14px; }
.login-card h1 { margin-bottom: 6px; }
.login-card label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.login-card input {
  height: 36px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text); font: inherit;
}
.login-card .btn { height: 36px; margin-top: 4px; }

/* --- Toasts and dialogs --- */
.toasts {
  position: fixed; z-index: 50; left: 50%; transform: translateX(-50%);
  bottom: max(20px, env(safe-area-inset-bottom)); width: min(380px, calc(100% - 32px));
  display: grid; gap: 6px;
}
.toast {
  padding: 10px 12px; border-radius: 6px; font-size: 13px; white-space: pre-line;
  background: var(--text); color: var(--bg); box-shadow: 0 4px 16px rgba(0, 0, 0, .14);
  animation: rise .15s ease-out;
}
.toast.bad { display: flex; gap: 8px; align-items: baseline; }
.toast.bad::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--bad); flex: none; transform: translateY(-1px); }
@keyframes rise { from { transform: translateY(6px); opacity: 0; } }

.dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
  background: var(--bg); color: var(--text); width: min(380px, calc(100% - 32px));
  box-shadow: 0 12px 40px rgba(0, 0, 0, .16);
}
.dialog::backdrop { background: rgba(15, 15, 15, .5); }
.dialog h2 { font-size: 15px; margin-bottom: 4px; }
.dialog .actions { margin-top: 20px; }
.lightbox { width: min(960px, calc(100% - 24px)); padding: 12px; }
.lightbox img { width: 100%; border-radius: 4px; display: block; }
.lightbox p { margin: 8px 2px 0; }
.lightbox .close { position: absolute; right: 18px; top: 18px; background: rgba(0, 0, 0, .6); color: #fff; }

/* Touch sizes; 16px inputs stop iOS from zooming in on focus. */
@media (max-width: 899px) {
  .btn { height: 38px; }
  .btn.small { height: 32px; }
  .login-card input, .login-card .btn { height: 42px; }
  .login-card input, select { font-size: 16px; }
  .login { padding-top: 56px; }
  .topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .live-actions .btn { flex: 1 1 0; }
  .switch { margin-left: 4px; }
}

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