:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

* {
  box-sizing: border-box;
}

body {
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

/* ---------- Layout ---------- */

.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px 48px;
}

.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.app-header .queue-badge {
  color: var(--text-muted);
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--gridline);
  margin-bottom: 20px;
}

.tab-button {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font: inherit;
  font-weight: 500;
  padding: 10px 4px;
  margin-right: 20px;
  cursor: pointer;
}

.tab-button:hover {
  color: var(--text-primary);
}

.tab-button.active {
  color: var(--text-primary);
  border-bottom-color: var(--series-1);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ---------- Filter row ---------- */

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 20px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-field label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.filter-field select,
.filter-field input[type="date"] {
  font: inherit;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--gridline);
  border-radius: 6px;
  padding: 6px 8px;
  min-width: 120px;
}

/* ---------- Searchable multi-select combobox (multiselect.js) ---------- */

.msel {
  position: relative;
  min-width: 220px;
}

/* Project names are prefixed with their CALCSP-N key (see delivery.js /
   noduedate.js) — wider than the other filters so the key + name fit
   without truncating. */
#flt-project,
#ndd-project {
  min-width: 340px;
}

.msel-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font: inherit;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--gridline);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}

.msel-trigger:hover {
  border-color: var(--baseline);
}

.msel-trigger-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.msel-trigger-caret {
  color: var(--text-muted);
  font-size: 11px;
}

.msel-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 20;
  width: max(280px, 100%);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
  padding: 8px;
}

.msel-search {
  width: 100%;
  font: inherit;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--gridline);
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 6px;
}

.msel-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 6px;
}

.msel-action {
  font-size: 12px;
  color: var(--series-1);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.msel-action:hover {
  text-decoration: underline;
}

.msel-list {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.msel-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.msel-option:hover {
  background: var(--page);
}

.msel-option input {
  margin: 0;
}

.msel-empty {
  color: var(--text-muted);
  font-size: 12px;
  padding: 8px 4px;
}

.filter-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid var(--gridline);
  background: var(--surface-1);
  color: var(--text-primary);
  padding: 7px 14px;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--baseline);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #ffffff;
}

.btn-primary:hover {
  filter: brightness(1.05);
}

/* ---------- KPI tiles ---------- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}

.kpi-tile .kpi-label {
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 6px;
}

.kpi-tile .kpi-value {
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: proportional-nums;
}

.kpi-tile .kpi-sub {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}

/* ---------- Chart cards ---------- */

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px 6px;
}

.card h3 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card .chart {
  width: 100%;
  height: 280px;
  transition: height 0.25s ease;
}

.card .chart.tall {
  height: 360px;
}

/* card--expanded: the "grow this chart" toggle (Charts.makeExpandable) —
   spans the whole grid row and gives the chart more vertical room, no
   separate modal/lightbox. */
.card.card--expanded {
  grid-column: 1 / -1;
}

.card.card--expanded .chart {
  height: 520px;
}

.card-expand-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
}

.card-expand-btn:hover {
  color: var(--text-primary);
  background: var(--page);
}

/* ---------- Tables ---------- */

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--gridline);
}

.data-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.data-table th[data-sort] {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.data-table th[data-sort]:hover {
  color: var(--text-primary);
}

.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table tbody tr:hover {
  background: var(--page);
}

.data-table a {
  color: var(--series-1);
  text-decoration: none;
}

.data-table a:hover {
  text-decoration: underline;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.badge.bucket-over {
  color: var(--status-critical);
  background: color-mix(in srgb, var(--status-critical) 14%, transparent);
}

.badge.bucket-under {
  color: var(--status-warning);
  background: color-mix(in srgb, var(--status-warning) 18%, transparent);
}

.badge.bucket-on_target {
  color: var(--status-good);
  background: color-mix(in srgb, var(--status-good) 14%, transparent);
}

/* badge-muted: the basis NOT selected by the Estimation tab's real/ideal
   filter — still shown, but de-emphasized to gray so color only ever
   means the chosen basis (see estimation.js's issueCard). */
.badge.badge-muted {
  color: var(--text-muted);
  background: var(--page);
}

.badge.badge-muted::before {
  background: var(--text-muted);
}

/* Time in Status table's "Тип" column — config.workflow_status.category
   (see config.StatusCategory), same dot-badge component as the
   Estimation tab's over/under/on_target. */
.badge.category-active {
  color: var(--series-1);
  background: color-mix(in srgb, var(--series-1) 14%, transparent);
}

.badge.category-waiting {
  color: var(--status-warning);
  background: color-mix(in srgb, var(--status-warning) 18%, transparent);
}

.badge.category-done {
  color: var(--status-good);
  background: color-mix(in srgb, var(--status-good) 14%, transparent);
}

.badge.category-backlog {
  color: var(--text-muted);
  background: var(--page);
}

/* Issues tab's per-row On Time verdict (see issues.js's onTimeState) —
   green/yellow/red, same token set as the badges above. */
.badge.ontime-good {
  color: var(--status-good);
  background: color-mix(in srgb, var(--status-good) 14%, transparent);
}

.badge.ontime-warning {
  color: var(--status-warning);
  background: color-mix(in srgb, var(--status-warning) 18%, transparent);
}

.badge.ontime-bad {
  color: var(--status-critical);
  background: color-mix(in srgb, var(--status-critical) 14%, transparent);
}

/* ---------- Estimation tab ---------- */

.estimation-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 20px;
}

.estimation-form input[type="text"],
.estimation-form input[type="date"],
.estimation-form select {
  font: inherit;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--gridline);
  border-radius: 6px;
  padding: 6px 8px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 7px;
}

.issue-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 10px;
}

/* Accent border in the selected basis's verdict color — the card-level
   echo of its primary badge (see badge.bucket-* above and the real/ideal
   filter in estimation.js). */
.issue-card.accent-over {
  border-left-color: var(--status-critical);
}

.issue-card.accent-under {
  border-left-color: var(--status-warning);
}

.issue-card.accent-on_target {
  border-left-color: var(--status-good);
}

.issue-card .issue-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.issue-card .issue-key {
  font-weight: 600;
  color: var(--series-1);
}

.issue-card .issue-summary {
  color: var(--text-secondary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.issue-card .issue-detail {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--gridline);
}

.issue-card.expanded .issue-detail {
  display: block;
}

.issue-card .warning {
  color: var(--status-warning);
  font-size: 12px;
  margin-top: 4px;
}

.skipped-list {
  color: var(--text-muted);
  font-size: 12px;
}

/* ---------- Settings tab ---------- */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.job-card .job-name {
  font-weight: 600;
  margin-bottom: 8px;
}

.job-card .job-meta {
  color: var(--text-secondary);
  font-size: 12px;
  margin: 2px 0;
}

.job-card .job-meta.error {
  color: var(--status-critical);
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.status-dot.running {
  background: var(--status-warning);
}

.status-dot.idle {
  background: var(--status-good);
}

.empty-state {
  color: var(--text-muted);
  padding: 24px 0;
  text-align: center;
}

/* Standalone error line outside a .job-card (see .job-card .job-meta.error
   for the job-status variant) — e.g. the Time in Status per-issue search. */
.inline-error {
  color: var(--status-critical);
  font-size: 13px;
  margin: 4px 0 12px;
}
