:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --border: #dde1e8;
  --text: #1a1f2b;
  --muted: #5f6878;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --bad: #c62828;
  --bad-bg: #fde2e2;
  --warn: #a15c00;
  --warn-bg: #fff1d6;
  --bar: #3b82f6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1e2430;
    --border: #2b3240;
    --text: #e6e9ef;
    --muted: #97a0b0;
    --accent: #4f8cff;
    --accent-text: #ffffff;
    --ok: #4ade80;
    --ok-bg: #14301f;
    --bad: #f87171;
    --bad-bg: #3a1a1c;
    --warn: #fbbf24;
    --warn-bg: #36290f;
    --bar: #4f8cff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

button, input, select {
  font: inherit;
  color: inherit;
}

/* ---------------------------------------------------------------- layout */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  font-size: 16px;
  white-space: nowrap;
}

.brand img { width: 22px; height: 22px; }

nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }

nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

nav a:hover { background: var(--surface-2); color: var(--text); }
nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

.topbar .right { display: flex; align-items: center; gap: 12px; white-space: nowrap; }

main { max-width: 1240px; margin: 0 auto; padding: 24px 20px 48px; }

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 12px; }

.grid { display: grid; gap: 16px; }
.grid.kpi { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); margin-bottom: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}

.kpi .value { font-size: 28px; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value.bad { color: var(--bad); }
.kpi .value.ok { color: var(--ok); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }

table { width: 100%; border-collapse: collapse; }

th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }

th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }

tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
tbody tr.fresh { animation: fresh 2.5s ease-out; }

@keyframes fresh { from { background: var(--warn-bg); } to { background: transparent; } }

td.actions { white-space: nowrap; text-align: right; }

th.c-select, td.c-select { width: 32px; padding-right: 0; cursor: default; }
.c-select input { width: 16px; height: 16px; margin: 0; cursor: pointer; vertical-align: middle; }
tbody tr.selected { background: var(--surface-2); }
.toolbar.selection { margin-top: -4px; }
.head-actions { display: flex; gap: 8px; }
td.actions > * + * { margin-left: 6px; }

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

/* ---------------------------------------------------------------- controls */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 9px; font-size: 13px; }

input[type=text], input[type=password], input[type=search], select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  min-width: 0;
}

select.small { padding: 3px 6px; font-size: 13px; }

input:focus-visible, select:focus-visible, .btn:focus-visible, nav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1 1 220px; }

label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--muted); }

form.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
form.inline input[type=text] { flex: 1 1 200px; }

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

.nowrap { white-space: nowrap; }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }

.code { font-family: ui-monospace, Consolas, monospace; font-weight: 600; letter-spacing: .04em; }

/* ---------------------------------------------------------------- charts */

.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.bars div { flex: 1; background: var(--bar); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.bars div.zero { background: var(--border); }
.bars-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 6px; }

.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 6px 0 2px; }
.meter > div { height: 100%; background: var(--bar); }
.meter > div.warn { background: var(--warn); }
.meter > div.bad { background: var(--bad); }

.rows > div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.rows > div:last-child { border-bottom: none; }

/* ---------------------------------------------------------------- login */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { display: flex; align-items: center; gap: 10px; }
.login h1 img { width: 28px; height: 28px; }
.login input { width: 100%; margin: 8px 0 16px; padding: 10px 12px; }
.login .btn { width: 100%; justify-content: center; padding: 10px; }
.login .error { color: var(--bad); margin: 0 0 12px; }

/* ---------------------------------------------------------------- dialog & toasts */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}

dialog::backdrop { background: rgba(10, 14, 22, .55); }

.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; }
.dialog-body { padding: 18px; overflow-y: auto; }
.dialog-body section + section { margin-top: 20px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--ok);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  white-space: pre-line;
  max-width: 420px;
}

.toast.error { border-left-color: var(--bad); }

/* ---------------------------------------------------------------- mobile */

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 8px; }
  nav { order: 3; flex-basis: 100%; }
  .topbar .right { margin-left: auto; }
  main { padding: 16px 16px 40px; }
  .grid.two { grid-template-columns: 1fr; }
  .hide-mobile { display: none; }
  td.actions { text-align: left; }

  /* Tabulka blokací jako karty – akce musí být vidět bez posouvání do strany. */
  table.stack thead { display: none; }
  table.stack tr {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "select nick code" "select reason time" "select ip country" ". actions actions";
    gap: 4px 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }
  table.stack td { border: none; padding: 0; }
  table.stack td.hide-mobile { display: none; }
  table.stack .c-select { grid-area: select; width: auto; padding-top: 2px; }
  table.stack .c-nick { grid-area: nick; }
  table.stack .c-code { grid-area: code; text-align: right; }
  table.stack .c-reason { grid-area: reason; }
  table.stack .c-time { grid-area: time; text-align: right; color: var(--muted); }
  table.stack .c-ip { grid-area: ip; }
  table.stack .c-country { grid-area: country; text-align: right; }
  table.stack .c-actions { grid-area: actions; margin-top: 6px; white-space: normal; }
  table.stack .c-actions:empty { display: none; }
}
