:root {
  --bg: #fffaf1;
  --surface: #ffffff;
  --surface-soft: #fff6ea;
  --ink: #4d4d4d;
  --ink-strong: #3f4247;
  --muted: #7a7d82;
  --line: #ece4d6;
  --accent: #fbb03b;
  --accent-strong: #e59f2d;
  --ok: #2f855a;
  --error: #b42318;
  --radius: 14px;
  --shadow: 0 10px 24px rgba(77, 77, 77, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.backdrop {
  display: none;
}

.shell {
  width: min(1160px, 94vw);
  margin: 0 auto 34px;
  display: grid;
  gap: 14px;
}

.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 40;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand {
  font-family: "Space Grotesk", "Avenir Next", sans-serif;
  font-weight: 700;
  color: var(--ink-strong);
  text-decoration: none;
  letter-spacing: 0.01em;
}

.menu-items {
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-item {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  text-decoration: none;
  font-weight: 600;
  transition: background 120ms ease, border-color 120ms ease;
}

.menu-item:hover {
  border-color: #d8ccb9;
  background: #fffdfa;
}

.menu-item.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink-strong);
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-strong);
  font-weight: 700;
}

h1,
h2,
h3,
summary,
.tab {
  font-family: "Space Grotesk", "Avenir Next", sans-serif;
  color: var(--ink-strong);
}

h1 {
  margin: 4px 0 8px;
  font-size: clamp(1.32rem, 2vw, 1.85rem);
}

h2 {
  margin: 0;
  font-size: 1.02rem;
}

h3 {
  margin: 0;
  font-size: 0.96rem;
}

.sub {
  margin: 0;
  color: var(--muted);
}

.hint {
  margin: 0;
  color: var(--muted);
}

.hero-tools {
  min-width: 300px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.hero-tools label {
  color: var(--muted);
  font-weight: 600;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 700;
  transition: background 120ms ease, border-color 120ms ease;
}

.tab:hover {
  background: #fffdfa;
  border-color: #d8ccb9;
}

.tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink-strong);
}

.flash {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
}

.flash.ok {
  color: var(--ok);
  border-color: rgba(47, 133, 90, 0.28);
}

.flash.error {
  color: var(--error);
  border-color: rgba(180, 35, 24, 0.25);
}

.flash.warn {
  color: #8a5a00;
  border-color: rgba(251, 176, 59, 0.45);
  background: #fff9ef;
}

.pane {
  display: none;
  gap: 14px;
}

.pane.is-active {
  display: grid;
}

.grid {
  display: grid;
  gap: 14px;
}

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

.product-setup-grid {
  grid-template-columns: 1fr;
}

.card {
  display: grid;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

summary {
  cursor: pointer;
  font-weight: 700;
}

.stack {
  display: grid;
  gap: 8px;
}

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

.hero-tools .row select {
  width: auto;
  min-width: 160px;
}

.hidden {
  display: none !important;
}

.loading-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(251, 176, 59, 0.35);
  border-top-color: var(--accent-strong);
  animation: spin 0.8s linear infinite;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}

.readonly-input {
  background: #f7f4ef;
  color: var(--ink-strong);
  cursor: default;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(251, 176, 59, 0.3);
  border-color: var(--accent);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox input {
  width: auto;
}

.btn {
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 13px;
  cursor: pointer;
  font-weight: 700;
  color: var(--ink-strong);
  background: var(--accent);
  transition: background 120ms ease, border-color 120ms ease;
}

.btn:hover {
  background: #ffc165;
  border-color: #ffc165;
}

.btn-secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.btn-secondary:hover {
  background: #fffdfa;
  border-color: #d8ccb9;
}

.btn-compact {
  padding: 7px 10px;
  min-height: 32px;
  border-radius: 9px;
  font-size: 12px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.action-buttons {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.out {
  margin: 0;
  border-radius: 10px;
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 10px;
  min-height: 50px;
  font-size: 12px;
  overflow: auto;
}

.out.large {
  min-height: 250px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
}

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

.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  gap: 2px;
}

.stat .label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat .value {
  font-family: "Space Grotesk", "Avenir Next", sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink-strong);
}

.thumb-cell {
  width: 74px;
}

.thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
}

.thumb-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 700;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

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

td.is-number {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

th.is-number {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

th {
  background: var(--surface-soft);
  color: var(--ink-strong);
  font-weight: 700;
}

.sort-button {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  text-align: left;
}

.products-table .sort-button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
  line-height: 1.1;
}

th.is-number .sort-button {
  justify-content: flex-end;
  text-align: right;
}

.products-table th.is-number .sort-button {
  align-items: flex-end;
}

.products-table .sort-button .th-line {
  display: block;
  white-space: nowrap;
}

.sort-button .sort-indicator {
  min-width: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.sort-button.is-active .sort-indicator {
  color: var(--ink-strong);
}

.cost-calc-blocks {
  display: grid;
  gap: 12px;
}

.cost-calc-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px;
}

.cost-calc-block .table-wrap {
  border-radius: 10px;
}

.cost-calc-block .cost-calc-table th {
  background: #fff;
}

.cost-warnings-box {
  border: 1px solid rgba(251, 176, 59, 0.4);
  border-radius: 10px;
  background: #fff8ec;
  padding: 8px 10px;
}

.cost-warnings-box .hint-list {
  margin: 0;
}

.unassigned-outbound-block {
  margin-top: 12px;
  border: 1px solid rgba(215, 70, 70, 0.3);
  border-radius: 12px;
  background: #fff8f8;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.unassigned-outbound-block h3 {
  margin: 0;
  font-size: 14px;
  color: #7a2a2a;
}

.unassigned-outbound-table td,
.unassigned-outbound-table th {
  font-size: 12px;
}

tfoot .total-row th {
  background: #fffdfa;
  border-top: 2px solid #e4d6bf;
  color: var(--ink-strong);
  font-weight: 700;
}

tbody tr.total-row th,
tbody tr.total-row td {
  background: #fffdfa;
  border-top: 2px solid #e4d6bf;
  font-weight: 700;
}

tbody tr.tone-revenue td,
tbody tr.tone-revenue th {
  background: #eef8ef;
}

tbody tr.tone-cost td,
tbody tr.tone-cost th {
  background: #fff1f1;
}

.combined-total-row {
  background: #ffe8bf;
}

.combined-total-row th,
.combined-total-row td {
  background: #ffe8bf;
  border-top: 2px solid #f4ba57;
  color: var(--ink-strong);
  font-weight: 700;
}

/* Keep total-row background visible in cost-calc tables where th is reset to white. */
.cost-calc-table .combined-total-row th,
.cost-calc-table .combined-total-row td {
  background: #ffe8bf;
  color: var(--ink-strong);
}

.grand-total-gap td {
  padding: 10px 0;
  border-bottom: none;
  background: transparent;
}

.gross-margin-row th,
.gross-margin-row td {
  font-size: 16px;
  font-weight: 700;
}

.gross-margin-row.is-positive th,
.gross-margin-row.is-positive td {
  background: #1f6f3d;
  border-top-color: #1f6f3d;
  color: #fff;
}

.gross-margin-row.is-negative th,
.gross-margin-row.is-negative td {
  background: #b42318;
  border-top-color: #b42318;
  color: #fff;
}

.gross-margin-row.is-neutral th,
.gross-margin-row.is-neutral td {
  background: #fffdfa;
  border-top-color: #e4d6bf;
  color: var(--ink-strong);
}

tbody tr.tx-section-row th {
  background: var(--surface-soft);
  color: var(--ink-strong);
  font-weight: 700;
  border-top: 2px solid var(--line);
}

tbody tr.tx-section-row.tone-revenue th {
  background: #e3f4e3;
}

tbody tr.tx-section-row.tone-cost th {
  background: #fde7e7;
}

tbody tr:hover {
  background: #fffaf2;
}

tbody tr.tx-section-gap td {
  padding: 5px 0;
  border-bottom: none;
  background: transparent;
}

tbody tr.tx-section-gap:hover td {
  background: transparent;
}

tbody tr.tone-revenue:hover td,
tbody tr.tone-revenue:hover th {
  background: #e6f4e6;
}

tbody tr.tone-cost:hover td,
tbody tr.tone-cost:hover th {
  background: #fdeaea;
}

tbody tr.month-close-row-insufficient td,
tbody tr.month-close-row-insufficient th {
  background: #fff1f1;
}

tbody tr.month-close-row-insufficient:hover td,
tbody tr.month-close-row-insufficient:hover th {
  background: #ffe6e6;
}

#byTypeTable th:nth-child(3),
#byTypeTable th:nth-child(4),
#byTypeTable td:nth-child(3),
#byTypeTable td:nth-child(4) {
  font-size: 12px;
}

tbody tr.tx-correction-row td {
  background: #fffdf8;
}

.tx-correction-label {
  padding-left: 22px;
  color: var(--muted);
}

tbody tr.tx-row-clickable td {
  cursor: pointer;
}

#suppliersTable tr.is-selected td {
  background: #fff6e9;
}

.tx-type-clickable {
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: rgba(251, 176, 59, 0.6);
  text-underline-offset: 2px;
}

tbody tr.order-group-start td {
  border-top: 2px solid #e4d6bf;
}

tbody tr.order-group-child td:nth-child(-n + 3) {
  color: #b3a998;
}

.type-breakdown {
  display: inline-block;
  min-width: 260px;
}

.type-breakdown summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.type-breakdown summary::-webkit-details-marker {
  display: none;
}

.type-breakdown summary::before {
  content: ">";
  color: var(--muted);
  display: inline-block;
  width: 10px;
  transition: transform 120ms ease;
}

.type-breakdown[open] summary::before {
  transform: rotate(90deg);
}

.type-breakdown-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.type-breakdown-lines {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  display: grid;
  gap: 3px;
  border-left: 2px solid var(--line);
  padding-left: 8px;
}

.type-breakdown-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.orders-list {
  display: grid;
  gap: 10px;
}

.order-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
  display: grid;
  gap: 8px;
}

.product-link {
  color: var(--ink-strong);
  text-decoration: underline;
  text-decoration-color: rgba(251, 176, 59, 0.5);
  text-underline-offset: 2px;
  font-weight: 600;
}

.product-link:hover {
  color: #8a6430;
}

.product-filters-row {
  align-items: center;
  gap: 12px;
}

.product-filters-row input[type="search"] {
  flex: 1 1 320px;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  color: var(--ink);
  font-size: 13px;
}

.checkbox-inline input {
  width: 16px;
  height: 16px;
}

.products-table th.select-col,
.products-table td.select-cell {
  width: 56px;
  text-align: center;
}

.products-table th.product-title-col,
.products-table td.product-title-col {
  width: 30%;
  max-width: 360px;
}

.products-table td.product-title-col .product-link {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}

.select-cell-actions {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.select-cell-actions .archive-product-btn {
  width: 24px;
  height: 24px;
  min-height: 24px;
  border-radius: 7px;
}

.procurement-order-toolbar {
  align-items: end;
}

.procurement-order-sections {
  display: grid;
  gap: 14px;
}

.procurement-order-product {
  display: grid;
  gap: 3px;
}

.procurement-order-product-title {
  font-weight: 600;
  color: var(--ink-strong);
}

.procurement-order-table input[type="text"],
.procurement-order-table input[type="search"],
.procurement-order-table input[type="number"] {
  width: 100%;
  min-width: 86px;
}

.procurement-order-table td {
  vertical-align: middle;
}

.sales-hover-wrap {
  position: relative;
  display: inline-flex;
  justify-content: flex-end;
}

.sales-hover-value {
  border-bottom: 1px dashed rgba(77, 77, 77, 0.35);
  cursor: help;
}

.sales-hover-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 12;
  min-width: 244px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 40px rgba(41, 30, 16, 0.12);
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
}

.sales-hover-wrap:hover .sales-hover-panel {
  opacity: 1;
  transform: translateY(0);
}

.sales-hover-meta {
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--muted);
  text-align: left;
}

.table-check {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid #ecd9bb;
  background: #fff9ee;
  cursor: pointer;
}

.table-check input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.table-check span {
  position: relative;
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid #c9bba4;
  border-radius: 5px;
  background: #fff;
  transition: border-color 120ms ease, background 120ms ease;
}

.table-check input:checked + span {
  border-color: #fbb03b;
  background: #fbb03b;
}

.table-check input:checked + span::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 4px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.table-check input:focus-visible + span {
  outline: 2px solid rgba(251, 176, 59, 0.35);
  outline-offset: 2px;
}

.products-table tr.is-selected td {
  background: #fff8ec;
}

.products-table tr.is-selected td.select-cell {
  box-shadow: inset 3px 0 0 #fbb03b;
}

.coverage-cell .coverage-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.coverage-warning-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  color: #cf2f2f;
}

.product-detail-head {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 14px;
  align-items: start;
}

.product-top-stats {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin: 0;
}

.thumb-wrap .thumb {
  width: 64px;
  height: 64px;
}

.chart-shell {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 8px;
}

#salesChart {
  width: 100%;
  height: 320px;
  display: block;
}

.stats.compact {
  margin-top: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.hint-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 980px) {
  .top-nav {
    flex-direction: column;
    align-items: flex-start;
  }

  .menu-items {
    width: 100%;
    flex-wrap: wrap;
  }

  .hero {
    flex-direction: column;
  }

  .hero-tools {
    min-width: 0;
  }

  .grid.two {
    grid-template-columns: 1fr;
  }

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

  .stats.compact {
    grid-template-columns: 1fr;
  }

  .product-detail-head {
    grid-template-columns: 1fr;
  }

  .product-top-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
