/* ============================================================
   Tanaw Demand Planning — styles
   Colors are defined once as variables; dark mode swaps them.
   ============================================================ */

:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #1c5cab;
  --accent-hover: #184f95;
  --accent-soft: #e4eefb;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #0f8a6c;
  --band: rgba(235, 104, 52, 0.14);
  --grid: #e8e7e2;
  --limit: #7a7974;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-text: #b42c2c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2e2e2b;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #93928b;
    --accent: #5598e7;
    --accent-hover: #6da7ec;
    --accent-soft: #1c2a3d;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #34b893;
    --band: rgba(217, 89, 38, 0.2);
    --grid: #2a2a28;
    --limit: #93928b;
    --good-text: #4cc94c;
    --critical-text: #e66767;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 18px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 620; display: flex; align-items: center; gap: 10px; }

.muted { color: var(--text-2); }
.hidden { display: none !important; }

/* ---------- Header ---------- */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 48%, var(--surface) 48% 56%, transparent 56%),
    var(--accent);
}
.tagline { margin: 0; font-size: 13px; color: var(--text-2); }
.privacy-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 550;
  color: var(--good-text);
  background: color-mix(in srgb, var(--good) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--good) 30%, transparent);
  padding: 5px 10px; border-radius: 999px;
}
.privacy-badge svg { width: 14px; height: 14px; fill: currentColor; }

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
#results-section { display: flex; flex-direction: column; gap: 20px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}
.card-head { margin-bottom: 16px; }
.card-head p { margin: 4px 0 0; font-size: 14px; }
.card-head p.item-name { margin-top: 8px; font-size: 16px; font-weight: 600; color: var(--text); }
.card-head.row {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; flex-wrap: wrap;
}
.step {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 13px; font-weight: 700;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Upload ---------- */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop-zone:hover, .drop-zone:focus-visible, .drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}
.drop-title { margin: 0 0 4px; font-weight: 600; }
.drop-zone .muted { margin: 0; font-size: 14px; }
.link-like { color: var(--accent); text-decoration: underline; }
.load-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- Buttons & inputs ---------- */
.btn {
  font: inherit; font-size: 14px; font-weight: 600;
  border-radius: 8px; padding: 8px 16px;
  cursor: pointer; border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 550; color: var(--text-2); }
select, input[type="number"], input[type="text"], input[type="email"], input[type="password"] {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
.controls { display: flex; gap: 12px; flex-wrap: wrap; }
.controls.stacked { margin-bottom: 16px; }
.controls.stacked label { flex: 1 1 140px; }
.controls.stacked input[type="number"] { width: 100%; }
.export-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Sales input ---------- */
.input-form {
  display: grid; gap: 12px; align-items: end;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.input-form .wide { grid-column: span 2; }
.input-form input { width: 100%; }
p.small { font-size: 13px; margin: 8px 0 0; }
#input-table { margin-top: 12px; }
.btn-small { padding: 3px 10px; font-size: 13px; font-weight: 550; }
@media (max-width: 600px) { .input-form .wide { grid-column: auto; } }

/* ---------- Column mapping ---------- */
.mapping-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.mapping-grid .req { color: var(--critical-text); }
.mapping-options { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.field-hint { font-size: 12px; font-weight: 400; color: var(--text-3); }
.card-head p.sales-total { font-size: 15px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.notice {
  padding: 8px 12px; border-radius: 8px; font-size: 13.5px; color: var(--text);
  background: var(--surface-2); border-left: 3px solid var(--warning);
}
.preview { margin-top: 16px; }
.preview summary { cursor: pointer; font-size: 14px; color: var(--accent); font-weight: 550; }
.preview .table-wrap { margin-top: 8px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.table-wrap.compact { margin-top: 16px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 12px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
th { background: var(--surface-2); color: var(--text-2); font-weight: 600; position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
#portfolio-table tbody tr { cursor: pointer; }
#portfolio-table tbody tr:hover { background: var(--surface-2); }
#portfolio-table tbody tr.selected { background: var(--accent-soft); }
#portfolio-table th[data-sort] { cursor: pointer; user-select: none; }
#portfolio-table th[data-sort]:hover { color: var(--text); }
.table-wrap:has(#portfolio-table) { max-height: 380px; overflow-y: auto; }

.pill {
  display: inline-block; min-width: 22px; text-align: center;
  padding: 1px 7px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
}
.pill.cls-A, .pill.cls-X { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.footnote { font-size: 12.5px; color: var(--text-3); margin: 12px 0 0; }

/* ---------- KPIs ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; }
.kpi .label { font-size: 12px; color: var(--text-2); font-weight: 550; }
.kpi .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi .hint { font-size: 12px; color: var(--text-3); }

/* ---------- Charts ---------- */
.chart-block { position: relative; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.key { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 18px; height: 0; }
.swatch.line { border-top: 2px solid; }
.swatch.s1 { border-color: var(--series-1); }
.swatch.s2 { border-color: var(--series-2); }
.swatch.s3 { border-color: var(--series-3); }
.swatch.dashed { border-top-style: dashed; }
.swatch.limit { border-color: var(--limit); border-top-style: dashed; }
.swatch.center { border-color: var(--text-3); border-top-style: dotted; }
.swatch.band { height: 10px; background: var(--band); border-radius: 2px; }

.chart { width: 100%; height: 320px; }
.chart.short { height: 240px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-text { fill: var(--text-3); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .line-actual { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line-plan { fill: none; stroke: var(--series-3); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .line-forecast { fill: none; stroke: var(--series-2); stroke-width: 2; stroke-dasharray: 5 4; stroke-linejoin: round; stroke-linecap: round; }
.chart .band { fill: var(--band); stroke: none; }
.chart .limit-line { stroke: var(--limit); stroke-width: 1.25; stroke-dasharray: 4 4; }
.chart .center-line { stroke: var(--text-3); stroke-width: 1.25; stroke-dasharray: 1.5 3; }
.chart .limit-label { fill: var(--text-2); font-size: 11px; font-family: var(--font); }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .dot-forecast { fill: var(--series-2); stroke: var(--surface); stroke-width: 2; }
.chart .dot-alert { fill: var(--critical); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--text-3); stroke-width: 1; }
.chart .divider { stroke: var(--border); stroke-width: 1; }
.chart .divider-label { fill: var(--text-3); font-size: 11px; font-family: var(--font); }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 8px 10px; font-size: 12.5px; min-width: 140px;
}
.tooltip .tt-title { font-weight: 650; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.tooltip .tt-row span:first-child { color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; }
.tooltip .tt-swatch { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- Signals & safety stock ---------- */
.signals { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.signals li { display: flex; gap: 8px; align-items: flex-start; }
.signals .icon {
  flex: none; width: 18px; height: 18px; border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 800; color: #fff;
}
.signals .ok .icon { background: var(--good); }
.signals .alert .icon { background: var(--critical); }
.signals .warn .icon { background: var(--warning); color: #3a2a00; }

.ss-results { display: grid; grid-template-columns: 1fr auto; gap: 10px 16px; margin: 0; }
.ss-results dt { color: var(--text-2); font-size: 14px; }
.ss-results dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
.ss-results dd.big { font-size: 20px; color: var(--accent); }

.app-footer { text-align: center; font-size: 12.5px; padding: 0 16px 32px; }
.app-footer p { margin: 4px 0; }
.app-footer .credit { color: var(--text-2); }

@media (max-width: 600px) {
  .app-header { padding: 12px 16px; }
  .card { padding: 16px; }
  .controls label { flex: 1 1 100%; }
}

/* ---------- Sign-in screens ---------- */
.header-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.licensed-to { font-size: 13px; color: var(--text-2); }
.auth-screen { max-width: 420px; margin: 48px auto; padding: 0 16px; }
.auth-card form { display: grid; gap: 14px; margin-top: 8px; }
.auth-card input { width: 100%; }
.auth-card h2 { margin-top: 0; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; } /* used with .link-like */
.contact { white-space: pre-line; }

/* ---------- How Tanaw Demand Planning calculates ---------- */
/* The whole section is one dropdown (.methods-toggle); topics inside are dropdowns too */
.methods-toggle > summary { list-style: none; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.methods-toggle > summary::-webkit-details-marker { display: none; }
.methods-toggle > summary::after { /* chevron: points down when closed, up when open */
  content: ""; flex: none; margin-left: auto; margin-right: 6px; width: 10px; height: 10px;
  border-right: 2px solid var(--text-2); border-bottom: 2px solid var(--text-2);
  transform: translateY(-3px) rotate(45deg); transition: transform .15s;
}
.methods-toggle[open] > summary::after { transform: translateY(3px) rotate(-135deg); }
.methods-toggle > summary:hover .methods-title { color: var(--accent); }
.methods-head { display: flex; flex-direction: column; gap: 4px; }
.methods-title { font-size: 18px; font-weight: 650; color: var(--text); }
.methods-intro { font-size: 14px; font-weight: 400; }
.methods-toggle[open] > summary { margin-bottom: 8px; }
.methods-toggle details { border-top: 1px solid var(--border); padding: 4px 0; }
.methods-toggle details:last-of-type { border-bottom: 1px solid var(--border); }
.methods-toggle details summary { cursor: pointer; font-weight: 600; padding: 10px 0; color: var(--text); }
.methods-toggle details summary:hover { color: var(--accent); }
.methods-toggle details[open] { padding-bottom: 14px; }
.methods h3 { font-size: 15px; margin: 18px 0 6px; }
.methods p, .methods li { font-size: 14px; line-height: 1.6; color: var(--text-2); }
.methods li { margin: 4px 0; }
.methods .formula {
  font-family: "Cambria Math", "STIX Two Math", Georgia, "Times New Roman", serif;
  font-size: 16px; line-height: 1.9; color: var(--text);
  background: var(--surface-2); border-radius: 8px; padding: 8px 14px; margin: 8px 0;
  overflow-x: auto;
}
.methods .formula.inline { display: inline-block; padding: 2px 10px; margin: 4px 0; }
.methods .compact { max-width: 640px; margin: 8px 0; }
.methods .refs li { font-size: 13px; }

/* ---------- Printable report (Report button → print → Save as PDF) ---------- */
.report { display: none; }
@media print {
  @page { size: landscape; margin: 12mm; }
  body.printing-report { background: #fff; color: #000; }
  body.printing-report > :not(#report) { display: none !important; }
  body.printing-report .report { display: block; font: 9.5pt/1.4 var(--font); color: #000; }
  .report h1 { font-size: 17pt; margin: 0 0 2pt; }
  .report h2 { font-size: 12pt; margin: 14pt 0 4pt; }
  .report .meta { margin: 0; color: #444; }
  .report .kpi-row { display: flex; gap: 18pt; margin: 10pt 0 4pt; }
  .report .kpi-row div { border-left: 2pt solid #1c5cab; padding-left: 6pt; }
  .report .kpi-row b { display: block; font-size: 13pt; }
  .report .warn { border-left: 2pt solid #b42c2c; padding-left: 6pt; }
  .report table { border-collapse: collapse; width: 100%; font-size: 8pt; font-variant-numeric: tabular-nums; }
  .report th, .report td { border-bottom: 0.5pt solid #bbb; padding: 2pt 4pt; text-align: left; }
  .report th { background: #eee; }
  .report .num { text-align: right; }
  .report tr.total td { font-weight: 700; border-top: 1pt solid #000; }
  .report thead { display: table-header-group; }
  .report tr { break-inside: avoid; }
  .report .notes { margin-top: 12pt; color: #444; font-size: 8pt; break-inside: avoid; }
  .report .notes p { margin: 2pt 0; }
}
