/* ============================================================
   SiamServe CFO Command Center — Zen Minimal Design System
   ============================================================ */
:root {
  --bg: #F7F6F2;
  --surface: #FFFFFF;
  --surface-2: #FBFAF7;
  --ink: #1C1C1A;
  --ink-2: #55554F;
  --ink-3: #8B8B82;
  --line: #E6E4DC;
  --accent: #0E6B5C;        /* deep zen teal */
  --accent-soft: #E3EFEC;
  --gold: #B08D42;
  --good: #2E7D5B;
  --warn: #C98A2B;
  --bad: #B4452F;
  --info: #3D6B9E;
  --shadow: 0 1px 2px rgba(28,28,26,.04), 0 8px 24px rgba(28,28,26,.05);
  --radius: 14px;
  --font: 'IBM Plex Sans Thai', 'Noto Sans SC', system-ui, sans-serif;
}
* { margin:0; padding:0; box-sizing:border-box; }
html, body { height:100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4 { font-weight:600; letter-spacing:-0.01em; }
button { font-family: var(--font); cursor:pointer; }

/* ---------- Login ---------- */
#login-screen {
  position:fixed; inset:0; display:flex; align-items:center; justify-content:center;
  background:
    radial-gradient(1200px 600px at 80% -10%, #EDEAE1 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #E7EFEC 0%, transparent 55%),
    var(--bg);
  z-index:1000;
}
.login-card {
  width: 380px; background: var(--surface); border:1px solid var(--line);
  border-radius: 20px; padding: 44px 40px; box-shadow: var(--shadow);
  animation: rise .5s ease;
}
@keyframes rise { from { opacity:0; transform: translateY(14px);} to {opacity:1; transform:none;} }
.login-logo { display:flex; align-items:center; gap:12px; margin-bottom:28px; }
.logo-mark {
  width:42px; height:42px; border-radius:12px; background: var(--accent);
  display:flex; align-items:center; justify-content:center; color:#fff; font-weight:700; font-size:18px;
}
.login-logo .name { font-size:17px; font-weight:600; }
.login-logo .sub { font-size:12px; color: var(--ink-3); }
.login-card h1 { font-size:20px; margin-bottom:6px; }
.login-card .hint { color: var(--ink-3); font-size:12.5px; margin-bottom:24px; }
.field { margin-bottom:16px; }
.field label { display:block; font-size:12px; color: var(--ink-2); margin-bottom:6px; }
.field input {
  width:100%; padding:11px 14px; border:1px solid var(--line); border-radius:10px;
  font-size:14px; font-family:var(--font); background: var(--surface-2); color:var(--ink);
  outline:none; transition: border .15s;
}
.field input:focus { border-color: var(--accent); background:#fff; }
.btn-primary {
  width:100%; padding:12px; background: var(--accent); color:#fff; border:none;
  border-radius:10px; font-size:14px; font-weight:600; margin-top:6px;
  transition: opacity .15s;
}
.btn-primary:hover { opacity:.92; }
.login-error { color: var(--bad); font-size:12.5px; margin-top:12px; min-height:16px; text-align:center; }
.demo-badge {
  margin-top:20px; text-align:center; font-size:11.5px; color:var(--ink-3);
  background:var(--surface-2); border:1px dashed var(--line); border-radius:8px; padding:8px;
}
.login-lang { display:flex; gap:6px; justify-content:center; margin-top:18px; }

/* ---------- App layout ---------- */
#app { display:none; min-height:100vh; }
#app.active { display:flex; }
.sidebar {
  width: 232px; flex-shrink:0; background: var(--surface); border-right:1px solid var(--line);
  padding: 22px 14px; display:flex; flex-direction:column; gap:2px;
  position:sticky; top:0; height:100vh; overflow-y:auto;
}
.sidebar .brand { display:flex; align-items:center; gap:10px; padding:0 10px 18px; }
.sidebar .brand .logo-mark { width:34px; height:34px; font-size:14px; border-radius:10px; }
.sidebar .brand b { font-size:14px; display:block; }
.sidebar .brand span { font-size:10.5px; color:var(--ink-3); }
.nav-section { font-size:10px; text-transform:uppercase; letter-spacing:.12em; color:var(--ink-3); padding:14px 12px 6px; }
.nav-item {
  display:flex; align-items:center; gap:10px; padding:9px 12px; border-radius:9px;
  color: var(--ink-2); font-size:13px; border:none; background:none; width:100%; text-align:left;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight:600; }
.nav-item .ico { width:18px; text-align:center; font-size:14px; }
.sidebar .foot { margin-top:auto; padding:12px; font-size:11px; color:var(--ink-3); }

.main { flex:1; min-width:0; padding: 26px 32px 60px; }
.topbar { display:flex; align-items:center; justify-content:space-between; margin-bottom:22px; gap:14px; flex-wrap:wrap; }
.topbar h2 { font-size:21px; }
.topbar .crumb { font-size:12px; color:var(--ink-3); margin-top:3px; }
.top-actions { display:flex; align-items:center; gap:10px; }
.lang-switch { display:flex; border:1px solid var(--line); border-radius:9px; overflow:hidden; background:var(--surface); }
.lang-switch button {
  border:none; background:none; padding:7px 12px; font-size:12px; color:var(--ink-3); font-weight:600;
}
.lang-switch button.active { background: var(--ink); color:#fff; }
.btn-ghost {
  border:1px solid var(--line); background:var(--surface); border-radius:9px; padding:7px 14px;
  font-size:12.5px; color:var(--ink-2);
}
.btn-ghost:hover { border-color:var(--ink-3); }

/* ---------- Cards & grids ---------- */
.grid { display:grid; gap:16px; }
.kpi-row { grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); }
.card {
  background: var(--surface); border:1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.card h3 { font-size:13.5px; color:var(--ink-2); font-weight:600; margin-bottom:14px; display:flex; justify-content:space-between; align-items:center; gap:8px;}
.kpi .label { font-size:11.5px; color: var(--ink-3); margin-bottom:6px; display:flex; align-items:center; gap:6px;}
.kpi .value { font-size:22px; font-weight:650; letter-spacing:-.02em; }
.kpi .value small { font-size:12px; color:var(--ink-3); font-weight:500; }
.kpi .delta { font-size:11.5px; margin-top:5px; font-weight:600; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); } .delta.flat { color: var(--ink-3); }
.spark { margin-top:8px; height:30px; }

.chart-box { position:relative; }
.chart-box canvas { max-width:100%; }
.h-260 { height:260px; } .h-300 { height:300px; } .h-220 { height:220px; } .h-180 { height:180px; }

.two-col { grid-template-columns: 1fr 1fr; }
.three-col { grid-template-columns: repeat(3, 1fr); }
.span-2 { grid-column: span 2; }
@media (max-width: 1100px) { .two-col, .three-col { grid-template-columns: 1fr; } .span-2 { grid-column: span 1; } }

/* ---------- Tables ---------- */
table.data { width:100%; border-collapse: collapse; font-size:12.5px; }
table.data th {
  text-align:right; font-weight:600; color:var(--ink-3); font-size:11px; text-transform:uppercase;
  letter-spacing:.06em; padding:8px 10px; border-bottom:1px solid var(--line);
}
table.data th:first-child, table.data td:first-child { text-align:left; }
table.data td { padding:8px 10px; text-align:right; border-bottom:1px solid var(--surface-2); }
table.data tr:hover td { background: var(--surface-2); }
table.data td.name { font-weight:600; color:var(--ink); }
table.data tr.total td { border-top:2px solid var(--line); font-weight:700; }
table.data tr.sub td { color:var(--ink-2); }
.pos { color: var(--good); } .neg { color: var(--bad); }

/* ---------- Chips, badges, pills ---------- */
.pill { display:inline-block; padding:3px 10px; border-radius:99px; font-size:11px; font-weight:600; }
.pill.ok { background:#E5F1EA; color:var(--good); }
.pill.low { background:#F7EDDC; color:var(--warn); }
.pill.crit { background:#F6E4DF; color:var(--bad); }
.pill.over { background:#E3EAF4; color:var(--info); }
.pill.neutral { background:var(--surface-2); color:var(--ink-2); border:1px solid var(--line); }

.seg { display:flex; border:1px solid var(--line); border-radius:9px; overflow:hidden; background:var(--surface); width:max-content; }
.seg button { border:none; background:none; padding:7px 14px; font-size:12px; color:var(--ink-3); font-weight:600; }
.seg button.active { background: var(--accent); color:#fff; }

/* ---------- Alerts ---------- */
.alert-item { display:flex; gap:10px; padding:10px 0; border-bottom:1px solid var(--surface-2); font-size:12.5px; align-items:flex-start;}
.alert-item:last-child { border-bottom:none; }
.alert-dot { width:8px; height:8px; border-radius:50%; margin-top:5px; flex-shrink:0; }
.alert-dot.bad { background:var(--bad); } .alert-dot.warn { background:var(--warn); } .alert-dot.info { background:var(--info); } .alert-dot.good { background:var(--good); }
.alert-item .when { color:var(--ink-3); font-size:11px; }

/* ---------- Scenario simulator ---------- */
.sim-layout { display:grid; grid-template-columns: 360px 1fr; gap:16px; }
@media (max-width: 1100px) { .sim-layout { grid-template-columns: 1fr; } }
.slider-row { margin-bottom:18px; }
.slider-row .top { display:flex; justify-content:space-between; font-size:12.5px; margin-bottom:6px; }
.slider-row .top b { color: var(--accent); font-variant-numeric: tabular-nums; }
.slider-row input[type=range] {
  width:100%; accent-color: var(--accent); height:4px;
}
/* ---------- Filter chips (slicers) ---------- */
.chip-row { display:flex; flex-wrap:wrap; gap:8px; }
.chip {
  border:1px solid var(--line); background:var(--surface); border-radius:99px;
  padding:6px 14px; font-size:12px; color:var(--ink-2); font-weight:600; transition:.12s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color:#fff; }

.preset-row { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:18px; }
.preset-row button {
  border:1px solid var(--line); background:var(--surface-2); border-radius:99px;
  padding:6px 13px; font-size:12px; color:var(--ink-2); font-weight:600; transition:.12s;
}
.preset-row button:hover { border-color:var(--accent); color:var(--accent); }
.sim-score { text-align:center; padding:6px 0 2px; }
.sim-score .score-num { font-size:44px; font-weight:700; letter-spacing:-.03em; }
.sim-score .rank { font-size:13px; font-weight:700; margin-top:2px; }
.sim-score .rank-bar { height:6px; border-radius:99px; background:var(--surface-2); margin:12px 20px 4px; overflow:hidden; }
.sim-score .rank-bar > div { height:100%; border-radius:99px; background:linear-gradient(90deg, var(--bad), var(--warn), var(--good)); transition:width .4s ease; }
.impact-chips { display:grid; grid-template-columns:repeat(auto-fit,minmax(140px,1fr)); gap:10px; }
.impact-chip { background:var(--surface-2); border:1px solid var(--line); border-radius:11px; padding:12px 14px; }
.impact-chip .k { font-size:11px; color:var(--ink-3); }
.impact-chip .v { font-size:17px; font-weight:700; margin-top:3px; font-variant-numeric: tabular-nums;}
.impact-chip .d { font-size:11px; font-weight:600; margin-top:2px; }

/* ---------- Warehouse ---------- */
.wh-layout { display:grid; grid-template-columns: 1fr 330px; gap:16px; }
@media (max-width: 1100px) { .wh-layout { grid-template-columns: 1fr; } }
#wh-canvas-wrap {
  position:relative; border-radius: var(--radius); overflow:hidden; border:1px solid var(--line);
  background: linear-gradient(180deg, #FDFCFA 0%, #F0EEE7 100%); height: 480px;
}
#wh-canvas-wrap canvas { display:block; }
.wh-legend {
  position:absolute; bottom:12px; left:12px; display:flex; gap:12px; background:rgba(255,255,255,.85);
  backdrop-filter: blur(4px); padding:8px 14px; border-radius:99px; font-size:11px; border:1px solid var(--line);
}
.wh-legend span { display:flex; align-items:center; gap:5px; }
.wh-legend i { width:10px; height:10px; border-radius:3px; display:inline-block; }
.wh-tip {
  position:absolute; top:12px; right:12px; font-size:11px; color:var(--ink-3);
  background:rgba(255,255,255,.85); padding:6px 12px; border-radius:99px; border:1px solid var(--line);
}
#wh-detail { min-height:120px; }
.forecast-card { border:1px solid var(--line); border-radius:11px; padding:12px 14px; margin-bottom:10px; background:var(--surface-2); }
.forecast-card .head { display:flex; justify-content:space-between; align-items:center; margin-bottom:8px; }
.forecast-card .sku { font-weight:700; font-size:12.5px; }
.forecast-card .days { display:flex; gap:8px; }
.fc-day { flex:1; text-align:center; border-radius:8px; padding:7px 4px; font-size:11px; }
.fc-day b { display:block; font-size:13px; }
.fc-day.ok { background:#E5F1EA; color:var(--good);} .fc-day.low { background:#F7EDDC; color:var(--warn);} .fc-day.crit { background:#F6E4DF; color:var(--bad);} .fc-day.over { background:#E3EAF4; color:var(--info);}
.wh-meta { font-size:11px; color:var(--ink-3); display:flex; justify-content:space-between; margin-top:4px; }

/* ---------- Gauge / misc ---------- */
.gauge-wrap { position:relative; }
.gauge-center { position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:flex-end; padding-bottom:14%; pointer-events:none; }
.gauge-center .num { font-size:30px; font-weight:700; }
.gauge-center .cap { font-size:11px; color:var(--ink-3); }
.footnote { font-size:11px; color:var(--ink-3); margin-top:10px; line-height:1.5; }
.section-gap { margin-top:16px; }
.mb16 { margin-bottom:16px; }

::-webkit-scrollbar { width:9px; height:9px; }
::-webkit-scrollbar-thumb { background:var(--line); border-radius:99px; }
::-webkit-scrollbar-track { background:transparent; }
