:root {
  --page: #f3f6f8;
  --panel: #ffffff;
  --head: #f7f9fb;
  --line: #ccd7df;
  --line-strong: #aebcc7;
  --text: #111820;
  --muted: #5c6b76;
  --green: #13795b;
  --green-soft: #def7ec;
  --orange: #c74f13;
  --orange-soft: #fff0e8;
  --blue: #0b63ce;
  --blue-soft: #e7f0ff;
  --amber: #8a5a00;
  --amber-soft: #fff3d6;
  --red: #b3261e;
  --red-soft: #ffe5e1;
  --shadow: 0 8px 20px rgba(17, 24, 32, 0.07);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
}

body {
  margin: 0;
  color: var(--text);
  background: var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
select {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 6px 12px;
  align-items: center;
  min-height: 58px;
  padding: 7px 12px 6px;
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand-block {
  display: flex;
  gap: 9px;
  align-items: center;
  min-width: 0;
}

.brand-block > div:last-child {
  display: grid;
  min-width: 0;
}

.brand-block strong {
  font-size: 15px;
  line-height: 1.2;
}

.brand-block span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 680;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mark {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  color: #fff;
  background: var(--green);
  border-radius: 6px;
  font-size: 15px;
  font-weight: 900;
}

.top-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}

.button,
.control,
.compact-control select {
  height: 30px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  font-weight: 820;
  text-decoration: none;
  white-space: nowrap;
}

.button:hover {
  border-color: var(--line-strong);
  background: #f7f9fb;
}

.button.primary,
.nav-button {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: #bcd4ff;
}

.button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.avatar {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: #fff;
  background: var(--blue);
  border-radius: 50%;
  font-weight: 900;
}

.sync-status {
  grid-column: 1 / -1;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-status[data-tone="good"] {
  color: var(--green);
}

.sync-status[data-tone="bad"] {
  color: var(--red);
}

.workspace {
  max-width: 1920px;
  margin: 0 auto;
  padding: 8px;
}

.control-band {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto repeat(2, minmax(120px, 150px)) repeat(5, auto);
  gap: 6px;
  align-items: end;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
}

.control {
  min-width: 0;
  padding: 0 8px;
  font-weight: 760;
}

.search {
  width: 100%;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(48px, 1fr));
  height: 30px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.segmented button {
  min-width: 52px;
  padding: 0 8px;
  color: var(--muted);
  font-weight: 850;
  background: transparent;
  border: 0;
  border-right: 1px solid var(--line);
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  color: #fff;
  background: var(--green);
}

.segmented button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.compact-control {
  display: grid;
  grid-template-columns: auto;
  gap: 2px;
  min-width: 80px;
}

.compact-control span {
  color: var(--muted);
  font-size: 9px;
  font-weight: 850;
  text-transform: uppercase;
}

.compact-control select {
  min-width: 82px;
  padding: 0 7px;
  font-weight: 820;
}

.sort-control select {
  min-width: 96px;
}

.interpretation-band {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 34px;
  padding: 7px 10px;
  color: #29404e;
  background: #edf4f7;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
}

.interpretation-band strong {
  flex: 0 0 auto;
  color: var(--orange);
}

.interpretation-band span {
  font-weight: 690;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 8px 0;
}

.kpi {
  position: relative;
  display: grid;
  min-height: 92px;
  align-content: center;
  padding: 11px 13px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  content: "";
  background: var(--blue);
}

.replenish-kpi::before {
  background: var(--green);
}

.clearance-kpi::before {
  background: var(--orange);
}

.hold-kpi::before {
  background: var(--amber);
}

.kpi-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
}

.kpi strong {
  margin-top: 1px;
  font-size: 27px;
  line-height: 1.05;
}

.kpi small {
  margin-top: 4px;
  color: var(--muted);
  font-weight: 720;
}

.model-band,
.action-board,
.table-tool,
.readiness-band {
  margin-top: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 8px 11px;
  border-bottom: 1px solid var(--line);
}

.section-heading h1,
.section-heading h2,
.queue-head h3 {
  margin: 0;
  line-height: 1.2;
}

.section-heading h1,
.section-heading h2 {
  font-size: 16px;
}

.section-heading p {
  margin: 2px 0 0;
  color: var(--muted);
  font-weight: 680;
}

.section-heading > span,
.model-version {
  color: var(--muted);
  font-weight: 800;
}

.formula-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.formula-grid > div {
  display: grid;
  gap: 3px;
  min-height: 63px;
  align-content: center;
  padding: 8px 11px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.formula-grid > div:nth-child(3n) {
  border-right: 0;
}

.formula-grid > div:nth-last-child(-n + 3) {
  border-bottom: 0;
}

.formula-grid span {
  color: var(--blue);
  font-size: 10px;
  font-weight: 880;
  text-transform: uppercase;
}

.formula-grid strong {
  font-size: 12px;
  line-height: 1.35;
}

.queue-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.queue {
  min-width: 0;
  border-right: 1px solid var(--line);
}

.queue:last-child {
  border-right: 0;
}

.queue-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  padding: 7px 10px;
  background: var(--head);
  border-bottom: 1px solid var(--line);
}

.queue-head h3 {
  font-size: 12px;
}

.queue-head span {
  display: grid;
  min-width: 24px;
  height: 22px;
  place-items: center;
  padding: 0 6px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-weight: 850;
}

.replenish-queue .queue-head {
  color: #0b674d;
  background: var(--green-soft);
}

.clearance-queue .queue-head {
  color: #a13c0a;
  background: var(--orange-soft);
}

.hold-queue .queue-head {
  color: var(--amber);
  background: var(--amber-soft);
}

.queue ol {
  min-height: 188px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.queue li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px 10px;
  min-height: 44px;
  align-content: center;
  padding: 6px 10px;
  border-bottom: 1px solid #e4eaee;
}

.queue li:last-child {
  border-bottom: 0;
}

.queue li.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.queue-code {
  min-width: 0;
  overflow: hidden;
  font-weight: 880;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-value {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  font-weight: 900;
}

.queue-reason {
  min-width: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 680;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-heading {
  min-height: 52px;
}

.table-scroll {
  max-height: 570px;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 1420px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

th,
td {
  height: 34px;
  padding: 5px 7px;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-right: 1px solid #e0e7eb;
  border-bottom: 1px solid #d9e1e6;
}

th:last-child,
td:last-child {
  border-right: 0;
}

th {
  position: sticky;
  top: 0;
  z-index: 4;
  height: 36px;
  color: #364550;
  background: #edf2f5;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

td {
  font-weight: 690;
}

tbody tr:nth-child(even) td {
  background: #fbfcfd;
}

tbody tr:hover td {
  background: #eef6ff;
}

th:nth-child(1) { width: 132px; }
th:nth-child(2) { width: 126px; }
th:nth-child(3) { width: 82px; }
th:nth-child(4) { width: 62px; }
th:nth-child(5),
th:nth-child(6),
th:nth-child(7),
th:nth-child(8),
th:nth-child(9),
th:nth-child(11),
th:nth-child(12) { width: 75px; }
th:nth-child(10) { width: 88px; }
th:nth-child(13) { width: 92px; }
th:nth-child(14) { width: 260px; }
th:nth-child(15) { width: 105px; }

.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.action-badge,
.confidence-badge,
.branch-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 9px;
  font-weight: 900;
  white-space: nowrap;
}

.action-badge.replenish,
.confidence-badge.ready {
  color: #0b674d;
  background: var(--green-soft);
  border-color: #b6e5d5;
}

.action-badge.clearance,
.confidence-badge.provisional {
  color: #a13c0a;
  background: var(--orange-soft);
  border-color: #ffcdb4;
}

.action-badge.hold,
.confidence-badge.monitor {
  color: var(--amber);
  background: var(--amber-soft);
  border-color: #f0d596;
}

.branch-badge {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: #bfd6ff;
}

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

.empty-row td {
  height: 120px;
  color: var(--muted);
  text-align: center;
}

.readiness-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.readiness-grid > div {
  display: grid;
  gap: 3px;
  min-height: 58px;
  align-content: center;
  padding: 8px 10px;
  border-right: 1px solid var(--line);
}

.readiness-grid > div:last-child {
  border-right: 0;
}

.readiness-grid strong {
  font-size: 11px;
}

.readiness-grid span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 760;
}

.readiness-grid .ready strong {
  color: var(--green);
}

.readiness-grid .missing strong {
  color: var(--orange);
}

@media (max-width: 1320px) {
  .control-band {
    grid-template-columns: minmax(180px, 1fr) auto repeat(2, minmax(110px, 1fr)) repeat(3, auto);
  }

  .sort-control {
    grid-column: auto;
  }

  .readiness-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .readiness-grid > div:nth-child(3) {
    border-right: 0;
  }

  .readiness-grid > div:nth-child(-n + 3) {
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 920px) {
  .topbar {
    position: static;
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: flex-start;
    overflow-x: auto;
  }

  .control-band {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }

  .search {
    grid-column: 1 / -1;
  }

  .control,
  .segmented,
  .compact-control select {
    width: 100%;
  }

  .kpi-grid,
  .formula-grid,
  .queue-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .formula-grid > div:nth-child(3n) {
    border-right: 1px solid var(--line);
  }

  .formula-grid > div:nth-child(2n),
  .queue:nth-child(2) {
    border-right: 0;
  }

  .formula-grid > div:nth-last-child(-n + 3) {
    border-bottom: 1px solid var(--line);
  }

  .formula-grid > div:nth-last-child(-n + 2) {
    border-bottom: 0;
  }

  .queue:last-child {
    grid-column: 1 / -1;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 620px) {
  .workspace {
    padding: 6px;
  }

  .brand-block span {
    white-space: normal;
  }

  .interpretation-band,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .kpi-grid,
  .formula-grid,
  .queue-grid,
  .readiness-grid {
    grid-template-columns: 1fr;
  }

  .formula-grid > div,
  .formula-grid > div:nth-child(2n),
  .formula-grid > div:nth-child(3n),
  .queue,
  .queue:nth-child(2),
  .readiness-grid > div,
  .readiness-grid > div:nth-child(3) {
    border-right: 0;
  }

  .formula-grid > div,
  .formula-grid > div:nth-last-child(-n + 2),
  .readiness-grid > div {
    border-bottom: 1px solid var(--line);
  }

  .formula-grid > div:last-child,
  .readiness-grid > div:last-child {
    border-bottom: 0;
  }

  .queue:last-child {
    grid-column: auto;
  }
}

@media print {
  .top-actions,
  .control-band,
  .interpretation-band,
  .export-button {
    display: none !important;
  }

  .topbar {
    position: static;
  }

  .table-scroll {
    max-height: none;
    overflow: visible;
  }
}
