@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&display=swap');

/* Dark (default). Light palette applies via .light on <html> (manual toggle) or
   the system preference when the user hasn't chosen. */
:root {
  --bg: #0d1117; --card: #161b22; --fg: #c9d1d9; --muted: #8b949e;
  --border: #30363d; --accent: #2f81f7; --danger: #f85149; --ok: #3fb950;
  --warning: #d29922;
  --inset: #0d1117; --btn: #21262d;
  --hover: rgba(255, 255, 255, .045); --sel: rgba(47, 129, 247, .15);
}
:root.light {
  --bg: #f3f6fb; --card: #ffffff; --fg: #1a202c; --muted: #6b7a99;
  --border: #dce3ef; --accent: #1a6ef5; --danger: #d93025; --ok: #1e8a3c;
  --warning: #b45309;
  --inset: #eef2f8; --btn: #e9eef6;
  --hover: rgba(20, 40, 80, .05); --sel: rgba(26, 110, 245, .12);
}
@media (prefers-color-scheme: light) {
  :root:not(.dark):not(.light) {
    --bg: #f3f6fb; --card: #ffffff; --fg: #1a202c; --muted: #6b7a99;
    --border: #dce3ef; --accent: #1a6ef5; --danger: #d93025; --ok: #1e8a3c;
    --warning: #b45309;
    --inset: #eef2f8; --btn: #e9eef6;
    --hover: rgba(20, 40, 80, .05); --sel: rgba(26, 110, 245, .12);
  }
}
/* thin custom scrollbar (6px, thumb = border color) */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.tag { font-size: 11px; color: var(--muted); font-weight: 400; margin-left: 6px; }
.status { display: flex; align-items: center; gap: 12px; }
.dot { font-size: 12px; color: var(--muted); padding-left: 14px; position: relative; }
.dot::before {
  content: ''; position: absolute; left: 0; top: 5px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--muted);
}
.dot.online { color: var(--ok); } .dot.online::before { background: var(--ok); }
.save { font-size: 12px; color: var(--muted); }
main { max-width: 1000px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.card h2 { font-size: 14px; margin: 0 0 12px; color: var(--muted); font-weight: 600; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.row label { color: var(--muted); }
.grow { flex: 1; } .spacer { flex: 1; }
input, select, button { font: inherit; }
input, select {
  background: var(--inset); color: var(--fg); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px;
}
input.narrow { width: 90px; } input#param-name { min-width: 160px; }
input[type=range] { padding: 0; }
button {
  background: var(--btn); color: var(--fg); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.chip { padding: 3px 10px; font-size: 12px; }
button.danger { color: var(--danger); }
.muted { color: var(--muted); } .small { font-size: 12px; }
.list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 180px; overflow: auto; }
.list li {
  display: flex; align-items: center; gap: 10px; padding: 7px 6px;
  border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums;
  font-size: 16px;
}
.list li.del { opacity: .4; text-decoration: line-through; }
.list .t { color: var(--muted); font-size: 14px; min-width: 104px; }
.list .badge { font-size: 13px; padding: 2px 8px; border: 1px solid var(--border); border-radius: 10px; }
.list .aval { font-weight: 700; }
.list button { padding: 2px 8px; font-size: 12px; margin-left: auto; }
.chart { width: 100%; height: 260px; display: block; margin-top: 10px;
  background: var(--inset); border: 1px solid var(--border); border-radius: 6px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--muted); font-weight: 600; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--hover); }
tbody tr.sel { background: var(--sel); }
td.num { text-align: right; }
.hit-good { color: var(--ok); } .fp-bad { color: var(--danger); }
tbody tr.clickable:hover { background: var(--hover); }
.ecu-ddis:empty { display: none; }
.ecu-ddis { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.ddi-tbl td, .ddi-tbl th { font-size: 14px; }
.ddi-tbl .hit-good { font-weight: 600; }
.bus-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .bus-grid { grid-template-columns: 1fr; } }
.sub { font-size: 12px; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
td a, .sub a { color: var(--accent); text-decoration: none; }
td a:hover { text-decoration: underline; }
.guide { background: var(--inset); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 12px; margin: 4px 0 8px; font-size: 13px; }
.guide ol { margin: 6px 0 0; padding-left: 20px; }
.warnings:empty { display: none; }
.warnings { margin: 6px 0; }
.warn { display: block; color: var(--danger); font-size: 12px; padding: 2px 0; }
.warn.okmsg { color: var(--ok); }
#candidate-explain { min-height: 18px; margin: 8px 2px; }
dialog { background: var(--card); color: var(--fg); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.login-form { display: flex; flex-direction: column; gap: 8px; min-width: 260px; }

/* Login gate — covers the whole app until signed in. :not([hidden]) so the
   `hidden` attribute wins over this ID rule's display. */
#login-gate:not([hidden]) { position: fixed; inset: 0; z-index: 300; display: flex;
  align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.gate-card { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 340px;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 28px 24px; }
.gate-title { margin: 0; font-size: 26px; font-weight: 700; }
.gate-sub { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.gate-card input { font-size: 16px; padding: 11px; }
.gate-card .primary { padding: 11px; font-size: 16px; font-weight: 600; }
.gate-card .warn { min-height: 16px; }
.explorer { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.spark { border: 1px solid var(--border); border-radius: 6px; padding: 6px; cursor: pointer; background: var(--inset); }
.spark.sel { border-color: var(--accent); }
.spark canvas { width: 100%; height: 32px; display: block; }
.spark .lbl { font-size: 11px; color: var(--muted); margin-top: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#user-badge { color: var(--ok); background: rgba(63, 185, 80, .18);
  padding: 2px 8px; border-radius: 10px; }
#theme-toggle { font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; }
.detail:empty { display: none; }
.detail { background: var(--inset); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; margin: 8px 0; }
.detail-title { font-weight: 600; margin-bottom: 6px; }
.mono { font-family: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace; }
.frame-tbl { width: auto; margin: 8px 0; border: 1px solid var(--border); }
.frame-tbl th, .frame-tbl td { border: 1px solid var(--border); padding: 3px 8px; text-align: center; }
.frame-tbl td:first-child, .frame-tbl th:first-child { color: var(--muted); text-align: right; }
/* Big field-logging button — tappable blind (looking at the machine monitor). */
.biglog {
  width: 100%; min-height: 108px; margin: 10px 0 4px; padding: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); border: none; border-radius: 12px; color: #fff;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: transform .05s ease, filter .05s ease;
}
.biglog:active { transform: scale(.98); filter: brightness(.9); }
.biglog .big-main { font-size: 2rem; font-weight: 800; letter-spacing: .04em; }
.biglog .big-sub { font-size: 1rem; opacity: .92; }
.biglog .big-count { font-size: .85rem; opacity: .8; }
.big-status { font-size: 13px; color: var(--muted); }

/* Left half = manual button, right half = auto-recording (metronome). */
.record-split { display: flex; gap: 10px; margin: 10px 0 4px; align-items: stretch; }
.record-split .biglog { flex: 1; width: auto; margin: 0; }
.autopanel { flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; padding: 10px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--inset); text-align: center; }
.autopanel.running { border-color: var(--ok); }
.auto-title { font-weight: 800; letter-spacing: .06em; color: var(--muted); }
.autopanel.running .auto-title { color: var(--ok); }
.auto-freq { font-size: 13px; color: var(--muted); }
.auto-freq input { width: 64px; }
.auto-count { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.autopanel.running .auto-count { color: var(--ok); }
.auto-btn { font-size: 1.05rem; font-weight: 700; padding: 8px 16px;
  background: var(--accent); color: #fff; border: none; border-radius: 10px; }
.autopanel.running .auto-btn { background: var(--danger); }
.auto-sound { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

@media (max-width: 720px) {
  .record-split { flex-direction: column; }  /* stack on the phone */
  .record-split .biglog { min-height: 22vh; }
  .biglog .big-main { font-size: 2.6rem; }
  .autopanel { min-height: 18vh; }
  .auto-count { font-size: 2.4rem; }
}

/* Zámek obrazovky — celoobrazovkový režim jen na logování */
/* :not([hidden]) so the `hidden` attribute actually hides it — an ID rule with a
   bare `display:flex` would otherwise outrank the UA `[hidden]{display:none}`. */
#lock-overlay:not([hidden]) { position: fixed; inset: 0; z-index: 200; display: flex;
  flex-direction: column; background: var(--bg); padding: 10px; gap: 10px; }
.lock-log { flex: 1; width: 100%; border: none; border-radius: 16px; background: var(--accent);
  color: #fff; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  padding: 0 14px; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; }
.lock-log:active { filter: brightness(.9); }
.lock-log .lock-main { font-size: 2.4rem; font-weight: 800; letter-spacing: .04em; }
.lock-log .lock-sub { font-size: 1.2rem; opacity: .92; }
.lock-log .lock-count { font-size: 1rem; opacity: .82; }
.unlock { align-self: center; min-width: 220px; padding: 12px 20px; border-radius: 10px;
  background: var(--btn); color: var(--fg); border: 1px solid var(--border); font-size: 15px; }
.unlock.holding { background: var(--danger); color: #fff; }
.hl-ddi { color: var(--accent); font-weight: 600; }
.hl-val { color: var(--ok); font-weight: 700; }
.seq-wrap { max-height: 360px; overflow: auto; margin-top: 4px; }
.frame-tbl.seq { width: 100%; }
.frame-tbl.seq td:nth-child(3) { text-align: left; }

/* Section 5 (Korelace) — bigger, easier-to-read values */
#results th, #results td { font-size: 15px; }
#results td.num { font-size: 17px; font-weight: 600; }
#signal-detail { font-size: 14px; }
#signal-detail .val-line { font-size: 16px; margin: 8px 0; }
#signal-detail .val-line .hl-val { font-size: 1.2em; }
.frame-tbl.seq th, .frame-tbl.seq td { font-size: 14px; }
.frame-tbl.seq td:last-child { font-size: 16px; }

/* Unit conversion box (raw × coefficient → real units) */
.scale-box { background: var(--inset); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; margin: 8px 0; font-size: 14px; display: flex; flex-wrap: wrap;
  align-items: center; gap: 6px; }
.scale-title { font-weight: 600; color: var(--muted); }
.scale-box input.narrow { width: 84px; }
.scale-out { font-size: 17px; }
.scale-out b { color: var(--ok); }
.cloud-row #cloud-status { color: var(--muted); }
/* success note (validace akcí) — tinted panel per the design tokens */
.warn.okmsg { background: rgba(63, 185, 80, .12); border: 1px solid rgba(63, 185, 80, .3);
  border-radius: 6px; padding: 6px 10px; }
