:root {
  --bg: #f6f1e8;
  --paper: #fffdf9;
  --ink: #3c322b;
  --muted: #8b7d70;
  --line: #eadfce;
  --clay: #c4654a;
  --clay-dark: #a8513a;
  --sage: #6e8f78;
  --sage-deep: #3f5c4a;
  --sand: #e7d3b0;
  --red: #a14b45;
  --amber: #9a6433;
  --blue: #5d6e86;
  --shadow: 0 10px 28px rgba(92, 64, 42, 0.06);
  --sans: "Segoe UI Variable", "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% -10%, #fffaf3 0%, transparent 55%),
    radial-gradient(700px 360px at 100% 0%, #f4e3d2 0%, transparent 46%),
    var(--bg);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.shell {
  height: 100%;
  display: grid;
  grid-template-columns: 248px 1fr;
  grid-template-rows: auto minmax(0, 1fr);
}
.masthead {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: 12px 28px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.masthead img { height: 46px; width: auto; justify-self: start; }
.masthead img:last-child { justify-self: end; }
.masthead p {
  margin: 0;
  text-align: center;
  font-size: 22px;
  font-weight: 740;
  letter-spacing: 0.03em;
}
.sidebar {
  background: linear-gradient(180deg, #fbf8f2 0%, #f4eee4 100%);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 6px 8px; }
.logo {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(160deg, #d57a60, var(--clay-dark));
  color: #fffaf6;
  display: grid;
  place-items: center;
  font-weight: 750;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 16px rgba(196, 101, 74, 0.28);
}
.brand strong { display: block; font-size: 16px; letter-spacing: 0.08em; font-weight: 750; }
.brand span, .side-note { color: var(--muted); font-size: 12px; }
.sidebar nav { display: flex; flex-direction: column; gap: 6px; }
.nav-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  color: #5c5148;
  background: transparent;
  border: 0;
  border-radius: 12px;
  padding: 11px 12px;
  text-align: left;
}
.nav-btn em { font-style: normal; color: var(--clay); font-weight: 700; }
.nav-btn:hover { background: rgba(255, 253, 249, 0.7); }
.nav-btn.active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(92, 64, 42, 0.07);
}
.side-actions { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.side-note { line-height: 1.5; margin: 0; padding: 0 4px; }

.workspace { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 32px;
  border-bottom: 1px solid transparent;
  background: rgba(246, 241, 232, 0.82);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 3;
}
.topbar h1 { margin: 0; font-size: 22px; font-weight: 680; letter-spacing: -0.02em; }
.search { margin-left: auto; }
.search input {
  width: min(320px, 42vw);
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 999px;
  padding: 11px 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}
.main { overflow: auto; padding: 8px 32px 72px; }

.page-head, .form-actions, .split-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.page-head { margin: 8px 0 18px; }
.page-head h2, .card h2, .card h3 { margin: 0; letter-spacing: -0.02em; }
.page-head h2 { font-size: 26px; font-weight: 680; }
.page-head p, .lead { margin: 8px 0 0; color: var(--muted); max-width: 760px; line-height: 1.55; }
.actions, .form-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.kpis, .flow { display: grid; gap: 14px; margin-bottom: 16px; }
.kpis { grid-template-columns: repeat(5, 1fr); }
.flow { grid-template-columns: repeat(4, 1fr); }
.kpi, .flow-card, .card, .empty, .lock {
  background: var(--paper);
  border: 1px solid rgba(234, 223, 206, 0.9);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.kpi, .flow-card { padding: 16px 18px; text-align: left; color: inherit; transition: transform 0.15s ease, box-shadow 0.15s ease; }
.kpi:hover, .flow-card:hover { transform: translateY(-1px); box-shadow: 0 14px 30px rgba(92, 64, 42, 0.08); }
.kpi span, .flow-card small { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.kpi strong { display: block; font-size: 34px; line-height: 1.1; margin: 8px 0 4px; font-variant-numeric: tabular-nums; color: #2f2823; }
.kpi em, .flow-card em { display: block; color: var(--muted); font-style: normal; font-size: 13px; }
.flow-card { border-top: 3px solid #e7c3b6; }
.flow-card:nth-child(2) { border-top-color: #d7b56d; }
.flow-card:nth-child(3) { border-top-color: var(--sage); }
.flow-card:nth-child(4) { border-top-color: var(--clay); }
.flow-card b { display: block; margin: 8px 0 4px; font-size: 16px; }
.flow-card strong { font-size: 28px; font-variant-numeric: tabular-nums; }

.columns { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 14px; margin-bottom: 14px; }
.card { padding: 18px 20px 20px; margin-bottom: 14px; }
.sec-h { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.num {
  width: 38px;
  height: 38px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: #f8ebe4;
  color: var(--clay-dark);
  font-weight: 750;
  flex: none;
}
.sec-h p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .lbl { font-size: 13px; font-weight: 650; color: #6f6258; }
.req::after { content: " *"; color: var(--clay); }
input, select, textarea {
  width: 100%;
  color: var(--ink);
  background: #fff;
  border: 1px solid #e7dccb;
  border-radius: 12px;
  padding: 11px 12px;
}
textarea { resize: vertical; min-height: 74px; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid #e7b5a6;
  outline-offset: 1px;
  border-color: #e0b2a4;
}
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid #e7dccb;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
  color: #4d433c;
}
.checks input { width: auto; accent-color: var(--clay); }
.split { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.hint, .legend, .note { color: var(--muted); font-size: 13px; line-height: 1.5; }
.note { background: #fbf3e8; border-radius: 12px; padding: 10px 12px; }
.lock { background: #fbf6ee; border-color: #ead9c2; }
.lock p { margin: 6px 0 0; }
.form-error { background: #fbeceb; color: var(--red); border-radius: 12px; padding: 10px 12px; margin: 0 0 12px; }
.avg { font-weight: 700; }

.btn {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--paper);
  color: var(--ink);
}
.btn:hover { background: #fff; }
.btn.primary { background: var(--clay); color: #fffaf6; border-color: var(--clay); }
.btn.primary:hover { background: var(--clay-dark); }
.btn.gold { background: var(--sage); border-color: var(--sage); color: #f7fbf8; font-weight: 700; }
.btn.gold:hover { background: var(--sage-deep); }
.btn.danger { color: var(--red); background: #fff8f6; border-color: #f0d2cc; }
.sidebar .btn.light { background: transparent; color: #5c5148; border-color: #e0d3c2; }
.sidebar .btn.primary { box-shadow: 0 8px 16px rgba(196, 101, 74, 0.22); }
.btn:disabled { opacity: 0.6; cursor: wait; }

.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.b-ok { background: #e5f2e8; color: #3d6a4c; }
.b-no { background: #fbeceb; color: #8d403c; }
.b-wait { background: #f8edd9; color: #8a5a2b; }
.b-go { background: #e7eef6; color: #4d627c; }
.b-muted { background: #f3ece3; color: #6d6258; }

table { width: 100%; border-collapse: collapse; }
.data th, .score th, .pairs-table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #9a8b7c;
  padding: 8px 14px 12px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}
.data td, .score td, .pairs-table td { padding: 14px; border-bottom: 1px solid #f3ebdf; vertical-align: middle; }
.data tr:last-child td { border-bottom: 0; }
.data tr[data-action]:hover td { background: #fbf6ef; }
.score th:first-child, .pairs-table th { width: 28%; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--ink); font-weight: 700; }
.table-wrap { overflow: auto; }
.pairs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; margin: 0; }
.pairs div { padding-bottom: 8px; border-bottom: 1px solid #f3ebdf; }
.pairs dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.pairs dd { margin: 4px 0 0; white-space: pre-wrap; }

.stepper { display: flex; gap: 8px; margin-bottom: 14px; }
.step { flex: 1; min-width: 120px; text-align: left; background: #fff; border: 1px solid #eadfce; border-radius: 16px; padding: 12px; color: var(--ink); }
.step small { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
.step b { display: block; margin-top: 3px; }
.step.current { border: 2px solid var(--clay); background: #fff8f5; }
.step.done { background: #f3f8f4; border-color: #d5e6da; }
.step.wait { background: #fbf6ee; }
.step.out { background: #fbf3f1; }

.bar-row { display: grid; grid-template-columns: 180px 1fr 36px; gap: 10px; align-items: center; width: 100%; background: transparent; border: 0; padding: 6px 0; text-align: left; color: inherit; border-radius: 10px; }
.bar-row:hover { background: #fbf6ef; }
.move { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%; background: transparent; border: 0; border-bottom: 1px solid #f3ebdf; padding: 10px 0; text-align: left; color: inherit; }
.move span, .move em { color: var(--muted); font-style: normal; font-size: 13px; }
.move em { grid-column: 2; grid-row: 1 / span 2; align-self: center; white-space: nowrap; }
.bar { height: 8px; background: #f0e6d8; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #e0b08a, var(--clay)); }
.empty { padding: 36px; text-align: center; }
.empty p { color: var(--muted); }
.toast { position: fixed; right: 20px; bottom: 20px; background: #3f342c; color: #fffaf6; padding: 12px 16px; border-radius: 14px; box-shadow: var(--shadow); z-index: 6; }
.doc-head { border-bottom: 2px solid #f0d2c6; margin-bottom: 16px; padding-bottom: 10px; }
.doc-head h2 { font-size: 20px; margin: 4px 0; }
.doc-head p, .doc-head span { color: var(--muted); font-size: 13px; }
.filters { display: flex; gap: 8px; align-items: center; }
.filters select { width: 220px; }
details.card summary { font-weight: 700; padding: 2px 0 8px; }
details.card summary::-webkit-details-marker { color: var(--clay); }

@media (max-width: 1100px) {
  .kpis, .flow { grid-template-columns: 1fr 1fr; }
  .columns, .grid, .pairs, .split { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; height: auto; }
  .sidebar { position: sticky; top: 0; z-index: 4; }
  .kpis, .flow, .stepper { grid-template-columns: 1fr; display: grid; }
  .main, .topbar { padding-left: 16px; padding-right: 16px; }
}

@media print {
  .sidebar, .topbar, .no-print, .toast, .form-actions { display: none !important; }
  .shell, .workspace, .main { display: block; height: auto; overflow: visible; background: white; }
  .main { padding: 0; }
  .card, .kpi, .flow-card { box-shadow: none; }
  details, details > * { display: block !important; }
}
