/* HAART API panel. One stylesheet, no external fonts or CDNs: the panel's
   CSP allows nothing but this origin. Light and dark follow the system. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16181d;
  --muted: #646b78;
  --line: #e1e4ea;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --good: #1a7f37;
  --good-bg: #e6f4ea;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --bad: #cf222e;
  --bad-bg: #ffebe9;
  --bar: #1f6feb;
  --bar-zero: #c9d1dd;
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --text: #e6e8ec;
    --muted: #9099a8;
    --line: #2a2f39;
    --accent: #4c8dff;
    --accent-ink: #0b0d10;
    --good: #57c27a;
    --good-bg: #16301f;
    --warn: #e0b341;
    --warn-bg: #33290f;
    --bad: #ff7b72;
    --bad-bg: #3a1a1a;
    --bar: #4c8dff;
    --bar-zero: #333a46;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0 0 1rem; line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }

.muted { color: var(--muted); font-weight: normal; }
.small { font-size: .85em; }
.mono { font-family: var(--mono); font-size: .92em; }
.warn { color: var(--warn); }
.empty { color: var(--muted); margin: .25rem 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* top bar */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.5rem;
  padding: .6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); letter-spacing: .02em; }
.brand span, .login h1 span { color: var(--muted); font-weight: 500; }
.top nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.top nav a {
  color: var(--muted); padding: .35rem .7rem; border-radius: 8px;
}
.top nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.top nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.logout { margin: 0; }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
main.narrow { max-width: 420px; padding-top: 12vh; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.cols > .card { margin-bottom: 0; }
.cols + .card { margin-top: 1.25rem; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem 1rem; display: flex; flex-direction: column; gap: .15rem;
}
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .value { font-size: 2rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: .8rem; }
.kpi .value.small-value { font-size: 1.45rem; padding: .2rem 0; }
.kpi.accent .value { color: var(--good); }

/* chart */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--bar); }
.chart .bar.zero { fill: var(--bar-zero); }
.chart .bar:hover { opacity: .8; }

/* tables */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tr.current { background: var(--surface-2); }
tr.withdrawn td { color: var(--muted); }
tr.notes td { color: var(--muted); font-size: .88em; border-bottom: 1px solid var(--line); padding-top: 0; white-space: pre-wrap; }
td.num, th.num { text-align: right; }
td.msg { max-width: 520px; word-break: break-word; }
td.actions { white-space: nowrap; }
td.actions > * + * { margin-left: .6rem; }

/* badges and states */
.badge {
  display: inline-block; font-size: .75rem; font-weight: 600; padding: .05rem .45rem;
  border-radius: 999px; vertical-align: .1em; white-space: nowrap;
}
.badge.crash { background: var(--bad-bg); color: var(--bad); }
.badge.error { background: var(--warn-bg); color: var(--warn); }
.badge.mandatory { background: var(--warn-bg); color: var(--warn); }
.state { font-size: .88em; white-space: nowrap; }
.state::before { content: "●"; margin-right: .35em; font-size: .8em; }
.state.accelerating { color: var(--good); }
.state.reconnecting { color: var(--warn); }
.state.idle { color: var(--muted); }
.state.offline { color: var(--muted); opacity: .7; }

.reports { list-style: none; margin: 0; padding: 0; }
.reports li { padding: .5rem 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: .25rem .5rem; align-items: baseline; }
.reports li:last-child { border-bottom: 0; }
.reports li a { word-break: break-word; }
.reports li .muted { flex-basis: 100%; }
.more { float: right; font-size: .85rem; font-weight: normal; }

.status dl, .meta { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.25rem; margin: 0; }
.status dt, .meta dt { color: var(--muted); }
.status dd, .meta dd { margin: 0; word-break: break-word; }
.meta { margin-bottom: 1.5rem; }
.nowrap { white-space: nowrap; }

.flash {
  background: var(--good-bg); color: var(--good); border-radius: var(--radius);
  padding: .7rem 1rem; margin: 0 0 1.25rem; font-weight: 500;
}
.flash.bad { background: var(--bad-bg); color: var(--bad); white-space: pre-wrap; }
p.warn { background: var(--warn-bg); padding: .6rem .9rem; border-radius: 8px; }

pre.log {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  padding: .75rem .9rem; overflow: auto; max-height: 32rem;
  font: 12.5px/1.45 var(--mono); white-space: pre; margin: 0 0 1rem;
}

/* forms */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: .4rem; }
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=file]), select, textarea {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; resize: vertical; }
.editor textarea { font: 13px/1.5 var(--mono); tab-size: 2; min-height: 22rem; }

button {
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  border-radius: 8px; padding: .45rem 1rem; cursor: pointer; font-weight: 600;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); font-weight: 500; }
button.ghost:hover { background: var(--surface-2); filter: none; }
button.small { padding: .15rem .55rem; font-size: .85rem; }
form.inline { display: inline; margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: .75rem; }
.editor-bar { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; margin-bottom: .6rem; font-size: .88rem; }
.editor-bar button { margin-left: auto; }
.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-top: .75rem; }
.row .grow { flex: 1; min-width: 14rem; }

.upload { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; }
.upload .wide, .upload .row { grid-column: 1 / -1; }

.login { padding: 1.75rem; }
.login h1 { font-size: 1.4rem; margin-bottom: .25rem; }
.login form { display: flex; flex-direction: column; gap: .75rem; margin-top: 1.25rem; }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols { grid-template-columns: 1fr; }
  .cols > .card { margin-bottom: 0; }
  .upload { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; gap: .5rem 1rem; padding: .6rem 1rem; }
  main { padding: 1rem 1rem 2rem; }
}

/* Пользователи */
input.short { width: 5.5rem; }
button.danger { color: var(--bad); }
details.hint { margin: .5rem 0 1rem; }
details.hint summary { cursor: pointer; color: var(--muted); }
details.hint .mono { word-break: break-all; }
