:root {
  --bg: #f8fafc; --panel: #ffffff; --fg: #0f172a; --muted: #64748b;
  --line: #e2e8f0; --accent: #2563eb; --accent-fg: #ffffff;
  --pos: #15803d; --neg: #b91c1c; --chip: #f1f5f9;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --panel: #111c33; --fg: #e2e8f0; --muted: #94a3b8;
    --line: #23314f; --accent: #60a5fa; --accent-fg: #0b1220;
    --pos: #4ade80; --neg: #f87171; --chip: #1b2742;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 8px 12px; border-radius: 8px; color: var(--muted);
  text-decoration: none; white-space: nowrap; font-weight: 500;
}
.tabs a.on { background: var(--chip); color: var(--fg); }

main { max-width: 1100px; margin: 0 auto; padding: 12px 16px 40px; }

.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.filters button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 5px 12px; cursor: pointer; font-size: 14px;
}
.filters button.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }

.picker { position: relative; }
#search {
  width: 100%; padding: 11px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel); font-size: 16px; /* 16px: iOS nu mai face zoom */
}
.results {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px);
  list-style: none; margin: 0; padding: 4px; max-height: min(60vh, 420px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgb(0 0 0 / .18);
}
.results li { padding: 10px 10px; border-radius: 8px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.results li:hover, .results li.hl { background: var(--chip); }
.results li .meta { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.results li.head { cursor: default; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px 2px; }
.results li.head:hover { background: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--chip);
  border-radius: 999px; padding: 4px 4px 4px 10px; font-size: 14px; max-width: 100%;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.chip .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button {
  border: 0; background: none; cursor: pointer; width: 28px; height: 28px;
  border-radius: 50%; color: var(--muted); font-size: 18px; line-height: 1;
}
.chip button:hover { background: var(--line); }

.controls { display: grid; gap: 8px; margin-bottom: 10px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: flex; flex-wrap: wrap; gap: 2px; background: var(--chip); border-radius: var(--radius); padding: 3px; width: fit-content; max-width: 100%; }
.seg button {
  border: 0; background: none; padding: 7px 11px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 500; color: var(--muted); min-width: 40px;
}
.seg button.on { background: var(--panel); color: var(--fg); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.seg.small button { padding: 6px 10px; }
select, input[type=date] {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
}
button.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 6px 4px; }
.custom button {
  border: 0; background: var(--accent); color: var(--accent-fg); padding: 8px 14px;
  border-radius: 8px; cursor: pointer; font-weight: 600;
}
.toggle { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }

.chart {
  height: min(62vh, 460px); min-height: 280px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  touch-action: pan-y; /* glisarea verticala ramane a paginii */
}
.chart.tall { height: min(70vh, 560px); }
.note { color: var(--muted); font-size: 13px; margin: 8px 2px; }

/* metrici: tabel pe ecran lat, carduri pe telefon */
.metrics table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.metrics th, .metrics td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
.metrics th { font-size: 12px; color: var(--muted); font-weight: 600; }
.metrics th:first-child, .metrics td:first-child { text-align: left; white-space: normal; }
.metrics tr:last-child td { border-bottom: 0; }
.metrics .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }

.cards { display: grid; gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.card h3 { margin: 0 0 6px; font-size: 15px; display: flex; align-items: center; }
.card dl { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin: 0; }
.card dt { color: var(--muted); font-size: 12px; }
.card dd { margin: 0 0 4px; font-variant-numeric: tabular-nums; font-weight: 600; }
@media (min-width: 760px) { .cards { display: none; } }
@media (max-width: 759px) { .metrics table { display: none; } }

.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

[hidden] { display: none !important; }

/* telefon: perioadele pe un singur rand, pe toata latimea; mai putin spatiu pierdut */
@media (max-width: 600px) {
  main { padding: 10px 12px 32px; }
  .top { gap: 10px; padding-left: 12px; padding-right: 12px; }
  .seg#periods, .seg#usIntervals { width: 100%; flex-wrap: nowrap; }
  .seg#periods button, .seg#usIntervals button { flex: 1; min-width: 0; padding: 8px 0; }
  .chart { height: 52vh; min-height: 260px; }
  .chart.tall { height: 60vh; }
}
