:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  color: #202622;
  background: #f3f5f3;
  --ink: #202622;
  --muted: #667069;
  --line: #d9dfda;
  --surface: #ffffff;
  --green: #207b58;
  --blue: #315b8a;
  --amber: #b87908;
  --red: #b84436;
  --focus: #d59a13;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: #f3f5f3; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { letter-spacing: 0; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.brand { display: flex; align-items: center; gap: 11px; min-width: 170px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 6px; background: var(--ink); color: #fff; font-weight: 900; }
.brand strong, .brand small { display: block; }
.brand small { color: var(--muted); font-size: .78rem; }

.auth-layout { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #e8ece9; }
.auth-panel { width: min(430px, 100%); padding: 30px; border: 1px solid #cbd3cd; border-top: 5px solid var(--green); border-radius: 8px; background: var(--surface); box-shadow: 0 18px 42px #18231c1c; }
.auth-panel .brand { margin-bottom: 42px; }
.auth-panel h1 { margin: 7px 0 28px; font-size: 1.75rem; }
.auth-panel label { display: grid; gap: 8px; font-weight: 750; font-size: .9rem; }
.auth-panel input { min-height: 48px; width: 100%; padding: 0 12px; border: 1px solid #aeb8b0; border-radius: 6px; }
.auth-panel .primary { width: 100%; margin-top: 16px; min-height: 46px; }
.auth-panel code { display: block; padding: 13px; overflow-wrap: anywhere; border: 1px solid var(--line); background: #f6f7f6; }

.topbar { min-height: 68px; padding: 10px clamp(18px, 4vw, 52px); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 22px; border-bottom: 1px solid var(--line); background: var(--surface); }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { padding: 9px 12px; border-radius: 5px; color: #32423a; text-decoration: none; font-weight: 700; font-size: .88rem; }
.topbar nav a:hover { background: #edf2ee; }
.topbar > button { justify-self: end; }

.workspace { width: min(1480px, 100%); margin: 0 auto; padding: 34px clamp(18px, 4vw, 52px) 60px; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.page-head h1 { margin: 4px 0 0; font-size: 2.2rem; }
.state-label { margin: 0; color: var(--green); font-size: .76rem; font-weight: 850; text-transform: uppercase; }

.primary, .quiet, .danger, .row-action { min-height: 40px; border-radius: 5px; padding: 0 14px; border: 1px solid transparent; font-weight: 750; }
.primary { background: var(--ink); color: #fff; }
.primary:hover { background: #374039; }
.quiet, .row-action { background: #fff; color: var(--ink); border-color: #bfc8c1; }
.quiet:hover, .row-action:hover { background: #eef2ef; }
.danger { background: #fff; color: #8d3025; border-color: #d9aaa4; }
.primary:disabled, .quiet:disabled { opacity: .5; cursor: not-allowed; }

.metrics { margin: 28px 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.metrics div { min-height: 88px; padding: 17px 20px; display: grid; align-content: center; gap: 5px; border-right: 1px solid var(--line); }
.metrics div:last-child { border-right: 0; }
.metrics span { color: var(--muted); font-size: .82rem; }
.metrics strong { font-size: 1.45rem; }

.catalogue { border-top: 3px solid var(--ink); background: var(--surface); }
.library-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); border: 1px solid var(--line); border-top: 0; }
.tree-panel { min-width: 0; padding: 16px 12px; border-right: 1px solid var(--line); background: #f7f9f7; }
.tree-title { display: grid; gap: 8px; padding: 0 5px 13px; border-bottom: 1px solid var(--line); }
.tree-title h2 { margin: 0; font-size: 1rem; }
.tree-reset, .tree-node { width: 100%; min-height: 35px; border: 0; border-radius: 4px; background: transparent; color: var(--ink); text-align: left; }
.tree-reset { padding: 0 9px; font-weight: 750; }
.tree { padding-top: 8px; }
.tree-node { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 7px; padding: 6px 8px; }
.tree-node span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-node small { color: var(--muted); }
.tree-node.depth-1 { padding-left: 20px; }
.tree-node.depth-2 { padding-left: 32px; }
.tree-node.depth-3 { padding-left: 44px; }
.tree-node.depth-4 { padding-left: 56px; }
.tree-node.depth-5 { padding-left: 68px; }
.tree-node.depth-6, .tree-node.depth-7 { padding-left: 80px; }
.tree-reset:hover, .tree-node:hover { background: #e9eeea; }
.tree-reset.active, .tree-node.active { background: #dfeae3; color: #145f43; }
.catalog-main { min-width: 0; }
.toolbar { min-height: 74px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 18px; border: 1px solid var(--line); border-top: 0; }
.toolbar h2 { margin: 0; font-size: 1.05rem; }
.toolbar small { display: block; margin-top: 4px; color: var(--muted); }
.filters { display: flex; gap: 8px; }
.filters input, .filters select { height: 40px; padding: 0 11px; border: 1px solid #bac4bc; border-radius: 5px; background: #fff; }
.filters input { width: min(290px, 32vw); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-top: 0; }
.library-layout .toolbar, .library-layout .table-wrap { border-left: 0; border-right: 0; }
.library-layout .table-wrap { border-bottom: 0; }
table { width: 100%; min-width: 990px; border-collapse: collapse; table-layout: fixed; }
th { padding: 11px 14px; background: #f0f3f1; color: #55615a; text-align: left; font-size: .76rem; }
td { padding: 14px; border-top: 1px solid #e3e7e4; vertical-align: middle; font-size: .88rem; overflow-wrap: anywhere; }
th:nth-child(1) { width: 30%; } th:nth-child(2) { width: 16%; } th:nth-child(3) { width: 12%; } th:nth-child(4) { width: 11%; } th:nth-child(5) { width: 15%; } th:nth-child(6) { width: 16%; }
td strong, td small { display: block; }
td small { margin-top: 4px; color: var(--muted); line-height: 1.35; }
.actions { display: flex; justify-content: flex-end; gap: 5px; flex-wrap: wrap; }
.row-action { min-height: 32px; padding: 0 9px; font-size: .78rem; }
.badge { display: inline-flex; min-height: 25px; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 800; white-space: nowrap; }
.badge.students { background: #e8f0fb; color: #24517f; }
.badge.teachers { background: #e5f2ec; color: #176244; }
.badge.correction { background: #fce9e6; color: #922f23; }
.site-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.file-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.file-badges span { padding: 3px 6px; border-radius: 4px; background: #edf1ee; color: #425047; font-size: .7rem; font-weight: 800; }
.badge.published { background: #e3f2e9; color: #176244; }
.badge.draft { background: #fff2d9; color: #7a5000; }
.badge.archived { background: #eceeed; color: #59615c; }
.empty-state { margin: 0; padding: 45px; text-align: center; border: 1px solid var(--line); border-top: 0; color: var(--muted); }

dialog { width: min(860px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 0; border-radius: 8px; box-shadow: 0 24px 70px #101a1460; }
dialog::backdrop { background: #111b1599; }
.dialog-shell { display: flex; max-height: calc(100vh - 28px); flex-direction: column; background: #fff; }
.dialog-head { min-height: 76px; padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 3px 0 0; font-size: 1.3rem; }
.icon-button { width: 40px; height: 40px; flex: 0 0 40px; border: 1px solid #c7cec9; border-radius: 50%; background: #fff; font-size: 1.55rem; line-height: 1; }
.dialog-body { padding: 20px; overflow-y: auto; }
.dialog-actions { min-height: 66px; padding: 12px 20px; display: flex; justify-content: flex-end; gap: 9px; border-top: 1px solid var(--line); background: #f6f8f6; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px; }
.form-grid label { display: grid; align-content: start; gap: 7px; font-size: .83rem; font-weight: 750; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; min-height: 42px; padding: 9px 10px; border: 1px solid #b8c2ba; border-radius: 5px; background: #fff; resize: vertical; }
.wide { grid-column: 1 / -1; }
fieldset { margin: 0; border: 1px solid var(--line); border-radius: 6px; }
legend { padding: 0 6px; font-size: .83rem; font-weight: 750; }
.audience-field { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 13px; }
.destination-checks { display: flex; flex-wrap: wrap; gap: 8px; }
.destination-checks label { display: block; }
.destination-checks input { position: absolute; opacity: 0; pointer-events: none; }
.destination-checks span { display: block; min-width: 130px; padding: 9px 12px; border: 1px solid #b8c2ba; border-radius: 5px; background: #fff; text-align: center; }
.destination-checks input:checked + span { border-color: var(--green); background: #e5f0e9; color: #145f43; box-shadow: inset 0 0 0 1px var(--green); }
.destination-checks input:disabled + span { opacity: .45; cursor: not-allowed; }
.destination-checks input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.check { display: flex !important; grid-template-columns: 18px 1fr; align-items: center !important; }
.check input { width: 18px; min-height: 18px; }
.levels-field { padding: 12px; }
.levels-field > div { display: flex; flex-wrap: wrap; gap: 12px; }
.levels-field label { display: flex; grid-template-columns: 18px auto; align-items: center; gap: 6px; }
.levels-field input { width: 18px; min-height: 18px; }
.files-field { padding: 12px; }
.file-slots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.file-slot { min-width: 0; padding: 11px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: #f8faf8; }
.file-slot label { grid-column: 1 / -1; }
.file-slot strong { font-size: .8rem; }
.file-slot input { min-height: 38px; padding: 6px; background: #fff; }
.file-slot > span { min-width: 0; overflow: hidden; color: var(--muted); font-size: .76rem; text-overflow: ellipsis; white-space: nowrap; }
.file-slot > button { min-height: 28px; padding: 0 8px; border: 1px solid #d9aaa4; border-radius: 4px; background: #fff; color: #8d3025; font-size: .72rem; }
.correction-slot { border-left: 4px solid var(--red); }
.form-error { min-height: 20px; margin: 0; color: #982f24; }

.preview-shell { height: min(760px, calc(100vh - 28px)); }
.preview-frame { flex: 1; min-height: 340px; background: #dfe4e0; }
.preview-frame iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.confirm-shell { width: 100%; }
.confirm-shell .dialog-body { line-height: 1.55; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: min(420px, calc(100% - 44px)); padding: 13px 16px; border-radius: 6px; background: #202622; color: #fff; box-shadow: 0 10px 28px #101a1438; }

@media (max-width: 820px) {
  .topbar { grid-template-columns: 1fr auto; }
  .topbar nav { display: none; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics div:nth-child(2) { border-right: 0; }
  .metrics div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .toolbar { align-items: stretch; flex-direction: column; }
  .filters { display: grid; grid-template-columns: 1fr 1fr; }
  .filters input { width: 100%; grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr; }
  .wide { grid-column: 1; }
  .audience-field { align-items: stretch; flex-direction: column; }
  .file-slots { grid-template-columns: 1fr; }
  .library-layout { grid-template-columns: 1fr; }
  .tree-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .tree { max-height: 240px; overflow-y: auto; }
}

@media (max-width: 480px) {
  .workspace { padding-inline: 12px; }
  .topbar { padding-inline: 12px; }
  .topbar .quiet { width: 42px; padding: 0; overflow: hidden; color: transparent; }
  .topbar .quiet::after { content: "×"; color: var(--ink); font-size: 1.4rem; }
  .page-head { align-items: stretch; flex-direction: column; }
  .page-head h1 { font-size: 1.8rem; }
  .page-head .primary { width: 100%; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metrics div { padding: 13px; }
  .destination-checks { display: grid; grid-template-columns: 1fr 1fr; }
  .destination-checks span { min-width: 0; }
}
