:root {
  --fg: #1d1d1f;
  --muted: #6e6e73;
  --line: #d9d9de;
  --bg: #ffffff;
  --panel: #f5f5f7;
  --accent: #2457d6;
  --up: #2457d6;
  --down: #c2410c;
  --ok: #1a7f37;
  --ok-bg: #dafbe1;
  --warn: #9a6700;
  --warn-bg: #fff8c5;
  --bad: #cf222e;
  --bad-bg: #ffebe9;
  --info-bg: #ddf4ff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #ececf0;
    --muted: #9a9aa2;
    --line: #3a3a40;
    --bg: #18181b;
    --panel: #232327;
    --accent: #7aa2ff;
    --up: #7aa2ff;
    --down: #fb923c;
    --ok: #3fb950;
    --ok-bg: #12261a;
    --warn: #d29922;
    --warn-bg: #2a2310;
    --bad: #f85149;
    --bad-bg: #2d1416;
    --info-bg: #122134;
  }
}

body { margin: 0; font: 16px/1.5 system-ui, sans-serif; color: var(--fg); background: var(--bg); }
[hidden] { display: none !important; }  /* classes like .btn set display, which would override it */
a { color: var(--accent); }
.muted { color: var(--muted); }

.topbar { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; align-items: center;
          padding: 12px 16px; border-bottom: 1px solid var(--line); }
.topbar .brand { color: inherit; text-decoration: none; font-weight: 600; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.topbar form { display: inline; margin: 0; }
.topbar select { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
button.link.danger { color: var(--bad); }
.inline-actions { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.inline-actions form { margin: 0; }

main { max-width: 960px; margin: 0 auto; padding: 16px; }
.messages { list-style: none; padding: 0; }
.messages li { background: var(--panel); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; }

h1 { margin: 8px 0 4px; line-height: 1.25; }
.crumbs { margin: 0 0 4px; font-size: 0.875rem; }
.crumbs a { color: var(--muted); }
.card { background: var(--panel); border-radius: 12px; padding: 16px; margin: 16px 0; }
.card h2 { margin: 0 0 8px; font-size: 1.125rem; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 8px 0; color: var(--muted); font-size: 0.9375rem; }
.description { margin: 12px 0; overflow-wrap: anywhere; }
.description img { max-width: 100%; }
.description pre { overflow-x: auto; background: var(--panel); padding: 8px; border-radius: 8px; }

.btn { display: inline-block; font: inherit; font-weight: 500; padding: 6px 14px; border-radius: 8px; cursor: pointer;
       border: 1px solid var(--accent); background: var(--accent); color: var(--bg); text-decoration: none; }
.btn.secondary { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }

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

.notice { border-radius: 8px; padding: 10px 12px; margin: 12px 0; }
.notice.warn { background: var(--warn-bg); }
.notice.bad { background: var(--bad-bg); }
.notice.info { background: var(--info-bg); }

.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
table.list th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.8125rem; }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.filters { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin: 12px 0; }
.filters select { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
.stats { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 12px 0; }
.stats strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }

.files { list-style: none; padding: 0; margin: 8px 0; }
.files li { display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.files li:last-child { border-bottom: 0; }
.files .name { overflow-wrap: anywhere; }
.files .note { flex-basis: 100%; font-size: 0.875rem; }
.files video.player { flex-basis: 100%; width: 100%; max-height: 70vh; background: #000; border-radius: 8px; }
.files .preview-box { flex-basis: 100%; display: block; line-height: 0; }
.files img.player { max-width: 100%; max-height: 60vh; border-radius: 8px; background: var(--bg); cursor: zoom-in; }

.upload input[type=file] { font: inherit; max-width: 100%; }
.progress { height: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
.copy-field { display: flex; gap: 8px; margin: 8px 0; }
.copy-field input { flex: 1; min-width: 0; font: inherit; font-size: 0.875rem; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: inherit; }
details summary { cursor: pointer; }

/* Forms */
.form { max-width: 720px; }
.field { margin: 0 0 16px; }
.field > label, .label-row label, .choices legend { display: block; font-weight: 600; margin-bottom: 4px; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea {
  box-sizing: border-box; width: 100%; font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.field textarea { font-family: ui-monospace, monospace; font-size: 0.875rem; resize: vertical; }
.field .preview { border: 1px solid var(--line); border-radius: 6px; padding: 0 12px; margin: 0; box-sizing: border-box; }
.field .help { font-size: 0.875rem; margin-top: 4px; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--bad); }
.field.checkbox > label { font-weight: 400; display: flex; gap: 6px; align-items: baseline; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.errorlist { list-style: none; padding: 0; margin: 4px 0; color: var(--bad); font-size: 0.875rem; }
.choices { border: 0; padding: 0; margin: 16px 0; }
.choices label { display: block; margin: 4px 0; }
.choices .choice { display: inline-block; margin: 4px 16px 4px 0; }
/* Cleanup: show only the picker of the chosen scope (all of them without :has() support) */
.scope-form:has([name=scope][value=task]:checked) [data-scope]:not([data-scope=task]),
.scope-form:has([name=scope][value=course]:checked) [data-scope]:not([data-scope=course]),
.scope-form:has([name=scope][value=academic_year]:checked) [data-scope]:not([data-scope=academic_year]),
.scope-form:has([name=scope][value=student_group]:checked) [data-scope]:not([data-scope=student_group]) { display: none; }
td.actions { white-space: nowrap; text-align: right; }
th.share, td.share { width: 25%; min-width: 80px; }
.small { font-size: 0.8125rem; }
td.check { width: 1.5em; }
.members { list-style: none; padding: 0; margin: 8px 0; }
.members li { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line); }
.members li:last-child { border-bottom: 0; }
.members form { margin: 0 0 0 auto; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.inline-form select { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
                      padding: 4px 6px; max-width: 100%; }
.filters input.year { width: 6em; font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
input.groups { box-sizing: border-box; width: 100%; min-width: 10em; font: inherit; color: inherit; background: var(--bg);
               border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
.form.wide { max-width: none; }
.bar { height: 8px; background: var(--panel); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.bar > div { height: 100%; background: var(--accent); min-width: 1px; }
td.actions form { display: inline; margin-right: 8px; }
form.inline-delete { display: inline; margin: 0; }
button.icon { font: inherit; line-height: 1; padding: 2px 6px; border: 1px solid var(--line); border-radius: 6px;
              background: transparent; color: inherit; cursor: pointer; }
button.icon:disabled { opacity: 0.3; cursor: default; }

/* Status page */
.meters { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin: 16px 0; }
.meter { background: var(--panel); border-radius: 12px; padding: 16px; }
.meter h2 { margin: 0 0 4px; font-size: 1rem; font-weight: 600; }
.meter .value { font-size: 2.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.meter .value small { font-size: 1rem; font-weight: 400; color: var(--muted); }
.meter.up .value { color: var(--up); }
.meter.down .value { color: var(--down); }
.chart { width: 100%; height: 220px; background: var(--panel); border-radius: 12px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 12px; }
.chart .line { fill: none; stroke-width: 2; }
.chart .line.up { stroke: var(--up); }
.chart .line.down { stroke: var(--down); }
.legend { display: flex; gap: 16px; font-size: 0.875rem; color: var(--muted); }
.legend .up::before, .legend .down::before { content: ""; display: inline-block; width: 12px; height: 3px; margin: 0 6px 3px 0; }
.legend .up::before { background: var(--up); }
.legend .down::before { background: var(--down); }
