:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5f6b7a;
  --border: #dde3ea;
  --accent: #0a66cc;
  --accent-text: #ffffff;
  --ok: #137a42;
  --ok-bg: #e3f5ea;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --bad: #b3261e;
  --bad-bg: #fde7e5;
  --info: #0b5aa6;
  --info-bg: #e3effc;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #18202a;
    --text: #e6ebf1;
    --muted: #9aa6b4;
    --border: #2a3542;
    --accent: #4c9bff;
    --accent-text: #08111c;
    --ok: #6fd69a;
    --ok-bg: #133022;
    --warn: #f0c060;
    --warn-bg: #3a2c0c;
    --bad: #ff8a80;
    --bad-bg: #3d1a17;
    --info: #8cc2ff;
    --info-bg: #13283f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

/* Layout: 16px gutter on phones; from 1280px the container grows with the viewport. */
.container { width: 100%; margin: 0 auto; padding: 0 16px; }
@media (min-width: 1280px) {
  .container { max-width: min(100%, 1680px); padding: 0 clamp(1.5rem, 2.5vw, 3rem); }
}
@media (min-width: 1920px) {
  .container { max-width: 1840px; }
}
.container.narrow { max-width: 640px; }
main.container { padding-top: 24px; padding-bottom: 32px; min-height: calc(100vh - 140px); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.5rem; }
code, .mono { font-family: Consolas, "Cascadia Mono", ui-monospace, monospace; }
pre { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--info-bg); color: var(--info); }
.account { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.account form { margin: 0; }
.menu-toggle { display: none; }

@media (max-width: 900px) {
  .menu-toggle { display: block; margin-left: auto; background: none; color: var(--text); border: 1px solid var(--border); padding: 4px 10px; }
  .nav { display: none; flex-basis: 100%; flex-direction: column; padding-bottom: 8px; }
  .nav.open { display: flex; }
  .account { margin-left: 0; flex-basis: 100%; padding-bottom: 8px; }
}

.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card.highlight { border-color: var(--accent); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.auth { margin-top: 8vh; }
.grid-2 { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 1100px) { .grid-2 { grid-template-columns: 3fr 2fr; } }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 20px; }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.tile-value { font-size: 1.8rem; font-weight: 700; line-height: 1.2; }
.tile-label { color: var(--muted); font-size: 0.9rem; }
.tile.warn .tile-value { color: var(--warn); }
.tile.bad .tile-value { color: var(--bad); }

.chart { width: 100%; height: auto; }
.chart .bar { fill: var(--accent); }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .value { fill: var(--text); font-size: 11px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; white-space: nowrap; }
tbody tr:hover { background: var(--bg); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.wrap { max-width: 420px; overflow-wrap: anywhere; }
.rules input, .rules select { min-width: 70px; }
.rules td:first-child input { min-width: 200px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--bad-bg); color: var(--bad); }
.flash-warn { background: var(--warn-bg); color: var(--warn); }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 0.92rem; }
label.check { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; margin: 6px 0; }
label.check input { margin-top: 4px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 38px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[disabled], select[disabled] { opacity: 0.7; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row label { flex: 1 1 200px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); align-items: end; }
.filters { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); align-items: end; }
.filter-actions { display: flex; gap: 12px; align-items: center; }
form.inline { display: inline; margin: 0; }
.actions { white-space: nowrap; }

button, .button {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: 8px 16px; min-height: 38px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text); display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .button:hover { filter: brightness(1.08); text-decoration: none; }
button.secondary, .button.secondary { background: var(--surface); color: var(--accent); }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.small { padding: 3px 10px; min-height: 28px; font-size: 0.85rem; }
button.link { background: none; border: none; color: var(--accent); padding: 0; min-height: 0; font-weight: 500; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.big { font-size: 1.15rem; }
.center { text-align: center; }
.qr { display: flex; justify-content: center; margin: 12px 0; }
.qr svg { background: #fff; padding: 8px; border-radius: 8px; max-width: 240px; height: auto; }
.copyable { cursor: copy; position: relative; }
.copyable.copied::after { content: "Copied"; position: absolute; right: 8px; top: 8px; font-size: 0.8rem; color: var(--ok); }
.alerts { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.footer { color: var(--muted); font-size: 0.85rem; padding-top: 12px; padding-bottom: 24px; }
