/* Робочий інструмент: світлий папір, синій чорнильний акцент, таблиця — головний елемент. */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --fg: #16202c;
  --muted: #5a6676;
  --line: #d9e0e9;
  --accent: #1d56b3;
  --accent-fg: #ffffff;
  --accent-soft: #e3ecfa;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #1d7a46;
  --ok-soft: #e3f4ea;
  --f-campus: #1d56b3;
  --f-campus-soft: #e3ecfa;
  --f-school: #8a4b00;
  --f-school-soft: #fbefdc;
  --f-online: #5b3fb0;
  --f-online-soft: #ece7fb;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #161d27;
    --surface-2: #1d2633;
    --fg: #e6ebf2;
    --muted: #97a3b4;
    --line: #2a3443;
    --accent: #6ea2f5;
    --accent-fg: #0b1220;
    --accent-soft: #1b2d4d;
    --danger: #f2877d;
    --danger-soft: #3a1d1b;
    --ok: #6fd39b;
    --ok-soft: #173325;
    --f-campus: #8db7f7;
    --f-campus-soft: #1b2d4d;
    --f-school: #f0b66a;
    --f-school-soft: #3a2a14;
    --f-online: #b9a5f5;
    --f-online-soft: #2a2247;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font);
}
a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }
h1, h2 { line-height: 1.25; text-wrap: balance; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 650; }
h2 { font-size: 1.15rem; font-weight: 650; }
small { display: block; color: var(--muted); font-size: 0.85em; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.js-hidden { display: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Шапка */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner, .page {
  max-width: 1180px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-block: 10px; }
.brand { color: var(--fg); text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand span { color: var(--muted); font-weight: 400; margin-left: 4px; }
.nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.who { color: var(--muted); max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inline { display: inline; margin: 0; }

.page { padding-block: 24px 48px; display: grid; gap: 20px; }
.page > * { min-width: 0; }
.page-head { display: grid; gap: 6px; }
.back { margin: 0; }
.back a { text-decoration: none; }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 8px 14px; min-height: 38px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--fg);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

/* Фільтри */
.filters { display: flex; flex-wrap: wrap; align-items: end; gap: 12px 16px; margin: 0; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); padding: 2px; margin: 0; background: var(--surface); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span { display: block; padding: 6px 12px; border-radius: 6px; color: var(--muted); font-weight: 600; }
.segmented input:checked + span { background: var(--accent-soft); color: var(--accent); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
.field-inline { display: grid; gap: 2px; font-size: 0.85rem; color: var(--muted); }
.field-inline select { min-width: 9rem; }
.reset { align-self: center; }

select, input[type="text"], input[type="email"], input[type="date"], input[type="time"], input[type="number"], textarea {
  font: inherit; color: var(--fg); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; width: 100%;
}
textarea { resize: vertical; }
[aria-invalid="true"] { border-color: var(--danger); }

/* Підсумки */
.summary {
  display: grid; grid-template-columns: auto auto minmax(0, 2fr) minmax(0, 1fr);
  gap: 16px 32px; align-items: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px;
}
.stat { display: grid; }
.stat-value { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-label { color: var(--muted); }
.label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.bars, .format-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.bars li { display: grid; grid-template-columns: 3.5rem minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.bar-name { font-weight: 600; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 4px; min-width: 2px; }
.bar-value { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.9rem; }
.label-gap { margin-top: 14px; }
.format-list li { display: flex; justify-content: space-between; gap: 12px; align-items: center; }

/* Таблиці */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.date { white-space: nowrap; }
td.title a { font-weight: 600; text-decoration: none; }
td.title a:hover { text-decoration: underline; }
td.people { max-width: 22rem; }
table.events { min-width: 820px; }
table.users { min-width: 640px; }
tr.inactive td { color: var(--muted); }
.actions-cell { text-align: right; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.85rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge-on_campus { background: var(--f-campus-soft); color: var(--f-campus); }
.badge-school_visit { background: var(--f-school-soft); color: var(--f-school); }
.badge-online { background: var(--f-online-soft); color: var(--f-online); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }

.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 32px 20px; text-align: center; display: grid; gap: 12px; justify-items: center; }
.empty p { margin: 0; color: var(--muted); }
.notice { margin: 0; padding: 10px 14px; background: var(--accent-soft); border-radius: var(--radius); }

/* Панелі та форми */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; display: grid; gap: 18px; }
.panel.narrow { max-width: 560px; }
.event-form { max-width: 860px; }
.field { display: grid; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > span, .field > legend { font-weight: 600; padding: 0; }
.field em, .check em { font-style: normal; font-weight: 400; color: var(--muted); font-size: 0.85rem; margin-left: 6px; }
.field.nested { margin-top: 8px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 16px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.check { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.check input { margin-top: 4px; accent-color: var(--accent); }
.people-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 8px 20px; }
.people-checks small { display: inline; }
.hint { margin: 0; color: var(--muted); font-size: 0.9rem; }
.error { margin: 0; color: var(--danger); font-size: 0.9rem; }
.error-summary { margin: 0; padding: 10px 14px; background: var(--danger-soft); color: var(--danger); border-radius: var(--radius); font-weight: 600; }
.actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.danger-zone { margin: 0; }

/* Картка івенту */
.detail { max-width: 860px; }
.detail-head { display: flex; justify-content: space-between; align-items: start; gap: 16px; flex-wrap: wrap; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-weight: 600; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 16px 24px; margin: 0; }
.facts .wide { grid-column: 1 / -1; }
.facts dt { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.facts dd { margin: 0; }
.facts dd.num { text-align: left; font-size: 1.25rem; font-weight: 700; }
.notes { white-space: pre-wrap; }
.people-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.meta { color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--line); padding-top: 12px; }

@media (max-width: 860px) {
  .summary { grid-template-columns: 1fr 1fr; }
  .breakdown { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  h1 { font-size: 1.35rem; }
  .filters { display: grid; grid-template-columns: 1fr 1fr; }
  .segmented { grid-column: 1 / -1; justify-self: start; }
  .field-inline select { min-width: 0; }
  .panel { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
