:root {
  --ink: #13283b;
  --navy: #0c2238;
  --blue: #176b87;
  --cyan: #4bb7b2;
  --gold: #d7a94b;
  --muted: #657587;
  --line: #dce5ea;
  --surface: rgba(255, 255, 255, 0.92);
  --bg: #eef3f5;
  --shadow: 0 18px 50px rgba(12, 34, 56, 0.08);
}
/* Keep report pages strictly separated, even when opened directly with file://. */
[hidden] { display: none !important; }
* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(75, 183, 178, .14), transparent 30rem),
    linear-gradient(180deg, #f8faf9 0, var(--bg) 42rem);
  font-family: "Noto Sans Lao", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", sans-serif;
  font-variant-numeric: tabular-nums;
}
button, input { font: inherit; }
.page-shell { width: min(1480px, calc(100% - 40px)); margin: 0 auto; padding: 28px 0 40px; }
.hero {
  min-height: 220px;
  padding: 38px 42px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 30px;
  overflow: hidden;
  color: white;
  border-radius: 28px;
  background:
    linear-gradient(135deg, rgba(12, 34, 56, .98), rgba(23, 107, 135, .9)),
    repeating-linear-gradient(120deg, transparent 0 38px, rgba(255,255,255,.04) 39px 40px);
  box-shadow: var(--shadow);
}
.eyebrow, .section-kicker { margin: 0 0 8px; color: #77d5ce; font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.hero h1 { margin: 0; font-size: clamp(38px, 6vw, 72px); line-height: .98; letter-spacing: -.055em; }
.hero-copy { margin: 16px 0 0; max-width: 640px; color: rgba(255,255,255,.72); font-size: 16px; }
.freshness { min-width: 205px; display: flex; align-items: center; gap: 12px; padding: 16px 18px; border: 1px solid rgba(255,255,255,.16); border-radius: 16px; background: rgba(255,255,255,.08); backdrop-filter: blur(10px); }
.freshness small, .freshness strong { display: block; }
.freshness small { color: rgba(255,255,255,.62); font-size: 12px; }
.freshness strong { margin-top: 3px; font-size: 17px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #6be3a4; box-shadow: 0 0 0 6px rgba(107,227,164,.12); }
.status-dot.snapshot { background: #efbf5b; box-shadow: 0 0 0 6px rgba(239,191,91,.14); }
#sync-status { margin-top: 4px; }
main { margin-top: -22px; position: relative; }
.view-tabs { width: fit-content; margin: 0 0 14px 24px; padding: 5px; display: flex; flex-wrap: wrap; gap: 5px; border: 1px solid rgba(188,205,214,.66); border-radius: 14px; background: rgba(255,255,255,.92); box-shadow: 0 12px 28px rgba(12,34,56,.08); }
.view-tabs button { padding: 10px 22px; color: var(--muted); border: 0; border-radius: 10px; background: transparent; line-height: 1.3; cursor: pointer; }
.view-tabs button.active { color: white; font-weight: 800; background: var(--navy); }
.filter-card, .panel, .kpi { background: var(--surface); border: 1px solid rgba(188,205,214,.66); box-shadow: var(--shadow); backdrop-filter: blur(14px); }
.filter-card { padding: 22px 24px; border-radius: 22px; }
.filter-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; }
.filter-heading strong { display: block; font-size: 19px; }
.filter-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.period-tabs { margin-top: 18px; display: grid; grid-template-columns: repeat(6, minmax(110px, 1fr)); gap: 8px; padding: 6px; border-radius: 14px; background: #edf2f4; }
.period-tabs button { min-height: 52px; padding: 11px 12px; color: #536575; border: 0; border-radius: 10px; background: transparent; line-height: 1.3; cursor: pointer; transition: .2s ease; }
.period-tabs button:hover { color: var(--navy); background: rgba(255,255,255,.7); }
.period-tabs button.active { color: white; font-weight: 700; background: var(--navy); box-shadow: 0 8px 18px rgba(12,34,56,.16); }
.custom-range { margin-top: 14px; display: flex; align-items: end; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: #f8fafb; }
.custom-range[hidden] { display: none; }
.custom-range label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.custom-range input, .search input { padding: 10px 12px; color: var(--ink); border: 1px solid #cad7de; border-radius: 10px; background: white; }
.custom-range button { padding: 11px 18px; color: white; border: 0; border-radius: 10px; background: var(--blue); cursor: pointer; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 18px 0; }
.kpi { min-height: 164px; padding: 23px; display: flex; flex-direction: column; justify-content: space-between; border-radius: 20px; }
.kpi.primary { color: white; border-color: transparent; background: linear-gradient(145deg, #176b87, #0d4d69); }
.kpi.warning { background: linear-gradient(145deg, #fffaf0, #fff4d6); border-color: #f1d998; }
.kpi.danger { background: linear-gradient(145deg, #fff6f4, #ffe7e2); border-color: #f3bbb0; }
.kpi.danger strong { color: #b33b2e; }
.kpi.debt-primary { color: white; border-color: transparent; background: linear-gradient(145deg, #8c3f35, #6d2d28); }
.kpi.debt-primary span, .kpi.debt-primary small { color: rgba(255,255,255,.68); }
.kpi span { color: var(--muted); font-size: 13px; font-weight: 700; }
.kpi.primary span, .kpi.primary small { color: rgba(255,255,255,.65); }
.kpi strong { display: block; margin: 12px 0; font-size: clamp(27px, 3vw, 42px); letter-spacing: -.04em; }
.kpi strong.name-kpi { font-size: clamp(17px, 1.7vw, 24px); line-height: 1.3; }
.kpi small { color: #84919e; }
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel { min-width: 0; padding: 24px; border-radius: 22px; }
.trend-panel, .top-customer-panel { grid-column: 1 / -1; }
.panel-title { margin-bottom: 20px; display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.panel-title h2 { margin: 0; font-size: 20px; letter-spacing: -.02em; }
.panel-title .section-kicker { color: var(--blue); }
.unit { padding: 6px 9px; color: var(--muted); border-radius: 8px; background: #edf3f5; font-size: 11px; font-weight: 800; }
.chart { min-height: 290px; }
.trend-chart { position: relative; cursor: crosshair; }
.trend-svg { width: 100%; height: 290px; overflow: visible; }
.trend-line { fill: none; stroke: var(--blue); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.trend-area { fill: url(#areaFill); opacity: .32; }
.hover-guide { stroke: #8ba1af; stroke-width: 1; stroke-dasharray: 4 4; opacity: 0; pointer-events: none; }
.hover-point { fill: white; stroke: var(--blue); stroke-width: 4; opacity: 0; pointer-events: none; }
.trend-tooltip { position: absolute; z-index: 5; min-width: 170px; padding: 12px 14px; color: white; border-radius: 12px; background: rgba(12,34,56,.95); box-shadow: 0 12px 28px rgba(12,34,56,.25); pointer-events: none; transform: translate(-50%, calc(-100% - 16px)); opacity: 0; transition: opacity .12s ease; }
.trend-tooltip.visible { opacity: 1; }
.trend-tooltip strong, .trend-tooltip span { display: block; }
.trend-tooltip strong { font-size: 14px; }
.trend-tooltip span { margin-top: 4px; color: rgba(255,255,255,.72); font-size: 11px; }
.grid-line { stroke: #e4eaee; stroke-width: 1; }
.axis-label { fill: #7d8b98; font-size: 10px; }
.rank-list { display: grid; gap: 15px; }
.rank-row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(120px, 2.2fr) auto; align-items: center; gap: 14px; }
.rank-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 650; }
.bar-track { height: 9px; overflow: hidden; border-radius: 999px; background: #e8eef1; }
.bar-fill { height: 100%; min-width: 3px; border-radius: inherit; background: linear-gradient(90deg, var(--blue), var(--cyan)); }
.rank-value { min-width: 105px; text-align: right; color: #334b5f; font-size: 12px; font-weight: 800; }
.customer-rank { grid-template-columns: 1fr 1fr; column-gap: 42px; }
.customer-rank .rank-row { grid-template-columns: 28px minmax(110px, 1fr) minmax(90px, 1.3fr) auto; }
.rank-number { width: 26px; height: 26px; display: grid; place-items: center; color: var(--blue); border-radius: 8px; background: #e9f4f5; font-size: 11px; font-weight: 900; }
.customer-table-panel, .product-table-panel { margin-top: 18px; }
.stock-heading { display: flex; justify-content: space-between; align-items: end; gap: 30px; }
.stock-heading h2 { margin: 0; font-size: 28px; }
.stock-heading p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.stock-filters { display: flex; align-items: end; gap: 10px; }
.stock-filters label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
.stock-filters input, .stock-filters select { min-height: 41px; padding: 9px 11px; color: var(--ink); border: 1px solid #cad7de; border-radius: 10px; background: white; }
.stock-filters input { width: 240px; }
.stock-kpis { margin-top: 18px; }
.stock-table-panel { margin-top: 18px; }
.receivable-heading { display: flex; justify-content: space-between; align-items: end; gap: 30px; }
.receivable-heading h2 { margin: 0; font-size: 28px; }
.receivable-heading p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.receivable-filters { display: flex; align-items: end; gap: 10px; }
.receivable-filters label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
.receivable-filters input, .receivable-filters select { min-height: 41px; padding: 9px 11px; color: var(--ink); border: 1px solid #cad7de; border-radius: 10px; background: white; }
.receivable-filters input { width: 250px; }
.receivable-customer-panel, .receipt-detail-panel { margin-top: 18px; }
.receivable-customer-table { min-width: 760px; }
.receivable-customer-table td:nth-child(n+2), .receivable-customer-table th:nth-child(n+2) { text-align: right; }
.receivable-customer-table th:nth-child(n+2) .sort-button { justify-content: flex-end; }
.receipt-detail-table { min-width: 1520px; }
.receipt-detail-table td:nth-child(1), .receipt-detail-table td:nth-child(2), .receipt-detail-table td:nth-child(3) { white-space: nowrap; }
.receipt-detail-table td:nth-child(4) { min-width: 270px; font-weight: 650; }
.receipt-detail-table td:nth-child(7), .receipt-detail-table th:nth-child(7), .receipt-detail-table td:nth-child(8), .receipt-detail-table th:nth-child(8) { text-align: right; }
.receipt-detail-table th:nth-child(7) .sort-button, .receipt-detail-table th:nth-child(8) .sort-button { justify-content: flex-end; }
.stock-table { min-width: 1120px; }
.stock-table td:nth-child(1) { min-width: 300px; font-weight: 650; }
.stock-table td:nth-child(2) { min-width: 170px; }
.stock-table td:nth-child(4), .stock-table th:nth-child(4), .stock-table td:nth-child(7), .stock-table th:nth-child(7), .stock-table td:nth-child(8), .stock-table th:nth-child(8) { text-align: right; }
.stock-table td:nth-child(1), .stock-table th:nth-child(1), .stock-table td:nth-child(2), .stock-table th:nth-child(2), .stock-table td:nth-child(3), .stock-table th:nth-child(3) { text-align: left; }
.stock-table th:nth-child(1) .sort-button, .stock-table th:nth-child(2) .sort-button, .stock-table th:nth-child(3) .sort-button { justify-content: flex-start; }
.stock-table th:nth-child(4) .sort-button, .stock-table th:nth-child(7) .sort-button, .stock-table th:nth-child(8) .sort-button { justify-content: flex-end; }
.product-table { min-width: 980px; }
.product-table td:nth-child(2) { white-space: nowrap; }
.product-table td:nth-child(3) { min-width: 320px; font-weight: 650; }
.product-table td:nth-child(4), .product-table th:nth-child(4), .product-table td:nth-child(5), .product-table th:nth-child(5), .product-table td:nth-child(6), .product-table th:nth-child(6), .product-table td:nth-child(7), .product-table th:nth-child(7) { text-align: right; }
.product-table th:nth-child(2) .sort-button, .product-table th:nth-child(3) .sort-button { justify-content: flex-start; }
.product-table th:nth-child(4) .sort-button, .product-table th:nth-child(5) .sort-button, .product-table th:nth-child(6) .sort-button, .product-table th:nth-child(7) .sort-button { justify-content: flex-end; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.status-pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-positive { color: #247a52; background: #e4f5ec; }
.status-zero { color: #926312; background: #fff2cd; }
.status-negative { color: #ac3d31; background: #ffe5e0; }
.table-heading { align-items: end; }
.search { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; background: white; }
th, td { padding: 14px 16px; border-bottom: 1px solid #e6ecef; text-align: left; }
th { position: sticky; top: 0; color: #617181; background: #f4f7f8; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.sort-button { width: 100%; padding: 0; display: inline-flex; align-items: center; justify-content: inherit; gap: 6px; color: inherit; border: 0; background: transparent; font: inherit; line-height: 1.3; letter-spacing: inherit; text-align: inherit; text-transform: inherit; cursor: pointer; }
.sort-button span { color: #a6b2bb; font-size: 12px; }
.sort-button:hover, .sort-button.active { color: var(--blue); }
.sort-button.active span { color: var(--blue); }
th:last-child .sort-button { justify-content: flex-end; }
th:nth-child(1) .sort-button, th:nth-child(3) .sort-button { justify-content: center; }
td { font-size: 13px; }
td:nth-child(1), td:nth-child(3), th:nth-child(1), th:nth-child(3) { text-align: center; }
td:last-child, th:last-child { text-align: right; }
tbody tr:hover { background: #f7fafb; }
.empty { padding: 50px 20px; color: var(--muted); text-align: center; }
footer { padding: 24px 3px 0; display: flex; justify-content: space-between; color: #7c8995; font-size: 11px; }
@media (max-width: 920px) {
  .page-shell { width: min(100% - 24px, 1480px); padding-top: 12px; }
  .hero { min-height: 200px; padding: 30px 24px 48px; align-items: flex-start; }
  .freshness { min-width: 180px; }
  .period-tabs { grid-template-columns: repeat(3, 1fr); }
  .stock-heading { align-items: stretch; flex-direction: column; }
  .stock-filters { flex-wrap: wrap; }
  .receivable-heading { align-items: stretch; flex-direction: column; }
  .receivable-filters { flex-wrap: wrap; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .customer-rank { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .hero { display: block; border-radius: 20px; }
  .hero h1 { font-size: 44px; }
  .freshness { margin-top: 24px; width: fit-content; }
  main { margin-top: -16px; }
  .filter-card, .panel { padding: 18px; border-radius: 18px; }
  .view-tabs { margin-left: 10px; }
  .filter-heading { display: block; }
  .filter-heading p { margin-top: 8px; }
  .period-tabs { grid-template-columns: 1fr 1fr; }
  .custom-range { align-items: stretch; flex-direction: column; }
  .stock-filters { align-items: stretch; flex-direction: column; }
  .stock-filters input { width: 100%; }
  .receivable-filters { align-items: stretch; flex-direction: column; }
  .receivable-filters input { width: 100%; }
  .custom-range > span { display: none; }
  .kpi-grid, .dashboard-grid { grid-template-columns: 1fr; }
  .trend-panel, .top-customer-panel { grid-column: auto; }
  .kpi { min-height: 142px; }
  .rank-row { grid-template-columns: minmax(100px, 1fr) 1.4fr; }
  .rank-value { grid-column: 2; min-width: 0; text-align: left; }
  .customer-rank .rank-row { grid-template-columns: 28px 1fr; }
  .customer-rank .bar-track, .customer-rank .rank-value { grid-column: 2; }
  .table-heading { align-items: stretch; flex-direction: column; }
  footer { gap: 12px; flex-direction: column; }
}
