:root {
  color-scheme: dark;
  --bg: #0c0c0e;
  --bg-elev: #151518;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --gold: #c5b358;
  --border: rgba(207, 207, 212, 0.14);
  --danger: #e11d48;
  --ok: #34d399;
  --font: "Montserrat", system-ui, sans-serif;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

a { color: var(--gold); text-decoration: none; }

h1 {
  margin: 0 0 14px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-wrap: balance;
}

h2 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-wrap: balance;
}

h3 {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 600;
}

.admin-wrap {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  padding: 18px max(24px, env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}

.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.admin-nav > a,
.nav-project {
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}

.admin-nav > a.active,
.admin-nav > a:hover {
  background: var(--bg-elev);
  color: var(--text);
}

.nav-project {
  color: var(--text);
  font-weight: 600;
}

.admin-nav .right {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

.nav-logout { margin: 0; }

.nav-logout button {
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.nav-logout button:hover {
  background: var(--bg-elev);
  color: var(--text);
}

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
}

.seg a {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 13px;
}

.seg a.is-on,
.seg a[aria-current="page"] {
  background: var(--gold);
  color: #141414;
  font-weight: 600;
}

.seg a:hover { color: var(--text); }
.seg a.is-on:hover,
.seg a[aria-current="page"]:hover { color: #141414; }

.card,
.panel,
.composer,
.person,
.quiet-row {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}

.filters,
.sheet-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 12px;
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.sheet-tools .filters,
.sheet-tools .collect {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 12px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
}

.sheet-tools .collect { margin-left: auto; }

label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.filters label,
.fields label,
.person > label,
.login-form label,
.collect label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.input,
.select,
input,
select {
  width: 100%;
  min-height: 40px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0f0f12;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 400;
}

.filters input,
.filters select,
.sheet-tools input,
.sheet-tools select {
  width: auto;
  min-width: 8.5rem;
}

.btn,
.primary,
.collect button,
.composer button,
.person button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--gold);
  color: #111;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.btn-ghost,
.collect .btn-ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-weight: 600;
}

.btn:disabled,
button:disabled { opacity: 0.45; cursor: default; }

.fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.checks {
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  gap: 8px 14px;
  min-inline-size: 0;
  margin: 14px 0 0;
  padding: 0;
  border: 0;
}

.checks legend {
  padding: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.checks-row {
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  gap: 8px 16px;
}

.check {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  cursor: pointer;
}

.check input {
  width: 18px;
  height: 18px;
  min-height: 0;
  flex: none;
  padding: 0;
  accent-color: var(--gold);
}

.composer .primary,
.person .primary,
.person > label { margin-top: 14px; }

.staff > h2 {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.04em;
}

.table-wrap { overflow-x: auto; }

.evaluate-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(14rem, 20rem);
  gap: 16px;
  align-items: start;
}

.verdict {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.verdict h3 {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.verdict p { margin: 0; }

@media (max-width: 720px) {
  .evaluate-split { grid-template-columns: minmax(0, 1fr); }
}

table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

thead th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

tbody th { font-weight: 600; }

.table-wrap th:first-child,
.table-wrap td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg-elev);
}

td span[data-source] { display: block; }
td span[data-source] + span[data-source] { margin-top: 4px; }

.empty,
.hint,
.meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

main > .empty {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elev);
}

.panel > .empty { padding-top: 4px; }

.flash {
  padding: 10px 12px;
  border-radius: 10px;
  margin: 0 0 12px;
}

.flash-ok { background: rgba(52, 211, 153, 0.12); color: var(--ok); }
.flash-err,
.alert,
.error {
  background: rgba(225, 29, 72, 0.12);
  color: #fda4af;
}

dl {
  display: grid;
  grid-template-columns: minmax(8rem, 14rem) minmax(0, 1fr);
  margin: 0 0 12px;
}

dt,
dd {
  margin: 0;
  padding: 8px 8px 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

dt { color: var(--muted); }
dd { font-variant-numeric: tabular-nums; }

.panel ul { margin: 0; padding-left: 1.15rem; }
.panel li + li { margin-top: 4px; }

.chart-row {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.15fr);
  gap: 12px;
  align-items: stretch;
  margin: 0 0 16px;
}

.chart {
  display: flex;
  flex-direction: column;
  margin: 0;
  min-width: 0;
  height: 100%;
  padding: 12px 12px 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
}

.chart figcaption {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.chart { width: 100%; max-width: none; }
.chart .plot { display: block; width: 100%; height: auto; }
#demand-trend .plot { flex: 1 1 auto; min-height: 0; }
#demand-trend .legend { margin-top: auto; }

.chart [data-tip] { cursor: crosshair; }

.chart-tip {
  position: fixed;
  z-index: 40;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elev);
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
  white-space: nowrap;
}

@media (max-width: 960px) {
  .chart-row { grid-template-columns: 1fr; }
}

.picks-fold {
  margin: 0 0 16px;
}

.picks-fold:not([open]) > .picks { display: none; }

.picks-fold > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.picks-fold > summary::-webkit-details-marker { display: none; }

.picks-fold > summary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.picks-fold > summary::after {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
}

.picks-fold[open] > summary { margin-bottom: 12px; }

.picks-fold[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }

.picks-summary {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picks {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
}

.pick {
  padding: 10px 12px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
}

.pick-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.pick-actions {
  display: flex;
  flex: none;
  gap: 6px;
}

.pick-head .btn { min-height: 32px; padding: 4px 10px; font-size: 12px; }

.pick-count {
  margin-left: 6px;
  color: var(--muted);
  font-weight: 500;
}

.pick-list {
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  gap: 2px 16px;
  max-height: none;
  overflow: visible;
}

.pick-models {
  display: block;
  max-height: 232px;
  overflow: auto;
  scrollbar-gutter: stable;
}

.pick-group { margin: 0 0 10px; }
.pick-group-title {
  margin: 2px 0 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.pick-group-grid {
  display: flex;
  flex-wrap: wrap;
  column-gap: 18px;
}
.pick-group-grid .check { width: 188px; }

.pick-list .check {
  display: flex;
  align-items: center;
  gap: 8px;
  width: auto;
  min-height: 32px;
  margin: 0;
  padding: 2px 0;
}

.pick-models .check { width: 100%; min-width: 0; }
.pick-models .pick-group-grid .check { width: 188px; flex: none; }
.pick-list .check-text { line-height: 1.3; }
.pick-models .check-text { min-width: 0; }
.pick-list .check[hidden],
.pick-group[hidden] { display: none; }

#model-find { margin-bottom: 8px; }

.demand-table { width: max-content; min-width: 100%; }

.demand-table th,
.demand-table td { vertical-align: middle; }

.demand-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-elev);
}

.demand-table thead th:first-child { z-index: 3; }

th.num,
td.num,
td[data-field="demand"] { text-align: right; }

th.num .bi-th-sort { margin-left: auto; }

.bi-th-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: inherit;
}

.bi-th-sort::after {
  content: "↕";
  opacity: 0.45;
  font-size: 0.85em;
}

.bi-th-sort[aria-sort="descending"]::after { content: "↓"; opacity: 0.9; }
.bi-th-sort[aria-sort="ascending"]::after { content: "↑"; opacity: 0.9; }

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 14px 0 0;
}

.pager-link,
.pager-gap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.pager-link.is-current { border-color: var(--gold); color: var(--gold); }
.pager-link.is-disabled { opacity: 0.35; pointer-events: none; }
.pager-gap { border: 0; min-width: 16px; cursor: default; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 12px;
}

.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend span {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex: none;
}

.login-card {
  width: 100%;
  max-width: 420px;
  margin: 10vh auto;
}

.login-form { display: grid; gap: 12px; }
.login-form .btn { width: 100%; min-height: 44px; }
.iam-auth .login-card .flash { margin: 12px 0 0; }

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

@media (max-width: 720px) {
  .admin-nav > a,
  .nav-project,
  .nav-logout button {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }

  .admin-nav .right { flex: 1 0 100%; margin-left: 0; }
  .fields { grid-template-columns: 1fr; }
  .input, select, input { font-size: 16px; }
  .login-card { margin: 6vh auto; }
}
