:root {
  --bg: #f5f6fa; --surface: #ffffff; --surface-2: #f0f2f7; --surface-3: #e7eaf2;
  --text: #0f172a; --muted: #5b6478; --faint: #8a93a6; --border: #e1e5ee;
  --accent: #1d4ed8; --accent-soft: #e0e8ff; --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7;
  --bad: #b91c1c; --bad-soft: #fee2e2; --radius: 14px; --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 6px 20px rgba(15, 23, 42, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020; --surface: #121a2e; --surface-2: #18213a; --surface-3: #212c49;
    --text: #e6eaf5; --muted: #a3adc4; --faint: #76809a; --border: #26324f;
    --accent: #8aa8ff; --accent-soft: #1f2c55; --ok: #4ade80; --ok-soft: #12321f; --warn: #fbbf24; --warn-soft: #3a2c0b;
    --bad: #f87171; --bad-soft: #3b1515; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020; --surface: #121a2e; --surface-2: #18213a; --surface-3: #212c49;
  --text: #e6eaf5; --muted: #a3adc4; --faint: #76809a; --border: #26324f;
  --accent: #8aa8ff; --accent-soft: #1f2c55; --ok: #4ade80; --ok-soft: #12321f; --warn: #fbbf24; --warn-soft: #3a2c0b;
  --bad: #f87171; --bad-soft: #3b1515; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.25);
  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 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.9rem; letter-spacing: -.02em; }
h2 { font-size: 1.25rem; letter-spacing: -.01em; }
h3 { font-size: 1rem; }
code, pre { font-family: var(--mono); font-size: .85em; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: .85rem; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.stack > * + * { margin-top: 1rem; }
.row-flex { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .wrap { display: flex; align-items: center; gap: 14px; min-height: 60px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #1d4ed8, #9333ea); font-size: .8rem; letter-spacing: .04em; }
.levelnav { display: flex; gap: 4px; flex-wrap: wrap; }
.levelnav a { --c: var(--accent); font-size: .78rem; font-weight: 700; letter-spacing: .03em; padding: 4px 8px;
  border-radius: 999px; color: var(--c); background: color-mix(in srgb, var(--c) 12%, transparent); }
.levelnav a:hover, .levelnav a.on { background: var(--c); color: #fff; text-decoration: none; }
.levelnav .sep { width: 1px; background: var(--border); margin: 2px 4px; }
.searchbox { display: flex; flex: 1; min-width: 180px; max-width: 340px; margin-left: auto; }
.searchbox input { width: 100%; }
.iconbtn { background: none; border: 1px solid var(--border); color: var(--muted); border-radius: 9px; height: 36px;
  min-width: 36px; cursor: pointer; font-size: .95rem; }
.iconbtn:hover { color: var(--text); background: var(--surface-2); }

/* forms */
input[type=text], input[type=search], input[type=url], input[type=password], input[type=number], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 10px; min-height: 36px; max-width: 100%;
}
textarea { width: 100%; min-height: 110px; font-family: var(--mono); font-size: .85rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
label { font-size: .9rem; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: .8rem; }
.field > span { font-weight: 600; font-size: .85rem; }
.field small { color: var(--muted); }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: inline-flex; gap: 6px; align-items: center; }
.btn { font: inherit; font-weight: 600; font-size: .88rem; display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: var(--radius-sm);
  padding: 7px 12px; cursor: pointer; white-space: nowrap; min-height: 36px; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
:root[data-theme="dark"] .btn.primary { color: #0b1020; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #0b1020; } }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 3px 9px; font-size: .8rem; min-height: 28px; }
.btn.ghost { border-color: transparent; background: none; }
form.inline { display: inline; margin: 0; }

/* cards & panels */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2, .panel-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.grid.cols-5 { grid-template-columns: repeat(auto-fill, minmax(205px, 1fr)); }

.hero { padding: 34px 0 18px; }
.hero p { color: var(--muted); max-width: 720px; margin: .3rem 0 0; font-size: 1.02rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 20px 0 8px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .v { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .k { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 30px 0 12px; }
.section-title h2 { margin: 0; }

.lcard { --c: #64748b; position: relative; display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 18px 16px; color: var(--text); box-shadow: var(--shadow); overflow: hidden;
  transition: transform .12s ease, border-color .12s ease; }
.lcard::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--c); }
.lcard:hover { text-decoration: none; transform: translateY(-2px); border-color: color-mix(in srgb, var(--c) 45%, var(--border)); }
.lcard .code { font-size: 1.9rem; font-weight: 800; color: var(--c); letter-spacing: -.02em; line-height: 1; }
.lcard .name { font-weight: 650; margin-top: 6px; }
.lcard .cefr { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 7px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); margin-left: 6px; vertical-align: 2px; }
.lcard .counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 14px; }
.lcard .counts div { text-align: center; background: var(--surface-2); border-radius: 8px; padding: 6px 2px; }
.lcard .counts b { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.lcard .counts span { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.lcard .bar { display: flex; height: 6px; border-radius: 99px; overflow: hidden; margin-top: 12px; background: var(--surface-3); }
.lcard .bar i { display: block; height: 100%; }
.lcard .secs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }

/* chips & badges */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: .72rem; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; letter-spacing: .02em; }
.chip.lv { --c: #64748b; background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.acc { background: var(--accent-soft); color: var(--accent); }
.ext { min-width: 52px; justify-content: center; font-size: .7rem; border-radius: 7px; padding: 4px 6px; }
.ext-pdf { background: #fee2e2; color: #b91c1c; } .ext-zip, .ext-rar, .ext-7z { background: #fef3c7; color: #92400e; }
.ext-mp3, .ext-m4a, .ext-wav, .ext-ogg { background: #dcfce7; color: #166534; }
.ext-doc, .ext-docx, .ext-odt, .ext-rtf { background: #dbeafe; color: #1e40af; }
.ext-ppt, .ext-pptx { background: #ffedd5; color: #9a3412; }
.ext-online { background: #ede9fe; color: #6d28d9; } .ext-video { background: #fce7f3; color: #be185d; }
.ext-page { background: var(--surface-3); color: var(--muted); }
:root[data-theme="dark"] .ext:not(.ext-page) { filter: saturate(.9) brightness(.9); }

/* item rows */
.rows { display: flex; flex-direction: column; }
.irow { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-top: 1px solid var(--border); }
.irow:first-child { border-top: 0; }
.irow .main { flex: 1; min-width: 0; }
.irow .title { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.irow .title:hover { color: var(--accent); }
.irow .meta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; font-size: .8rem; color: var(--muted); margin-top: 2px; }
.irow .acts { display: flex; gap: 6px; flex-shrink: 0; }
.group-h { display: flex; align-items: center; gap: 8px; margin: 22px 0 4px; padding-bottom: 6px; border-bottom: 2px solid var(--border); }
.group-h h3 { margin: 0; }
.group-h .chip { margin-left: auto; }

/* level page */
.lhead { --c: #64748b; margin: 22px 0 16px; border-radius: 18px; padding: 24px; color: #fff;
  background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 55%, #0f172a)); box-shadow: var(--shadow); }
.lhead .code { font-size: 2.6rem; font-weight: 800; letter-spacing: -.03em; line-height: 1; opacity: .95; }
.lhead h1 { margin: 6px 0 4px; color: #fff; }
.lhead p { margin: 0; opacity: .9; }
.lhead .btn { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.28); }
.lhead .btn:hover { background: rgba(255,255,255,.26); }
.lhead .chip { background: rgba(255,255,255,.18); color: #fff; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 4px; overflow-x: auto; }
.tabs button { font: inherit; font-weight: 600; background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 10px 12px; cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs button .chip { margin-left: 4px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 0; }
.filters input[type=search] { flex: 1; min-width: 200px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { font: inherit; font-size: .82rem; font-weight: 600; background: var(--surface); color: var(--muted);
  border: 0; padding: 6px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }

/* item page */
.crumbs { font-size: .85rem; color: var(--muted); margin: 18px 0 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.preview { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); }
.preview iframe { display: block; width: 100%; height: 78vh; border: 0; background: #fff; }
.preview audio, .preview video { display: block; width: 100%; }
.preview img { display: block; max-width: 100%; margin: 0 auto; }
.ratio { position: relative; padding-top: 56.25%; } .ratio iframe { position: absolute; inset: 0; height: 100%; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: .9rem; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.folder { margin-top: 14px; }
.folder > summary { cursor: pointer; font-weight: 650; padding: 6px 0; }
audio.mini { height: 32px; width: 240px; max-width: 100%; }

/* tables */
.tablewrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.t th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  font-weight: 700; padding: 8px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.t td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.t tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t .clip { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* flash */
.flash { border-radius: var(--radius-sm); padding: 10px 14px; margin: 14px 0; font-weight: 500; }
.flash.ok { background: var(--ok-soft); color: var(--ok); } .flash.err { background: var(--bad-soft); color: var(--bad); }

footer.foot { margin: 48px 0 24px; padding-top: 18px; border-top: 1px solid var(--border); color: var(--faint); font-size: .82rem; }

/* admin */
.admin-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { padding: 4px 8px 16px; }
.side nav a { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: .9rem; }
.side nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.side nav a.on { background: var(--accent-soft); color: var(--accent); }
.side nav .sep { height: 1px; background: var(--border); margin: 10px 4px; }
.admin-main { padding: 22px 26px 40px; min-width: 0; }
.admin-main h1 { font-size: 1.5rem; }
.progress { height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .4s ease; }
pre.log { background: #0b1020; color: #cbd5e1; border-radius: var(--radius-sm); padding: 12px; height: 340px; overflow: auto;
  font-size: .76rem; line-height: 1.45; white-space: pre-wrap; word-break: break-word; margin: 0; }
pre.log .warn { color: #fbbf24; } pre.log .error { color: #f87171; } pre.log .debug { color: #64748b; }
.kpis { display: flex; flex-wrap: wrap; gap: 6px; }
.login { max-width: 380px; margin: 12vh auto; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 6px; margin: 0 0 16px; }
legend { font-weight: 700; padding: 0 6px; }
details.guide { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: .8rem; }
details.guide summary { cursor: pointer; }
details.guide ol { padding-left: 1.3rem; margin: .7rem 0; font-size: .9rem; }
details.guide li + li { margin-top: .45rem; }
fieldset#brave { border-color: color-mix(in srgb, #fb542b 45%, var(--border)); }
.bulkbar { position: sticky; top: 0; z-index: 5; background: var(--surface); padding: 10px 0; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; border-bottom: 1px solid var(--border); }
.pager { display: flex; gap: 6px; align-items: center; margin-top: 12px; }

@media (max-width: 860px) {
  .admin-shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .side nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .side nav .sep { display: none; }
  .admin-main { padding: 16px; }
}
@media (max-width: 640px) {
  h1 { font-size: 1.5rem; }
  .irow { flex-wrap: wrap; }
  .irow .acts { width: 100%; padding-left: 64px; }
  .searchbox { max-width: none; order: 5; flex-basis: 100%; }
  .lhead { padding: 18px; }
  .preview iframe { height: 65vh; }
}
