/* ═══════════════════════════════════════════════════════════════════════════
   SCG (Thailand corporate) — design tokens + leftmenu app shell.
   Siam Cement Group corporate style: SCG red, bilingual TH/EN, sharp corners,
   hairline borders, calm industrial grid. All components reference these tokens
   — no hardcoded colours elsewhere.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --primary: #E50012;
  --primary-dark: #B30000;
  --accent: #1F3A5F;
  --bg: #FFFFFF;
  --bg-subtle: #F4F5F7;
  --fg: #1A1A1A;
  --muted: #6E7378;
  --border: #D9DCE0;
  --radius: 4px;
  --radius-lg: 6px;
  --radius-sm: 2px;
  --font-family: "Be Vietnam Pro", "Inter", "Helvetica Neue", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-soft: 0 2px 8px rgba(0, 0, 0, 0.04);

  /* status pill tints */
  --ok-bg: #D7F0DD; --ok-fg: #0F5132;
  --warn-bg: #FFEAD6; --warn-fg: #7A3A00;
  --bad-bg: #FCD8D5; --bad-fg: #5F1412;
}

/* Optional dark override (control-room / plant environments). */
[data-theme="dark"] {
  --bg: #14161A; --bg-subtle: #1C1F24; --fg: #ECEDEF;
  --muted: #9AA0A6; --border: #2A2E35; --shadow: 0 2px 8px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  color: var(--fg);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App shell (left sidebar + main) ───────────────────────────────────── */
.app-shell { display: grid; grid-template-columns: 208px 1fr; min-height: 100vh; transition: grid-template-columns 0.18s ease; }
/* Collapsed / compact rail */
.app-shell.collapsed { grid-template-columns: 54px 1fr; }

.sidebar {
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  padding: 14px 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand { display: flex; align-items: center; gap: 9px; padding: 4px 14px 10px; }
.sidebar .brand .logo {
  width: 30px; height: 30px; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; border-radius: 0; font-size: 13px;
}
.sidebar .brand .name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.sidebar .brand .name small { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }

.sidebar .group-label {
  font-size: 10px; color: var(--muted); padding: 10px 16px 3px;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
}
.sidebar .nav-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 16px;
  font-weight: 500; color: var(--fg); cursor: pointer; font-size: 13px;
  border-left: 3px solid transparent; white-space: nowrap;
}
.sidebar .nav-item.active { border-left-width: 3px; }
.sidebar .nav-item .icon svg { width: 16px; height: 16px; }
.sidebar .nav-item:hover { background: var(--bg); text-decoration: none; }
.sidebar .nav-item.active {
  background: var(--bg); color: var(--primary);
  border-left: 4px solid var(--primary); padding-left: 14px; font-weight: 700;
}
.sidebar .nav-item .icon { width: 20px; height: 20px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.sidebar .nav-item .icon svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.sidebar .nav-item .labels { display: flex; flex-direction: column; min-width: 0; }
.sidebar .nav-item .en { font-size: 11px; color: var(--muted); font-weight: 400; margin-top: 1px; }
.sidebar .nav-item.active .en { color: var(--primary); opacity: 0.7; }

/* ── Sidebar header with collapse toggle ───────────────────────────────── */
.sidebar .brand { justify-content: space-between; }
.sidebar .brand-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sidebar .collapse-btn {
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm);
  width: 28px; height: 28px; cursor: pointer; color: var(--muted); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; font-size: 14px; line-height: 1;
}
.sidebar .collapse-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Collapsed rail behaviour ──────────────────────────────────────────── */
.collapsed .sidebar .brand .name,
.collapsed .sidebar .group-label,
.collapsed .sidebar .nav-item .labels,
.collapsed .sidebar .user-card .meta,
.collapsed .sidebar .logout-btn span.txt,
.collapsed .sidebar .lang-switch { display: none; }
.collapsed .sidebar .nav-item { justify-content: center; padding: 11px 0; gap: 0; border-left-width: 3px; }
.collapsed .sidebar .nav-item.active { padding-left: 0; }
.collapsed .sidebar .brand { justify-content: center; padding: 6px 0 14px; }
.collapsed .sidebar .brand-main { justify-content: center; }
.collapsed .sidebar .collapse-btn { display: none; }
.collapsed .sidebar .sidebar-foot { padding: 12px 8px 4px; }
.collapsed .sidebar .user-card { justify-content: center; }
.collapsed .sidebar .logout-btn { padding: 8px 0; }
/* expand handle shown only when collapsed */
.sidebar .expand-btn { display: none; }
.collapsed .sidebar .expand-btn {
  display: flex; align-items: center; justify-content: center; margin: 0 auto 8px;
  width: 32px; height: 28px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); cursor: pointer;
}
.collapsed .sidebar .expand-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Language switcher ─────────────────────────────────────────────────── */
.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.lang-switch a { padding: 5px 10px; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--bg); text-decoration: none; }
.lang-switch a + a { border-left: 1px solid var(--border); }
.lang-switch a.active { background: var(--primary); color: #fff; }
.lang-switch a:hover:not(.active) { color: var(--primary); text-decoration: none; }
.sidebar .lang-switch { margin: 10px 0 4px; }

/* ── Data browser tabs ─────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); padding: 0 24px; flex-wrap: wrap; }
.tabs a { padding: 11px 16px; font-size: 13px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; text-decoration: none; }
.tabs a:hover { color: var(--fg); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.filter-bar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 16px; }
.filter-bar label { font-size: 12px; font-weight: 600; display: block; margin-bottom: 4px; }
.filter-bar select { font: inherit; font-size: 13px; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); }
/* Horizontal scroll contained to the content width — table never overflows the
   page, but scrolls right when it has more columns than fit. */
.table-scroll { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table-scroll .table { border-collapse: separate; border-spacing: 0; }
.table-scroll .table tbody tr:last-child td { border-bottom: none; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.pager .page-size { display: flex; align-items: center; gap: 6px; margin-right: auto; }
.pager .page-size select { font: inherit; font-size: 12px; padding: 4px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); }
.pager a { padding: 5px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--fg); }
.pager a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.pager a.disabled { opacity: 0.4; pointer-events: none; }

/* user profile + logout pinned to bottom */
.sidebar .sidebar-foot { margin-top: auto; padding: 8px 14px 4px; border-top: 1px solid var(--border); }
.sidebar .user-card { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sidebar .user-card .avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex-shrink: 0;
}
.sidebar .user-card .meta { min-width: 0; }
.sidebar .user-card .meta .who { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .user-card .meta .role { font-size: 10px; color: var(--muted); text-transform: capitalize; }
.sidebar .logout-btn {
  width: 100%; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  background: transparent; color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 5px 10px; display: flex; align-items: center; gap: 6px; justify-content: center;
}
.sidebar .logout-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Main column ───────────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.toolbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 22px;
  border-bottom: 3px solid var(--primary); background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.toolbar .title { font-size: 18px; font-weight: 600; }
.toolbar .actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.toolbar .search {
  background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 7px 12px; font-size: 13px; color: var(--fg); min-width: 220px; font-family: inherit;
}
.toolbar .avatar-sm {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600;
}

.content { flex: 1; min-width: 0; }

/* ── Hero (compact) ────────────────────────────────────────────────────── */
.hero { padding: 18px 24px 10px; }
.hero h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.2px; margin: 0; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.hero h1 .en { font-size: 13px; font-weight: 400; color: var(--muted); }
.hero p { font-size: 14px; color: var(--muted); line-height: 1.5; max-width: 680px; margin: 6px 0 0; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  font: inherit; font-size: 14px; font-weight: 600; border-radius: var(--radius-sm);
  padding: 9px 22px; cursor: pointer; border: 1px solid transparent; display: inline-flex;
  align-items: center; gap: 8px; justify-content: center;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--fg); border-color: var(--fg); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn-block { width: 100%; }
.btn:disabled, .btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn-primary:disabled:hover { background: var(--primary); border-color: var(--primary); }

/* ── Stat tiles ────────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; padding: 0 24px 24px; }
.stat {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 16px 18px; box-shadow: var(--shadow-soft);
}
.stat .label { font-size: 12px; color: var(--fg); font-weight: 700; margin-bottom: 6px; }
.stat .label .en { color: var(--muted); font-weight: 400; }
.stat .value { font-family: var(--font-family); font-size: 24px; font-weight: 600; }
.stat .value small { color: var(--primary); font-size: 12px; font-weight: 500; margin-left: 6px; }
.stat .value.mono { font-family: var(--font-mono); }

/* ── Cards & tables ────────────────────────────────────────────────────── */
.card {
  margin: 0 24px 24px; padding: 20px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-soft);
}
.card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card h3 small { color: var(--muted); font-weight: 400; margin-left: auto; font-size: 11px; }
.card-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; }
@media (max-width: 1100px) { .card-grid { grid-template-columns: 1fr; } }

/* Compact, dense tables — the general style across the whole app. */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table thead th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.3px; padding: 6px 8px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); white-space: nowrap;
}
.table tbody td { padding: 5px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-subtle); }
.table .num { font-family: var(--font-mono); text-align: right; font-size: 12px; }
.table .muted { color: var(--muted); }
/* Denser variant for data-heavy browser tables */
.table.dense { font-size: 12px; }
.table.dense thead th { padding: 5px 8px; }
.table.dense tbody td { padding: 4px 8px; }

/* ── Status pills ──────────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: var(--radius-sm); font-size: 11px; font-weight: 600;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); }
.pill.warn { background: var(--warn-bg); color: var(--warn-fg); }
.pill.bad { background: var(--bad-bg); color: var(--bad-fg); }
.pill.muted { background: var(--bg-subtle); color: var(--muted); }

/* ── Footer (tall, dense, dark) ────────────────────────────────────────── */
.foot { background: #1A1A1A; color: #A0A0A0; padding: 24px; font-size: 12px; line-height: 1.7; margin-top: auto; }
.foot .foot-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 24px; max-width: 1100px; }
@media (max-width: 800px) { .foot .foot-grid { grid-template-columns: 1fr; } }
.foot h4 { color: #ECEDEF; font-size: 12px; margin: 0 0 8px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.foot a { color: #A0A0A0; }
.foot a:hover { color: #fff; }
.foot .locations span { margin-right: 10px; }
.foot .subbrands { color: #7C7F84; }
.foot .pdpa { font-size: 11px; margin-top: 14px; padding-top: 14px; border-top: 1px solid #333; color: #7C7F84; max-width: 1100px; }

/* ── Auth (login) screen ───────────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .auth-wrap { grid-template-columns: 1fr; } }
.auth-hero {
  background: linear-gradient(150deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff; padding: 56px 48px; display: flex; flex-direction: column; justify-content: center;
}
@media (max-width: 900px) { .auth-hero { display: none; } }
.auth-hero .logo { width: 56px; height: 56px; background: #fff; color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 22px; margin-bottom: 28px; }
.auth-hero h1 { font-size: 40px; font-weight: 600; line-height: 1.15; margin: 0 0 10px; letter-spacing: -0.3px; }
.auth-hero h1 .th-sub { display: block; font-size: 20px; font-weight: 400; opacity: 0.9; margin-top: 8px; }
.auth-hero p { font-size: 15px; opacity: 0.9; max-width: 420px; line-height: 1.6; }
.auth-hero .meta { margin-top: 40px; font-size: 12px; opacity: 0.8; }

.auth-panel { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--bg); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .heading { font-size: 24px; font-weight: 600; margin: 0 0 4px; }
.auth-card .heading .en { display: block; font-size: 14px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.auth-card .sub { color: var(--muted); font-size: 14px; margin: 0 0 24px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field label .en { color: var(--muted); font-weight: 400; }
.field input {
  width: 100%; font: inherit; font-size: 15px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg);
}
.field input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.field .error { color: var(--bad-fg); font-size: 12px; margin-top: 4px; }

.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 18px; border: 1px solid; }
.alert.error { background: var(--bad-bg); color: var(--bad-fg); border-color: var(--bad-fg); }
.alert.ok { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-fg); }
.alert.info { background: var(--bg-subtle); color: var(--fg); border-color: var(--border); }

.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; margin: 20px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.btn-o365 {
  width: 100%; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 14px; display: flex; align-items: center; justify-content: center; gap: 10px;
}
.btn-o365:hover { border-color: var(--accent); }
.btn-o365 .ms-logo { display: inline-grid; grid-template-columns: 9px 9px; grid-template-rows: 9px 9px; gap: 2px; }
.btn-o365 .ms-logo i { display: block; width: 9px; height: 9px; }
.btn-o365 .ms-logo i:nth-child(1) { background: #F25022; }
.btn-o365 .ms-logo i:nth-child(2) { background: #7FBA00; }
.btn-o365 .ms-logo i:nth-child(3) { background: #00A4EF; }
.btn-o365 .ms-logo i:nth-child(4) { background: #FFB900; }

/* ── Upload module cards ───────────────────────────────────────────────── */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.module-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; box-shadow: var(--shadow-soft); }
.module-card h4 { margin: 0 0 4px; font-size: 14px; font-weight: 700; }
.module-card .freq { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }

/* compact upload bar */
.upload-bar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.upload-bar .fld { display: flex; flex-direction: column; gap: 4px; }
.upload-bar .fld.grow { flex: 1; min-width: 150px; }
.upload-bar .fld.sm { width: 84px; }
.upload-bar .fld.btns { flex-direction: row; gap: 8px; align-items: center; }
.upload-bar label { font-size: 12px; font-weight: 600; }
.upload-bar select, .upload-bar input { font: inherit; font-size: 13px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); width: 100%; }
.module-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 99px; color: var(--fg); }
.chip small { color: var(--muted); }
.chip a { font-weight: 700; text-decoration: none; }

.upload-form { display: flex; flex-direction: column; gap: 14px; max-width: 520px; }
.upload-form select, .upload-form input {
  font: inherit; font-size: 14px; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg); color: var(--fg);
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Dashboard slicer bar ──────────────────────────────────────────────── */
.slicer-bar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; padding: 0 24px 16px; }
.slicer-bar .fld { display: flex; flex-direction: column; gap: 4px; }
.slicer-bar label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.slicer-bar select { font: inherit; font-size: 13px; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); min-width: 120px; }
.slicer-reset { padding: 7px 14px; font-size: 13px; align-self: flex-end; }

/* ── Power BI-style report visuals ─────────────────────────────────────── */
.viz-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; padding: 0 24px 24px; }
.viz-grid .span-2 { grid-column: span 2; }
@media (max-width: 1000px) { .viz-grid { grid-template-columns: 1fr; } .viz-grid .span-2 { grid-column: span 1; } }
.viz {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-soft); padding: 14px 16px; display: flex; flex-direction: column; min-width: 0;
}
.viz h3 { margin: 0 0 10px; font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 8px; text-transform: none; }
.viz h3 small { color: var(--muted); font-weight: 400; margin-left: auto; font-size: 11px; }
.viz .canvas-wrap { position: relative; height: 260px; }
.viz.tall .canvas-wrap { height: 320px; }
.viz.xtall .canvas-wrap { height: 640px; }
.viz-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 90px 0; margin: 0; }

/* Dashboard loss-detail panel (Report Analysis "minus NetCon" by customer & product) */
.loss-tile h3 small a { color: var(--accent); font-weight: 600; text-decoration: none; }
.loss-tile h3 small a:hover { text-decoration: underline; }
.loss-tile .table-scroll.loss-scroll { max-height: 560px; overflow: auto; }
.loss-table thead th { position: sticky; top: 0; z-index: 2; background: linear-gradient(180deg, #24456E 0%, #1F3A5F 100%); color: #fff; white-space: nowrap; }
.loss-table td.val-neg { color: #B71C1C; font-weight: 600; }
.loss-table tbody tr:nth-child(even) { background: var(--bg-subtle, #F4F5F7); }

/* KPI cards — Power BI accent top border */
.stats.kpi .stat { position: relative; border-top: 3px solid var(--primary); }
.stats.kpi .stat:nth-child(2) { border-top-color: var(--accent); }
.stats.kpi .stat:nth-child(3) { border-top-color: #F57C00; }
.stats.kpi .stat:nth-child(4) { border-top-color: #2E7D32; }
.section-label { padding: 6px 24px 12px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }

/* ── Net Con by Zone (Bain-style, single screen) ───────────────────────── */
/* Match the dashboard KPI sizing (.stats.kpi) so cards are symmetric. */
.zone-kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; padding: 0 24px 24px; }
@media (max-width: 900px) { .zone-kpis { grid-template-columns: repeat(2, 1fr); } }
.zone-kpis .stat { padding: 16px 18px; border-top: 3px solid var(--border); }
.zone-kpis .stat .label { font-size: 12px; color: var(--fg); font-weight: 700; margin-bottom: 6px; }
.zone-kpis .stat .value { font-size: 24px; }
.zone-kpis .stat.pos { border-top-color: #2E7D32; }
.zone-kpis .stat.neg { border-top-color: #C62828; }
.zone-kpis .stat.net { border-top-color: var(--primary); }
.zone-kpis .stat .value.pos { color: #2E7D32; }
.zone-kpis .stat .value.neg { color: #C62828; }
.zone-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; padding: 0 24px 16px; align-items: stretch; }
@media (max-width: 1000px) { .zone-grid { grid-template-columns: 1fr; } }
.zone-grid .card { margin: 0; display: flex; flex-direction: column; }
.zone-chart-wrap { position: relative; flex: 1; min-height: 320px; }
.zone-table-wrap { overflow: auto; max-height: 380px; }

/* ── Presentation mode (full-screen slides) ────────────────────────────── */
.dash-actions { display: flex; gap: 8px; margin-left: auto; }
.present-overlay { display: none; position: fixed; inset: 0; z-index: 1000; background: var(--bg); flex-direction: column; }
.present-overlay.on { display: flex; }
.present-stage { flex: 1; min-height: 0; padding: 26px 34px 18px; display: flex; }
.present-stage > * { width: 100%; height: 100%; margin: 0 !important; border: none !important; box-shadow: none !important; display: flex; flex-direction: column; overflow: auto; }
.present-stage > * h3 { font-size: 18px; margin-bottom: 14px; }
.present-stage .canvas-wrap { flex: 1; height: auto !important; min-height: 0; }
.present-stage .stats, .present-stage .stats.kpi { grid-template-columns: repeat(4, 1fr); align-content: center; }
.present-stage .stat .value { font-size: 34px; }
.present-bar { height: 40px; display: flex; align-items: center; gap: 7px; padding: 0 12px; background: #1A1A1A; color: #fff; }
.present-bar .pb-title { font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.present-bar .pb-count { color: #A0A0A0; font-size: 11.5px; white-space: nowrap; }
.present-bar select { font: inherit; font-size: 12px; padding: 3px 7px; border-radius: var(--radius-sm); border: 1px solid #333; background: #14161A; color: #fff; max-width: 220px; height: 28px; }
.present-bar button { font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; padding: 4px 9px; height: 28px; border-radius: var(--radius-sm); border: 1px solid #444; background: #14161A; color: #fff; white-space: nowrap; }
.present-bar button:hover { border-color: var(--primary); }
.present-bar button.exit { background: var(--primary); border-color: var(--primary); }
.present-bar .spacer { margin-left: auto; }

/* ── Print / PDF export ────────────────────────────────────────────────── */
@media print {
  .sidebar, .toolbar, .slicer-bar, .hero, .section-label, .foot, .page-logic,
  .dash-actions, .present-overlay, .pager, .filter-bar, .tabs { display: none !important; }
  .app-shell { grid-template-columns: 1fr !important; display: block !important; }
  .main, .content { display: block !important; }
  .viz, .card, .stats { break-inside: avoid; page-break-inside: avoid; box-shadow: none !important; border: 1px solid #ccc !important; }
  .viz-grid { display: block !important; }
  .viz { margin: 0 0 14px !important; }
  .viz .canvas-wrap, .viz.tall .canvas-wrap, .viz.xtall .canvas-wrap { height: 360px !important; }
  body, .app-shell, .main { background: #fff !important; }
  @page { margin: 12mm; }
}

/* ── Compact health page ───────────────────────────────────────────────── */
.hp-strip { display: flex; align-items: center; gap: 14px; margin: 0 24px 16px; padding: 10px 16px; background: var(--bg); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: var(--radius-sm); box-shadow: var(--shadow-soft); }
.hp-strip.ok { border-left-color: var(--ok-fg); }
.hp-strip.bad { border-left-color: var(--bad-fg); }
.hp-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; padding: 0 24px 16px; }
@media (min-width: 1100px) { .hp-grid { grid-template-columns: repeat(4, 1fr); } }
.hp-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-soft); padding: 12px 14px; }
.hp-card h4 { margin: 0 0 8px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.kv { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.kv .row { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.kv .row > span:first-child { color: var(--muted); white-space: nowrap; }
.kv .row > span:last-child { font-family: var(--font-mono); text-align: right; font-size: 12px; }
.hp-counts { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; padding: 0 24px 16px; }
@media (max-width: 800px) { .hp-counts { grid-template-columns: repeat(2, 1fr); } }
.hp-counts .stat { padding: 12px 14px; }

/* ── Modal dialog ──────────────────────────────────────────────────────── */
dialog.modal { border: none; border-radius: var(--radius-lg); padding: 0; max-width: 560px; width: 92%; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28); color: var(--fg); background: var(--bg); }
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.modal-close:hover { color: var(--primary); }
.modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal-body .field { margin-bottom: 14px; }
.modal-body .field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.modal-body .field input { width: 100%; font: inherit; font-size: 14px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); }
.modal-body .field input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.modal-body .field .error { color: var(--bad-fg); font-size: 12px; margin-top: 4px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); }

/* segmented account-type toggle */
.seg-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; width: 100%; }
.seg-toggle label { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 12px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); background: var(--bg); }
.seg-toggle label + label { border-left: 1px solid var(--border); }
.seg-toggle label.on { background: var(--primary); color: #fff; }
.seg-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg-toggle .ms-dot { width: 12px; height: 12px; display: inline-grid; grid-template-columns: 5px 5px; grid-template-rows: 5px 5px; gap: 1px; }
.ms-dot { width: 12px; height: 12px; display: inline-grid; grid-template-columns: 5px 5px; grid-template-rows: 5px 5px; gap: 1px; vertical-align: middle; }
.ms-dot::before { content: ""; background: #F25022; }
.ms-dot::after { content: ""; background: #7FBA00; }
.seg-toggle label.on .ms-dot::before, .seg-toggle label.on .ms-dot::after { background: rgba(255,255,255,0.85); }

/* ── Summary View source colour-coding ─────────────────────────────────── */
.table td.src-sap, .table th.src-sap { background: #EAF2FB; }   /* SAP — blue */
.table td.src-vc,  .table th.src-vc  { background: #FFF3E0; }   /* VC — amber */
.table td.src-tr,  .table th.src-tr  { background: #E8F5E9; }   /* Transport — green */
.table th.src-sap, .table th.src-vc, .table th.src-tr { font-weight: 700; }
.summary-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.summary-head h3 { margin: 0; }
.src-legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin: 0 0 12px; font-size: 12px; }
.src-legend .chip-src { display: inline-flex; align-items: center; gap: 6px; }
.src-legend .swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--border); }
.src-legend .swatch.sap { background: #EAF2FB; }
.src-legend .swatch.vc { background: #FFF3E0; }
.src-legend .swatch.tr { background: #E8F5E9; }

/* ── Drill-down chips (filters arriving from a chart click) ─────────────── */
.drill-chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 12px; font-size: 12px; }
.drill-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 6px 3px 10px; border: 1px solid var(--accent); border-radius: 999px; background: #EAF2FB; color: var(--accent); }
.drill-chip strong { text-transform: capitalize; font-weight: 600; }
.drill-chip a { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); color: #fff; text-decoration: none; font-size: 12px; line-height: 1; }
.drill-chip a:hover { background: var(--red, #E50012); }

/* ── Report Analysis pivot (Zone → Plant → Customer) ───────────────────── */
/* Compact card: tighter padding than the default .card. */
.report-card { padding: 8px 12px; margin-top: 8px; }
.report-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.report-filter-toggle { white-space: nowrap; }
/* Collapsible top filter panel — hidden state frees the whole card for the table. */
.report-filters { padding-top: 2px; }
.report-card.filters-hidden .report-head { padding-bottom: 0; border-bottom: none; }
.report-card.filters-hidden .report-filters { display: none; }
.report-card.filters-hidden .table-scroll.freeze-head { max-height: calc(100vh - 168px); }
.report-title { display: flex; flex-direction: column; gap: 1px; margin-right: auto; }
.report-title h3 { margin: 0; font-size: 15px; }
.report-title .muted { font-size: 11px; }
/* Slim inline KPI row */
.report-kpis { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.report-kpis .rk { display: flex; flex-direction: column; gap: 0; padding: 3px 10px; background: var(--bg-subtle, #F4F5F7); border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 84px; }
.report-kpis .rk-label { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.report-kpis .rk-val { font-family: var(--font-mono); font-size: 14px; font-weight: 600; }
.report-kpis .rk-val.pos { color: #2E7D32; }
.report-kpis .rk-val.neg-bg { background: #FDECEA; color: #C62828; border-radius: 4px; padding: 0 5px; }
/* Compact dashboard-style slicer row */
.report-slicers { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 10px; padding: 6px 0 0; }
.report-slicers .rs-fld { display: flex; flex-direction: column; gap: 2px; }
.report-slicers .rs-fld label { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.report-slicers select { padding: 5px 8px; min-width: 118px; font-size: 13px; }
.report-slicers .btn.btn-sm { align-self: flex-end; }
.report-slicers .rs-check { display: inline-flex; align-items: center; gap: 6px; align-self: flex-end; padding: 5px 0; font-size: 13px; cursor: pointer; white-space: nowrap; }
.report-slicers .rs-check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.btn.btn-sm { padding: 5px 10px; font-size: 12px; }
.drill-chips.compact { margin: 8px 0 0; }

/* Actions row above the pivot (expand/collapse + export) */
.report-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0 6px; }
.report-actions .ra-left { display: flex; gap: 6px; }

/* Tree expand/collapse carets + indentation */
.table.pivot.tree .pv-caret { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-right: 4px; padding: 0; border: 0; background: transparent; color: var(--accent); font-size: 10px; line-height: 1; cursor: pointer; transition: transform .15s ease; vertical-align: middle; }
.table.pivot.tree tr.pv-group.collapsed .pv-caret { transform: rotate(-90deg); }
.table.pivot.tree .pv-spacer { display: inline-block; width: 20px; }
.table.pivot.tree td.ind1 { padding-left: 24px; }
.table.pivot.tree td.ind2 { padding-left: 44px; }
.table.pivot.tree td.ind3 { padding-left: 64px; }
.table.pivot tr.lvl-prod > td { color: var(--muted, #6E7378); font-style: italic; }
.table.pivot tr.lvl-prod .pv-prod { font-style: italic; }

/* Vertically-scrollable pivot with a frozen, colored header */
.table-scroll.freeze-head { max-height: calc(100vh - 272px); min-height: 220px; overflow: auto; }
.table.pivot thead th {
  position: sticky; top: 0; z-index: 3;
  background: linear-gradient(180deg, #24456E 0%, #1F3A5F 100%);
  color: #fff; font-weight: 600; letter-spacing: .02em;
  padding: 9px 10px; border-bottom: none;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.18);
}
.table.pivot thead th:first-child { border-top-left-radius: 6px; }
.table.pivot thead th:last-child { border-top-right-radius: 6px; }
.table.pivot.compact thead th { padding: 9px 10px; }

/* Pivot table */
.table.pivot td, .table.pivot th { vertical-align: middle; }
.table.pivot.compact td, .table.pivot.compact th { padding: 4px 10px; }
.table.pivot .val-pos { color: #2E7D32; }
/* Negative value highlight — red background cell. */
.table.pivot .neg-bg { background: #FCE4E2; color: #B71C1C; font-weight: 600; }
.table.pivot tr.lvl-zone > td { background: #EAF2FB; font-weight: 600; border-top: 2px solid var(--accent); }
.table.pivot tr.lvl-zone > td.neg-bg { background: #F7D9D6; }
.table.pivot tr.lvl-zone .pv-zone { color: var(--accent); }
.table.pivot tr.lvl-plant > td { background: var(--bg-subtle, #F4F5F7); font-weight: 500; }
.table.pivot tr.lvl-plant > td.neg-bg { background: #F7D9D6; }
.table.pivot tr.lvl-plant .pv-plant { color: #5D4037; }
.table.pivot tr.lvl-cust > td { color: var(--text, #1A1A1A); }
.table.pivot .pv-indent { display: inline-block; color: var(--muted, #9E9E9E); margin-right: 2px; }
.table.pivot .pv-indent2 { width: 20px; }
.table.pivot tfoot tr.lvl-grand > td { background: #1F3A5F; color: #fff; border-top: 2px solid #1F3A5F; }
.table.pivot tfoot tr.lvl-grand > td.neg-bg { background: #B71C1C; color: #fff; }

/* ── Page logic explainer (bottom of each page) ────────────────────────── */
.page-logic { margin: 8px 24px 28px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-subtle); }
.page-logic > summary { cursor: pointer; padding: 12px 16px; font-size: 13px; font-weight: 600; color: var(--accent); list-style: none; user-select: none; }
.page-logic > summary::-webkit-details-marker { display: none; }
.page-logic[open] > summary { border-bottom: 1px solid var(--border); }
.page-logic-body { padding: 8px 16px 14px; }
.page-logic-body .table { font-size: 13px; }
.page-logic-body .table td { white-space: normal; }

.error-page { padding: 80px 24px; text-align: center; }
.error-page .code { font-size: 64px; font-weight: 700; color: var(--primary); }
.error-page h1 { font-size: 24px; font-weight: 600; margin: 8px 0; }
.error-page p { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
