/* QR-haldus – haldusliidese stiilid */
:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --line: #e2e0d9;
  --line-strong: #cfccc2;
  --ink: #17171a;
  --ink-2: #4f4e4a;
  --ink-3: #7c7a73;
  --accent: #0f5f8c;
  --accent-ink: #ffffff;
  --accent-soft: #e5f0f7;
  --series-1: #2a78d6;
  --ok: #1f7a3a;
  --ok-soft: #e4f3e8;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --err: #b42318;
  --err-soft: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 20, .05), 0 2px 8px rgba(20, 20, 20, .04);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121214;
    --surface: #1b1b1e;
    --surface-2: #202024;
    --line: #2e2e33;
    --line-strong: #3b3b41;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #8f8e88;
    --accent: #5aaee0;
    --accent-ink: #0d1b24;
    --accent-soft: #16283a;
    --series-1: #3987e5;
    --ok: #5cc27a;
    --ok-soft: #15291c;
    --warn: #e0b04d;
    --warn-soft: #2d2412;
    --err: #f2786d;
    --err-soft: #331a18;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.55rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
code, .mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

/* --- päis ----------------------------------------------------------- */
.top {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.top-inner {
  max-width: 1240px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 24px; min-height: 58px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--ink);
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 5px;
}
.brand-mark i { background: var(--surface); border-radius: 1px; }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(4), .brand-mark i:nth-child(8) { background: transparent; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { white-space: nowrap; color: var(--ink-2); padding: 7px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.who { display: flex; align-items: center; gap: 12px; color: var(--ink-3); font-size: .85rem; white-space: nowrap; }
.who form { margin: 0; }
.menu-toggle { display: none; }

main { max-width: 1240px; margin: 0 auto; padding: 28px 20px 60px; }

/* --- komponendid ---------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { margin-top: 4px; color: var(--ink-3); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; font-size: .9rem;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
.btn.small { padding: 5px 10px; font-size: .82rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 20px; font-weight: 500; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.err { background: var(--err-soft); color: var(--err); }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: var(--err-soft); color: var(--err); }
.badge.wait { background: var(--warn-soft); color: var(--warn); }
.tag { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); margin: 2px 4px 2px 0; }
.type { font-size: .78rem; color: var(--ink-3); }

/* --- statistikaplokid ---------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: .8rem; color: var(--ink-3); font-weight: 500; }
.tile .value { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; margin-top: 2px; }
.tile .hint { font-size: .78rem; color: var(--ink-3); }

/* --- tabel ---------------------------------------------------------- */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
td .title { font-weight: 600; color: var(--ink); }
td .target { font-size: .82rem; color: var(--ink-3); max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb { width: 44px; height: 44px; border-radius: 6px; border: 1px solid var(--line); background: #fff; display: block; }
tbody tr:hover { background: var(--surface-2); }
.row-link { color: inherit; }
.row-link:hover { text-decoration: none; }

/* --- filtrid -------------------------------------------------------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type=search] { flex: 1; min-width: 200px; }

/* --- vormid --------------------------------------------------------- */
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 5px; }
.field { margin-bottom: 16px; }
.field .help { font-size: .8rem; color: var(--ink-3); margin-top: 4px; font-weight: 400; }
.field .error { font-size: .82rem; color: var(--err); margin-top: 4px; font-weight: 500; }
.field.has-error input, .field.has-error textarea, .field.has-error select { border-color: var(--err); }
input[type=text], input[type=url], input[type=email], input[type=password], input[type=search],
input[type=datetime-local], input[type=date], input[type=tel], input[type=number], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: .93rem;
}
select { width: auto; }
.filters select, .filters input { width: auto; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 16px; height: 16px; margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 700; font-size: 1.05rem; margin-bottom: 4px; padding: 0; }
.prefix { display: flex; align-items: stretch; }
.prefix span { padding: 8px 10px; background: var(--surface-2); border: 1px solid var(--line-strong); border-right: 0; border-radius: 8px 0 0 8px; color: var(--ink-3); font-size: .9rem; white-space: nowrap; }
.prefix input { border-radius: 0 8px 8px 0; }

.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.sticky { position: sticky; top: 78px; }
.section-title { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.section-title .n { width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: .8rem; font-weight: 700; display: grid; place-items: center; }

.type-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 18px; }
.type-picker a {
  border: 1px solid var(--line-strong); border-radius: 9px; padding: 10px 8px; text-align: center;
  color: var(--ink-2); font-weight: 600; font-size: .85rem; background: var(--surface);
}
.type-picker a:hover { text-decoration: none; border-color: var(--accent); }
.type-picker a.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.type-picker svg { display: block; margin: 0 auto 4px; width: 22px; height: 22px; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 6px 12px; font-size: .85rem; font-weight: 500; cursor: pointer; color: var(--ink-2); border-left: 1px solid var(--line-strong); }
.seg label:first-child span { border-left: 0; }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

.colors { display: flex; gap: 14px; flex-wrap: wrap; }
.color { display: flex; align-items: center; gap: 8px; font-size: .85rem; font-weight: 500; margin: 0; }
.color input[type=color] { width: 36px; height: 32px; padding: 0; border: 1px solid var(--line-strong); border-radius: 6px; background: none; cursor: pointer; }

.preview-box {
  background: repeating-conic-gradient(var(--surface-2) 0% 25%, var(--surface) 0% 50%) 50% / 16px 16px;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; place-items: center; min-height: 300px;
}
.preview-box svg, .preview-box img { width: 100%; max-width: 300px; height: auto; display: block; }
.preview-meta { font-size: .8rem; color: var(--ink-3); margin-top: 8px; text-align: center; }
.warn-box { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 8px; font-size: .85rem; margin-bottom: 14px; }
.info-box { background: var(--accent-soft); color: var(--accent); padding: 10px 12px; border-radius: 8px; font-size: .85rem; margin-bottom: 14px; }
details.more { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
details.more summary { cursor: pointer; font-weight: 600; color: var(--ink-2); margin-bottom: 12px; }

/* --- koodi vaade ---------------------------------------------------- */
.code-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start; }
.code-layout > *, .form-layout > * { min-width: 0; }
.qr-card .qr { background: #fff; border-radius: 8px; padding: 8px; border: 1px solid var(--line); }
.qr-card .qr svg { width: 100%; height: auto; display: block; }
.short-link { display: flex; align-items: center; gap: 8px; margin: 14px 0; padding: 8px 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; }
.short-link code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; }
.dl-group { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.kv { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 8px 12px; margin: 0; font-size: .9rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; word-break: break-word; }
.history { list-style: none; padding: 0; margin: 0; font-size: .85rem; }
.history li { padding: 9px 0; border-bottom: 1px solid var(--line); }
.history li:last-child { border-bottom: 0; }
.history .when { color: var(--ink-3); font-size: .78rem; }
.history del { color: var(--ink-3); }
.danger-zone { border-color: color-mix(in srgb, var(--err) 35%, var(--line)); }

/* --- graafikud ------------------------------------------------------ */
.range { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.range .seg span { padding: 5px 10px; }
.range input[type=date] { width: auto; padding: 5px 8px; font-size: .85rem; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--ink-3); font-size: 11px; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .baseline { stroke: var(--line-strong); stroke-width: 1; }
.chart .bar { fill: var(--series-1); }
.chart .bar.dim { opacity: .35; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hover { filter: brightness(1.15); }
.tooltip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--surface);
  padding: 6px 10px; border-radius: 6px; font-size: .8rem; white-space: nowrap; z-index: 5;
  transform: translate(-50%, calc(-100% - 8px)); box-shadow: 0 4px 14px rgba(0,0,0,.18); display: none;
}
.tooltip b { font-variant-numeric: tabular-nums; }
.hbars { display: grid; gap: 7px; }
.hbar { display: grid; grid-template-columns: minmax(80px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: .85rem; }
.hbar .lbl { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 10px; background: var(--surface-2); border-radius: 0 4px 4px 0; position: relative; }
.hbar .fill { position: absolute; inset: 0 auto 0 0; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .val { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; min-width: 64px; text-align: right; }
.hbar .val small { color: var(--ink-3); font-weight: 400; margin-left: 4px; }
.charts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-top: 16px; }
.empty { color: var(--ink-3); font-size: .88rem; padding: 18px 0; text-align: center; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-size: .82rem; cursor: pointer; }
.data-table { margin-top: 10px; max-height: 280px; overflow: auto; font-size: .85rem; }
.data-table td, .data-table th { padding: 5px 8px; }

/* --- sisselogimine -------------------------------------------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { margin-bottom: 22px; font-size: 1.1rem; }

.ms-btn { width: 100%; padding: 11px 14px; gap: 10px; font-size: .95rem; }
.ms-btn:hover { background: var(--surface-2); }

/* --- kohanduv ------------------------------------------------------- */
@media (max-width: 980px) {
  .form-layout, .code-layout { grid-template-columns: 1fr; }
  .sticky { position: static; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .top-inner { flex-wrap: wrap; gap: 8px 16px; padding: 10px 16px; }
  .nav { order: 3; flex: 0 0 100%; overflow-x: auto; }
  .who { margin-left: auto; }
  .who .name { display: none; }
  .range .seg { flex-wrap: wrap; }
  .card-head h2 { width: 100%; }
  main { padding: 20px 16px 50px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .type-picker { grid-template-columns: repeat(3, 1fr); }
  .hide-sm { display: none; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .tile .value { font-size: 1.4rem; }
}
