:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --surface-2: #f7f7f8;             /* table headers, sidebar headings, soft fills */
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e5e5;
  --accent: #ff6b1f;
  --accent-hover: #e85d10;
  --accent-soft: #fff1e8;
  --accent-soft-strong: #f0f4ff;    /* picker chips */
  --accent-soft-strong-border: #c5d4f3;
  --danger: #d92d20;
  --success: #16a34a;
  --warn: #b45309;
  --chip-new-bg: #ecfdf5;
  --chip-new-fg: #16a34a;
  --chip-dup-bg: #fef2f2;
  --chip-dup-fg: #d92d20;
  --chip-rej-bg: #fef3c7;
  --chip-rej-fg: #b45309;
  --chip-rev-bg: #e0f2fe;
  --chip-rev-fg: #0369a1;
  --chip-acc-bg: #dcfce7;
  --chip-acc-fg: #15803d;
  --alert-err-bg: #fef2f2;
  --alert-err-fg: #d92d20;
  --alert-ok-bg: #ecfdf5;
  --alert-ok-fg: #16a34a;
  --modal-overlay: rgba(0, 0, 0, 0.5);
  --radius: 14px;
  --shadow: 0 8px 24px rgba(20, 20, 20, 0.06);
  color-scheme: light;
}

/* ---------- Dark theme ---------------------------------------------------
 *
 * Activated either by `data-theme="dark"` on <html> (explicit user choice
 * persisted in localStorage) OR by the user's system preference when no
 * explicit choice is set. The `:root:not([data-theme="light"])` selector
 * inside the media query lets an explicit `light` override the system.
 *
 * Toggle is wired up by common.js (theme-toggle button in the header).
 * The no-flash inline script in each HTML <head> reads localStorage
 * synchronously before paint so users who override system preference
 * don't see a flash of the wrong theme on every navigation. */
:root[data-theme="dark"] {
  --bg: #0e0e12;
  --surface: #1a1a20;
  --surface-2: #232329;
  --text: #e8e8ea;
  --muted: #8a8b94;
  --border: #2c2c33;
  --accent: #ff7a35;
  --accent-hover: #ff9056;
  --accent-soft: #2a1810;
  --accent-soft-strong: #1f2438;
  --accent-soft-strong-border: #3a4a72;
  --danger: #ff6157;
  --success: #2bd874;
  --warn: #f0a020;
  --chip-new-bg: #0e2a1c;
  --chip-new-fg: #5ee19c;
  --chip-dup-bg: #2e1212;
  --chip-dup-fg: #ff8278;
  --chip-rej-bg: #2e2208;
  --chip-rej-fg: #f5c75a;
  --chip-rev-bg: #0e2230;
  --chip-rev-fg: #5ec0f5;
  --chip-acc-bg: #0e2a1c;
  --chip-acc-fg: #5ee19c;
  --alert-err-bg: #2e1212;
  --alert-err-fg: #ff8278;
  --alert-ok-bg: #0e2a1c;
  --alert-ok-fg: #5ee19c;
  --modal-overlay: rgba(0, 0, 0, 0.7);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e12;
    --surface: #1a1a20;
    --surface-2: #232329;
    --text: #e8e8ea;
    --muted: #8a8b94;
    --border: #2c2c33;
    --accent: #ff7a35;
    --accent-hover: #ff9056;
    --accent-soft: #2a1810;
    --accent-soft-strong: #1f2438;
    --accent-soft-strong-border: #3a4a72;
    --danger: #ff6157;
    --success: #2bd874;
    --warn: #f0a020;
    --chip-new-bg: #0e2a1c;
    --chip-new-fg: #5ee19c;
    --chip-dup-bg: #2e1212;
    --chip-dup-fg: #ff8278;
    --chip-rej-bg: #2e2208;
    --chip-rej-fg: #f5c75a;
    --chip-rev-bg: #0e2230;
    --chip-rev-fg: #5ec0f5;
    --chip-acc-bg: #0e2a1c;
    --chip-acc-fg: #5ee19c;
    --alert-err-bg: #2e1212;
    --alert-err-fg: #ff8278;
    --alert-ok-bg: #0e2a1c;
    --alert-ok-fg: #5ee19c;
    --modal-overlay: rgba(0, 0, 0, 0.7);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

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

.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.logo {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.5px;
}
.logo .dot { color: var(--accent); }
.nav { display: flex; gap: 18px; flex: 1; }
.nav a {
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
}
.nav a.active, .nav a:hover { color: var(--text); text-decoration: none; }
.nav a.active { color: var(--accent); }
.header-right { display: flex; gap: 8px; align-items: center; }

.container { max-width: 1180px; margin: 0 auto; padding: 28px 24px; }
.container.narrow { max-width: 560px; }

.hero {
  background: var(--surface);
  border-radius: 24px;
  padding: 36px 40px;
  margin-bottom: 28px;
  box-shadow: var(--shadow);
}
.hero h1 { font-size: 40px; margin: 0 0 12px; line-height: 1.1; }
.hero p { color: var(--muted); margin: 0; max-width: 560px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 14px; font-size: 22px; }
.card h3 { margin: 0 0 10px; font-size: 16px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 800px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hero h1 { font-size: 28px; }
}

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.field-inline { display: flex; align-items: center; gap: 8px; }
.field-inline label { margin: 0; }

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="tel"],
select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent;
  background: var(--accent); color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
.btn:hover { background: var(--accent-hover); }
.btn.outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn.outline:hover { background: var(--bg); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tab {
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.chip {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.chip.new { background: var(--chip-new-bg); color: var(--chip-new-fg); }
.chip.duplicate { background: var(--chip-dup-bg); color: var(--chip-dup-fg); }
.chip.rejected { background: var(--chip-rej-bg); color: var(--chip-rej-fg); }
.chip.in_review { background: var(--chip-rev-bg); color: var(--chip-rev-fg); }
.chip.accepted { background: var(--chip-acc-bg); color: var(--chip-acc-fg); }
.chip.muted { background: var(--surface-2); color: var(--muted); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.success { background: var(--chip-new-bg); color: var(--chip-new-fg); }
.chip.warn { background: var(--chip-rej-bg); color: var(--chip-rej-fg); }

.alert { padding: 12px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.alert.error { background: var(--alert-err-bg); color: var(--alert-err-fg); }
.alert.warn { background: var(--chip-rej-bg); color: var(--chip-rej-fg); }
.alert.success { background: var(--alert-ok-bg); color: var(--alert-ok-fg); }
.alert.info { background: var(--accent-soft); color: var(--accent); }

.list { display: flex; flex-direction: column; gap: 12px; }
.list-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  gap: 12px;
}
.list-row .meta { color: var(--muted); font-size: 13px; }
.list-row .actions { display: flex; gap: 8px; }

.direction-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  min-height: 180px;
}
.direction-card .title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.direction-card .group { font-size: 12px; color: var(--accent); margin-bottom: 8px; font-weight: 600; }
.direction-card .desc { color: var(--muted); flex: 1; margin-bottom: 14px; font-size: 14px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
th { font-weight: 600; color: var(--muted); }
tr:last-child td { border-bottom: none; }

.muted { color: var(--muted); }
.right { text-align: right; }
.row-flex { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
small.hint { color: var(--muted); font-size: 12px; }

.modal-bg {
  position: fixed; inset: 0; background: var(--modal-overlay);
  display: none; align-items: center; justify-content: center; z-index: 50;
  padding: 24px;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  padding: 24px; max-width: 640px; width: 100%;
  max-height: 90vh; overflow: auto;
}
.modal h3 { margin-top: 0; }

.kv { display: grid; grid-template-columns: 200px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

pre.code {
  background: #0f172a; color: #e2e8f0;
  padding: 12px; border-radius: 10px;
  overflow: auto; font-size: 12px;
}

.toggle {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
}
.toggle input { width: auto; margin: 0; }

/* --- Test-taking page --- */

/* Sticky timer bar appears just below the header during the taking phase. */
.timer-bar {
  position: sticky;
  top: 56px;
  z-index: 9;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.timer-display {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 18px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.timer-display.warn {
  background: #fef2f2;
  color: var(--danger);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.6; } }

/* Radio / checkbox option rows in the test-taking UI. Made comfortable for
 * touch — minimum 40px height, full-row tap target. */
.option-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 15px;
}
.option-row:hover { background: var(--bg); }
.option-row input[type="radio"],
.option-row input[type="checkbox"] {
  width: auto;
  margin: 0;
  flex: none;
}

/* --- Workflow steps (Мои заявки) --- */

/* Result-delay countdown shown on a step in "waiting_result" view status. */
.countdown {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.countdown-icon { font-size: 16px; }
.countdown-time { letter-spacing: 0.2px; }

/* Step section inside an application card — gives the step row a subtle
 * separator from the application header without taking too much space. */
.step-section {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ---------- Theme toggle button -----------------------------------------
 *
 * Lives inside .header-right, before the email + logout buttons. The icon
 * (sun ☀ in dark mode, moon ☾ in light mode) shows the theme you'd
 * *switch to* on click. */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 15px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.theme-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--text);
}
