:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1d2623;
  --muted: #66716d;
  --line: #e3dfd6;
  --accent: #0f5c57;
  --accent-ink: #ffffff;
  --accent-soft: #e2efec;
  --ok: #1f7a4a;
  --ok-soft: #e3f3e9;
  --warn: #9a6200;
  --warn-soft: #fbf0d9;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --radius: 12px;
  --nav-w: 232px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: .4rem 0; }
code, .mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

/* ---------- каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .75rem;
  height: 56px; padding: 0 1rem; background: var(--accent); color: var(--accent-ink);
}
.topbar .brand { color: inherit; text-decoration: none; font-weight: 650; letter-spacing: .01em; }
.burger { display: none; font-size: 1.4rem; cursor: pointer; padding: .25rem .5rem; margin-left: -.5rem; user-select: none; }
.bot-dot { margin-left: auto; width: 10px; height: 10px; border-radius: 50%; background: #9aa; box-shadow: 0 0 0 3px rgba(255,255,255,.15); }
.bot-dot.running { background: #4ade80; }
.bot-dot.error { background: #f87171; }

.sidebar {
  position: fixed; top: 56px; bottom: 0; left: 0; width: var(--nav-w); overflow-y: auto;
  background: var(--card); border-right: 1px solid var(--line); padding: .75rem .5rem 2rem; z-index: 25;
}
.sidebar a, .sidebar button.navlink {
  display: block; width: 100%; text-align: left; padding: .6rem .8rem; border-radius: 8px; color: var(--ink);
  text-decoration: none; font: inherit; background: none; border: 0; cursor: pointer;
}
.sidebar a:hover, .sidebar button.navlink:hover { background: var(--bg); }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar .sep { height: 1px; background: var(--line); margin: .5rem .6rem; }
.scrim { display: none; }

main { padding: 1.5rem; max-width: 1200px; }
main.with-nav { margin-left: var(--nav-w); }
main.bare { margin: 0 auto; max-width: 420px; padding-top: 12vh; }

@media (max-width: 860px) {
  .burger { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 30px rgba(0,0,0,.15); width: 80%; max-width: 300px; }
  #nav-toggle:checked ~ .sidebar { transform: none; }
  #nav-toggle:checked ~ .scrim { display: block; position: fixed; inset: 56px 0 0 0; background: rgba(0,0,0,.3); z-index: 20; }
  main.with-nav { margin-left: 0; }
  main { padding: 1rem .75rem 3rem; }
  h1 { font-size: 1.3rem; }
}

/* ---------- карточки и сетки ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card > h2:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
@media (max-width: 420px) { .grid.two { grid-template-columns: 1fr; } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.stat .v { font-size: 1.5rem; font-weight: 650; letter-spacing: -0.02em; }
.stat .l { color: var(--muted); font-size: .85rem; }
.head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.head h1 { margin: 0; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row.end { justify-content: flex-end; }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1.2rem; padding: 0 1.2rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td form { display: inline; }

/* Таблица → карточки на телефоне */
@media (max-width: 640px) {
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { border: 1px solid var(--line); border-radius: 10px; padding: .4rem .7rem; margin-bottom: .6rem; background: var(--card); }
  table.cards td { border: 0; padding: .25rem 0; }
  table.cards td[data-l]::before { content: attr(data-l) ": "; color: var(--muted); font-size: .8rem; }
  .table-wrap { margin: 0; padding: 0; }
}

/* ---------- формы ---------- */
label { display: block; font-weight: 600; font-size: .9rem; margin: .8rem 0 .3rem; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; margin: .6rem 0; cursor: pointer; }
.hint { color: var(--muted); font-size: .82rem; margin-top: .25rem; font-weight: 400; }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=email], input[type=search], select, textarea {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink);
  font: 16px/1.4 var(--font); /* 16px — чтобы iOS не зумил */
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 120px; resize: vertical; }
textarea.code { font-family: var(--mono); font-size: 13px; min-height: 480px; white-space: pre; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
input[type=file] { font-size: 15px; max-width: 100%; }
.inline-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 1rem; }
fieldset { border: 0; padding: 0; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-height: 40px;
  padding: .5rem 1rem; border-radius: 9px; border: 1px solid var(--accent); background: var(--accent);
  color: var(--accent-ink); font: 600 15px/1.2 var(--font); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.light { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn.danger { background: var(--bad); border-color: var(--bad); }
.btn.danger.ghost { background: transparent; color: var(--bad); }
.btn.sm { min-height: 32px; padding: .3rem .65rem; font-size: .85rem; border-radius: 7px; }
.btn.block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.2rem; }
@media (max-width: 640px) { .form-actions .btn { flex: 1 1 100%; } }

/* ---------- сообщения и бейджи ---------- */
.flash { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; word-break: break-word; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.err { background: var(--bad-soft); color: var(--bad); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.flash ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.chip { padding: .35rem .8rem; border: 1px solid var(--line); border-radius: 99px; background: var(--card); text-decoration: none; color: var(--ink); font-size: .9rem; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.pager { display: flex; gap: .4rem; align-items: center; justify-content: center; margin-top: 1rem; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; }
details[open] summary { margin-bottom: .5rem; }
pre.details { margin: 0; font-size: .8rem; white-space: pre-wrap; word-break: break-word; max-width: 420px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
@media (max-width: 480px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: .4rem; } }
.login-card h1 { text-align: center; }
.status-line { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: #aaa; }
.dot.running { background: var(--ok); }
.dot.error { background: var(--bad); }
.dot.starting { background: var(--warn); }

/* ---------- статистика ---------- */
h2.section { margin: 1.6rem 0 .75rem; font-size: 1.15rem; }
.grid.charts { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 1.25rem 1.5rem; }

/* ранжированные полосы: подпись · полоса · число (на узком экране полоса уходит под подпись) */
.bar-list { display: flex; flex-direction: column; gap: .15rem; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 32%) 1fr auto; grid-template-areas: "lbl trk val";
  gap: .2rem .75rem; align-items: center; padding: .25rem 0; }
.bar-row .lbl { grid-area: lbl; font-size: .9rem; overflow-wrap: anywhere; }
.bar-row .trk { grid-area: trk; height: 8px; background: var(--accent-soft); border-radius: 99px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--accent); border-radius: 99px; }
.bar-row .val { grid-area: val; text-align: right; white-space: nowrap; font-size: .9rem; font-variant-numeric: tabular-nums; }
@media (max-width: 520px) {
  .bar-row { grid-template-columns: 1fr auto; grid-template-areas: "lbl val" "trk trk"; }
}

/* столбики по дням: одна серия, тонкие столбики, скругление сверху, подсказка по наведению/фокусу */
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; font-size: .9rem; }
.chart-head .total { font-weight: 650; }
.cols { position: relative; display: flex; align-items: flex-end; gap: 2px; height: 120px; margin-top: .4rem;
  padding-top: 16px; border-bottom: 1px solid var(--line); }
.cols .ymax { position: absolute; top: 0; left: 0; font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.cols .empty { position: absolute; inset: 16px 0 0 0; display: flex; align-items: center; justify-content: center; }
.cols .gridline { position: absolute; top: 16px; left: 0; right: 0; border-top: 1px solid var(--line); }
.col { position: relative; flex: 1 1 0; max-width: 24px; height: 100%; display: flex; align-items: flex-end; outline: none; }
.col .bar { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; }
.col .bar.nz { min-height: 2px; }
.col:hover .bar, .col:focus-visible .bar { background: #2f8a83; }
.col:focus-visible { box-shadow: 0 0 0 2px var(--accent-soft); border-radius: 4px; }
.col .tip { display: none; position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: .75rem; padding: .25rem .5rem; border-radius: 6px;
  white-space: nowrap; z-index: 5; pointer-events: none; }
.col.l .tip { left: 0; transform: none; }
.col.r .tip { left: auto; right: 0; transform: none; }
.col:hover .tip, .col:focus .tip { display: block; }
.xlabels { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); margin-top: .2rem; font-variant-numeric: tabular-nums; }
.table-view { margin-top: .4rem; }
.table-view summary { font-weight: 500; font-size: .8rem; }
.table-view table { max-width: 260px; }
.table-view td { padding: .2rem .4rem; }

/* карточка пользователя */
h1.with-avatar { display: flex; align-items: center; gap: .75rem; }
.avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: var(--accent-soft); flex: none; }
.timeline { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; }
.timeline li { padding: .35rem 0; border-bottom: 1px solid var(--line); display: flex; gap: .75rem; flex-wrap: wrap; align-items: baseline; }
.timeline li:last-child { border-bottom: 0; }

/* публичная страница документа */
main.doc { max-width: 760px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
main.doc h1 { font-size: 1.6rem; line-height: 1.25; }
main.doc h2 { font-size: 1.1rem; margin: 1.6rem 0 .5rem; }
main.doc p { margin: .6rem 0; line-height: 1.6; }
.doc-foot { margin-top: 2.5rem !important; border-top: 1px solid var(--line); padding-top: 1rem; }
