:root {
  color-scheme: dark;
  --bg: #0a0a0c;
  --surface: #121217;
  --surface-2: #191921;
  --surface-3: #22222d;
  --border: #323240;
  --border-strong: #4e4e64;
  --text: #f3f3f6;
  --text-muted: #a9a9bd;
  --accent: #facc15;
  --accent-hover: #eab308;
  --accent-ink: #0a0a0c;
  --accent-soft: color-mix(in oklab, var(--accent) 14%, var(--surface));
  --danger: #f87171;
  --danger-soft: color-mix(in oklab, #ef4444 16%, var(--surface));
  --success: #4ade80;
  --success-soft: color-mix(in oklab, #22c55e 16%, var(--surface));
  --warning: #fbbf24;
  --radius: 10px;
  --radius-sm: 6px;
  --font-sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", Consolas, ui-monospace, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.55;
  accent-color: var(--accent);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  z-index: 1000;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.65rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.skip-link:focus {
  top: 0.75rem;
}

.container {
  width: min(1140px, 100% - 2rem);
  margin-inline: auto;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 60px;
  flex-wrap: wrap;
  padding-block: 0.4rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  font-size: 0.9rem;
}

.brand-sub {
  color: var(--text-muted);
  font-weight: 400;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.nav-link {
  color: var(--text-muted);
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
}
.nav-link:hover {
  color: var(--text);
  background: var(--surface-2);
  text-decoration: none;
}
.nav-link.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

.main-wrap {
  flex: 1;
  padding-block: 2rem 3.5rem;
}

.footer {
  border-top: 1px solid var(--border);
  padding-block: 1.25rem;
  font-size: 0.86rem;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.text-muted {
  color: var(--text-muted);
}

/* Cards & Surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  position: relative;
}

.card-accent-strip,
.card-top-bar {
  position: absolute;
  inset-inline: 0;
  inset-block-start: 0;
  height: 4px;
  background: var(--accent);
  border-radius: var(--radius) var(--radius) 0 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover {
  text-decoration: none;
}

.btn-sm {
  min-height: 36px;
  padding: 0.35rem 0.7rem;
  font-size: 0.84rem;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover {
  background: var(--surface-3);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-2);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in oklab, var(--danger) 50%, var(--border));
}
.btn-danger:hover {
  background: color-mix(in oklab, var(--danger) 24%, var(--surface));
}

.inline-form {
  display: inline-flex;
}

/* Badges & Pills */
.badge, .pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: color-mix(in oklab, var(--accent) 40%, var(--border));
}

.badge-req {
  color: var(--danger);
  border-color: color-mix(in oklab, var(--danger) 40%, var(--border));
}

.req {
  color: var(--accent);
  font-weight: 700;
}

/* Hero & Catalog */
.hero {
  padding-block: 1.5rem 2.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}

.hero-badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.6rem;
}

.hero-title, .page-title {
  margin: 0 0 0.6rem;
  font-size: clamp(1.6rem, 3.2vw, 2.35rem);
  line-height: 1.18;
  letter-spacing: -0.025em;
}

.hero-lead, .page-subtitle {
  margin: 0;
  color: var(--text-muted);
  max-width: 66ch;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.35rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.section-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr));
  gap: 1.15rem;
}

.material-card {
  display: flex;
  flex-direction: column;
  padding-top: 1.5rem;
}

.material-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.material-title {
  margin: 0 0 0.45rem;
  font-size: 1.12rem;
  line-height: 1.3;
}

.material-sub {
  margin: 0 0 0.6rem;
  font-size: 0.86rem;
  color: var(--accent);
}

.material-desc {
  margin: 0 0 1.25rem;
  font-size: 0.92rem;
  color: var(--text-muted);
  flex: 1;
}

/* Forms & Controls */
.field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  margin-block-end: 1rem;
}

.field > label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="email"],
select,
textarea {
  font: inherit;
  font-size: max(1rem, 1em);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.8rem;
  min-height: 48px;
  width: 100%;
  box-sizing: border-box;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

@media (pointer: coarse) {
  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="search"],
  select {
    min-height: 52px;
  }
}

:is(:user-invalid, .user-invalid-fallback) {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.error-msg {
  display: none;
  color: var(--danger);
  font-size: 0.85rem;
  gap: 0.35rem;
  align-items: center;
}

:is(:user-invalid, .user-invalid-fallback) + .error-msg {
  display: flex;
}

.alert {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  font-size: 0.92rem;
}
.alert-error {
  background: var(--danger-soft);
  border-color: color-mix(in oklab, var(--danger) 50%, var(--border));
  color: var(--danger);
}
.alert-success {
  background: var(--success-soft);
  border-color: color-mix(in oklab, var(--success) 50%, var(--border));
  color: var(--success);
}

.form-row-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.form-row-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.password-row {
  display: flex;
  gap: 0.5rem;
}

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-top: 0.25rem;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  min-height: 44px;
}

input[type="checkbox"],
input[type="radio"] {
  width: 1.15rem;
  height: 1.15rem;
  flex: none;
  cursor: pointer;
}

@supports not (accent-color: #facc15) {
  .option-row input[type="checkbox"],
  .option-row input[type="radio"],
  .inline-check input[type="checkbox"] {
    position: absolute;
    clip-path: inset(50%);
    width: 1px;
    height: 1px;
    overflow: hidden;
  }
  .option-row input + span::before,
  .inline-check input + span::before {
    content: "";
    display: inline-block;
    width: 1.1rem;
    height: 1.1rem;
    border: 2px solid var(--border-strong);
    border-radius: 4px;
    margin-inline-end: 0.55rem;
    vertical-align: middle;
  }
  .option-row input[type="radio"] + span::before {
    border-radius: 50%;
  }
  .option-row input:checked + span::before,
  .inline-check input:checked + span::before {
    background: var(--accent);
    border-color: var(--accent);
  }
}

/* Material View (Google-Form-inspired dark cards) */
.material-shell {
  width: min(820px, 100%);
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.material-header-card {
  padding-top: 1.75rem;
}

.material-header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.material-main-title {
  margin: 0 0 0.5rem;
  font-size: clamp(1.35rem, 2.6vw, 1.8rem);
  line-height: 1.25;
}

.material-main-desc {
  margin: 0;
  color: var(--text-muted);
}

.stepper-nav {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.material-progress {
  width: 100%;
  height: 6px;
  margin-bottom: 0.85rem;
  border-radius: 999px;
}

.stepper-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.stepper-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.83rem;
  cursor: pointer;
  min-height: 36px;
}
.stepper-btn.is-current {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.stepper-num {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface-3);
  font-size: 0.75rem;
  font-weight: 700;
}
.stepper-btn.is-current .stepper-num {
  background: var(--accent);
  color: var(--accent-ink);
}

.material-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.material-section[hidden] {
  display: none;
}

.section-banner {
  border-left: 4px solid var(--accent);
}
.section-banner-tag {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 0.25rem;
}
.section-banner-title {
  margin: 0 0 0.35rem;
  font-size: 1.22rem;
}
.section-banner-desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.block-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.block-title,
.card-section-title {
  margin: 0;
  font-size: 1.05rem;
}

.block-legend {
  font-weight: 600;
  font-size: 1rem;
  padding: 0;
  margin-bottom: 0.45rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.options-stack {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.option-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  min-height: 48px;
}
.option-row:hover {
  border-color: var(--border-strong);
}

.block-figure {
  margin: 0;
}
.block-figure img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
}
.block-figure figcaption {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Markdown theory content */
.md-body {
  font-size: 0.95rem;
  color: var(--text);
}
.md-p { margin: 0 0 0.65rem; }
.md-p:last-child { margin-bottom: 0; }
.md-list {
  margin: 0.35rem 0 0.75rem;
  padding-inline-start: 1.35rem;
}
.md-list li {
  margin-bottom: 0.3rem;
}
.md-inline-code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--surface-3);
  color: var(--accent);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}
.md-code {
  background: #08080a;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  margin: 0.5rem 0;
}
.md-callout {
  margin: 0.6rem 0;
  padding: 0.65rem 0.9rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.9rem;
}

/* 1C:Элемент Code Workbench */
.code-workbench {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #09090c;
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.code-lang {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
}

.code-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.code-editor {
  border: 0;
  border-radius: 0;
  background: #09090c;
  color: #f4f4f8;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.5;
  padding: 0.85rem 1rem;
  tab-size: 4;
}

.sandbox-editor {
  min-height: 360px;
}

.stdin-details {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 0.45rem 0.75rem;
}
.stdin-details summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-muted);
  user-select: none;
}
.stdin-input {
  margin-top: 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  min-height: 54px;
}

.code-output-panel {
  border-top: 1px solid var(--border);
  padding: 0.85rem;
  background: #070709;
  font-size: 0.88rem;
}
.code-output-panel.is-sandbox {
  border-top: 0;
  min-height: 240px;
}

.output-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
}
.output-status.is-ok { color: var(--success); }
.output-status.is-err { color: var(--danger); }

.console-pre {
  margin: 0;
  padding: 0.7rem 0.85rem;
  background: #101015;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.checks-list {
  list-style: none;
  margin: 0.65rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.check-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.84rem;
}
.check-item.is-pass {
  background: var(--success-soft);
  color: var(--success);
}
.check-item.is-fail {
  background: var(--danger-soft);
  color: var(--danger);
}

.section-nav-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

/* Sandbox layout */
.sandbox-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.select-control {
  min-width: min(300px, 100%);
}
.sandbox-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1rem;
  align-items: start;
}
.sandbox-pane {
  padding: 0;
  overflow: hidden;
}
.output-placeholder {
  color: var(--text-muted);
  padding: 0.5rem;
}
.syntax-cheatsheet {
  padding: 0.9rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.84rem;
  color: var(--text-muted);
}
.syntax-cheatsheet h3 {
  margin: 0 0 0.5rem;
  font-size: 0.92rem;
  color: var(--text);
}
.syntax-cheatsheet ul {
  margin: 0;
  padding-inline-start: 1.2rem;
}
.syntax-cheatsheet code {
  color: var(--accent);
  font-family: var(--font-mono);
}

/* Admin & KPI */
.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.admin-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}
.kpi-card {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.kpi-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.kpi-val {
  font-size: 1.65rem;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.filter-card {
  margin-bottom: 1.25rem;
}
.filter-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.85rem;
  align-items: end;
}
.filter-form .field {
  margin-block-end: 0;
}
.filter-actions {
  display: flex;
  gap: 0.5rem;
}

/* Responsive Tables */
.table-card {
  padding: 0;
  overflow: hidden;
}
.table-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.table-card-head h2 {
  margin: 0;
  font-size: 1.08rem;
}

.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(640px, 75vh);
  container-type: inline-size;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.data-table thead th {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.data-table tbody th {
  position: sticky;
  inset-inline-start: 0;
  z-index: 1;
  background: var(--surface);
  font-weight: 600;
}

.table-title-link {
  color: var(--text);
  font-weight: 600;
}
.table-title-link:hover {
  color: var(--accent);
}
.table-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 400;
}
.link-accent {
  color: var(--accent);
  font-weight: 600;
}

.status-pill {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text-muted);
  min-height: 32px;
}
.status-pill.is-on {
  color: var(--success);
  background: var(--success-soft);
  border-color: color-mix(in oklab, var(--success) 45%, var(--border));
}

.score-pill {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.82rem;
  white-space: nowrap;
}
.score-pill.is-good { background: var(--success-soft); color: var(--success); }
.score-pill.is-mid { background: var(--accent-soft); color: var(--accent); }
.score-pill.is-low { background: var(--danger-soft); color: var(--danger); }

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

@container (width < 640px) {
  .data-table,
  .data-table thead,
  .data-table tbody,
  .data-table tr,
  .data-table th,
  .data-table td {
    display: block;
  }
  .data-table thead {
    display: none;
  }
  .data-table tr {
    margin: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    overflow: hidden;
  }
  .data-table tbody th {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
    background: var(--surface-3);
    border-bottom: 1px solid var(--border);
  }
  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid var(--border);
  }
  .data-table td::before {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
  }
  .materials-table td:nth-child(2)::before { content: "Модуль: "; }
  .materials-table td:nth-child(3)::before { content: "Разделы: "; }
  .materials-table td:nth-child(4)::before { content: "Ответы: "; }
  .materials-table td:nth-child(5)::before { content: "Средний %: "; }
  .materials-table td:nth-child(6)::before { content: "Статус: "; }
  .materials-table td:nth-child(7)::before { content: "Действия: "; }

  .submissions-table td:nth-child(2)::before { content: "Группа: "; }
  .submissions-table td:nth-child(3)::before { content: "Материал: "; }
  .submissions-table td:nth-child(4)::before { content: "Теория: "; }
  .submissions-table td:nth-child(5)::before { content: "Код 1С: "; }
  .submissions-table td:nth-child(6)::before { content: "Итог: "; }
  .submissions-table td:nth-child(7)::before { content: "Дата: "; }
  .submissions-table td:nth-child(8)::before { content: "Действия: "; }
}

/* Native <dialog> */
dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 1.35rem;
  width: min(480px, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  overflow: auto;
}
dialog.dialog-wide {
  width: min(840px, calc(100vw - 2rem));
}
dialog:modal {
  overscroll-behavior: contain;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.74);
  overflow: hidden;
  overscroll-behavior: contain;
}
.dialog-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.dialog-title {
  margin: 0 0 0.5rem;
  font-size: 1.18rem;
}
.dialog-header-row .dialog-title {
  margin-bottom: 0;
}
.dialog-body {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1rem;
}

/* Builder */
.builder-topbar {
  position: sticky;
  top: 60px;
  z-index: 30;
  background: color-mix(in oklab, var(--bg) 94%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 1rem;
  margin-bottom: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.builder-topbar-left, .builder-topbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.builder-heading {
  margin: 0;
  font-size: 1.05rem;
}
.builder-meta-card {
  padding-top: 1.5rem;
  margin-bottom: 1.25rem;
}
.builder-section-card {
  margin-bottom: 1.25rem;
  border-left: 4px solid var(--accent);
}
.builder-section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}
.builder-block-card {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-top: 0.85rem;
}
.builder-block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.builder-add-blocks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--border-strong);
}
.builder-add-section-bar {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.builder-opt-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

/* Auth & Settings */
.auth-wrap {
  max-width: 440px;
  margin: 2.5rem auto;
}
.auth-card {
  padding-top: 1.75rem;
}
.auth-title {
  margin: 0 0 0.35rem;
  font-size: 1.4rem;
}
.auth-sub {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.settings-card {
  max-width: 560px;
}

/* Result summary */
.result-card {
  border-top: 4px solid var(--accent);
}
.result-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0 1.25rem;
}
.result-item {
  padding: 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin-bottom: 0.65rem;
}

/* Toasts */
.toast-region {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(360px, calc(100vw - 2rem));
}
.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

@media (max-width: 860px) {
  .sandbox-grid {
    grid-template-columns: 1fr;
  }
}

@media (forced-colors: active) {
  .card, .btn, input, select, textarea, dialog {
    border: 1px solid ButtonBorder;
  }
  .btn-primary {
    background: Highlight;
    color: HighlightText;
  }
  .card-accent-strip, .card-top-bar {
    background: Highlight;
  }
}
