:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1a2233;
  --muted: #6b7688;
  --line: #e3e8f0;
  --accent: #2f5bea;
  --shadow: 0 1px 3px rgba(20, 30, 60, .08), 0 6px 20px rgba(20, 30, 60, .05);

  --ok: #1f9d55;      --ok-bg: #e6f6ec;
  --order: #b7791f;   --order-bg: #fdf4e3;
  --critical: #c02b2b;--critical-bg: #fdeaea;
  --over: #2b6cb0;    --over-bg: #e8f1fb;
  --excluded: #718096;--excluded-bg: #edf0f5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 24px 60px; }

header.app { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
header.app h1 { font-size: 22px; margin: 0; letter-spacing: -.2px; }
.header-actions { display: flex; gap: 8px; }
.ghost-btn {
  font: inherit; font-size: 13px; font-weight: 550; cursor: pointer;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--accent);
}
.ghost-btn:hover { border-color: var(--accent); background: #f5f8ff; }
.subtitle { color: var(--muted); margin: 6px 0 4px; font-size: 13px; }
.policy { color: var(--muted); font-size: 12.5px; margin-bottom: 22px; }

/* Modal / popup */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 30, 60, .45);
  display: none; align-items: flex-start; justify-content: center;
  padding: 44px 16px; z-index: 100; overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--card); border-radius: 14px; width: 100%; max-width: 780px;
  box-shadow: 0 12px 48px rgba(20, 30, 60, .28); overflow: hidden;
  display: flex; flex-direction: column; max-height: calc(100vh - 88px);
}
.modal > header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; border-bottom: 1px solid var(--line);
}
.modal > header h2 { margin: 0; font-size: 17px; }
.modal-close {
  border: none; background: transparent; font-size: 26px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 0 4px; border-radius: 6px;
}
.modal-close:hover { color: var(--ink); background: var(--bg); }
.modal-body { padding: 22px; overflow-y: auto; }

.guide-h { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 4px 0 12px; }
.guide-h + .guide-h, .guide-section + .guide-section { margin-top: 30px; }
.guide-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.guide-table th, .guide-table td { text-align: left; }
.guide-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 0 12px 8px 0; }
.guide-table td { vertical-align: top; padding: 10px 12px 10px 0; border-top: 1px solid var(--line); border-bottom: none; font-size: 13px; white-space: normal; word-break: break-word; }
.guide-table th:first-child, .guide-table td:first-child { width: 116px; white-space: nowrap; }
.guide-table th:last-child, .guide-table td:last-child { width: 176px; }
.guide-table .rule { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.glossary { display: grid; gap: 14px; }
.glossary .term { font-weight: 650; font-size: 13.5px; }
.glossary .def { color: var(--ink); font-size: 13px; margin-top: 1px; }
.glossary .def em { color: var(--muted); font-style: normal; }

/* KPI cards */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .num { font-size: 28px; font-weight: 650; letter-spacing: -.5px; }
.kpi .lbl { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.kpi.alert .num { color: var(--critical); }
.kpi.warn .num { color: var(--order); }

/* Controls */
.controls { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.controls label { color: var(--muted); font-size: 12.5px; margin-right: 4px; }
.controls select {
  font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--ink);
}

/* Table */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: right; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: 12px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
thead th.l { text-align: left; }
tbody td { padding: 12px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
tbody td.l { text-align: left; }
tbody tr.plannable { cursor: pointer; }
tbody tr.plannable:hover { background: #f8faff; }
tbody tr:last-child td { border-bottom: none; }
.sku-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--muted); }
.sku-name { font-weight: 550; }
.num-strong { font-weight: 650; }
.dim { color: var(--muted); }

/* Status pills */
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.ok { color: var(--ok); background: var(--ok-bg); }
.pill.order-now { color: var(--order); background: var(--order-bg); }
.pill.critical { color: var(--critical); background: var(--critical-bg); }
.pill.overstocked { color: var(--over); background: var(--over-bg); }
.pill.excluded, .pill.no-demand { color: var(--excluded); background: var(--excluded-bg); }

/* Detail drawer */
tr.detail-row td { padding: 0; background: #fbfcfe; }
.detail { padding: 20px 22px; display: grid; grid-template-columns: minmax(280px, 1fr) minmax(360px, 1.3fr); gap: 26px; }
.detail h3 { margin: 0 0 12px; font-size: 14px; }
.steps { display: grid; gap: 9px; }
.step { display: grid; grid-template-columns: 92px 1fr; gap: 12px; align-items: baseline; }
.step .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.step .v { font-size: 13.5px; }
.step .v b { font-weight: 650; }
.decision { margin-top: 6px; padding: 10px 12px; border-radius: 8px; font-weight: 600; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: 18px; margin-top: 8px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.chart-legend .swatch { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.chart-note { color: var(--muted); font-size: 12px; margin-top: 10px; }

footer { color: var(--muted); font-size: 12px; margin-top: 24px; text-align: center; }

@media (max-width: 820px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .detail { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
