/* SDVI app shell — vanilla CSS, mobile-first.
   Two tracks:
     .role-ph (mobile-first 360+) — parent flows
     .role-staff (desktop-first 1024+) — UBND/HT/GV/Y-tế
   Both single codebase, responsive. */

:root {
  --c-primary: #0a5cba;
  --c-primary-dark: #073a78;
  --c-accent: #19a974;
  --c-warn: #f59f00;
  --c-danger: #d6336c;
  --c-bg: #f6f8fb;
  --c-card: #ffffff;
  --c-text: #1a1f2c;
  --c-muted: #6c7589;
  --c-border: #dde3ed;
  /* Design-system tokens (D-187) — color states + subtle backgrounds for badge/alert/button */
  --c-primary-hover: #0950a3;
  --c-primary-subtle: #eef4ff;
  --c-accent-subtle: #e6f7f0;
  --c-warn-subtle: #fff6e6;
  --c-danger-subtle: #fdecf2;
  --c-success: #19a974;      /* alias of accent — semantic name for status */
  --c-info: #0a5cba;         /* alias of primary — semantic name for status */
  --c-text-invert: #ffffff;
  /* Radius */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(10, 30, 60, 0.06);
  --shadow-md: 0 4px 12px rgba(10, 30, 60, 0.08);
  /* Typography scale (px) — replaces ad-hoc inline font-size */
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-2xl: 26px;
  --fw-normal: 400;
  --fw-medium: 600;
  --fw-bold: 700;
  --lh-base: 1.45;
  /* Spacing scale (4-based) — replaces ad-hoc inline padding/gap */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  font-family: -apple-system, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--c-bg); color: var(--c-text); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ----- top bar ----- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: var(--c-primary); color: white;
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 50;
}
.topbar .brand { font-weight: 600; font-size: 16px; flex: 0 0 auto; }
.topbar .brand small { font-weight: 400; opacity: 0.78; margin-left: 6px; font-size: 12px; }
.topbar .spacer { flex: 1; }
.topbar select.role-switch {
  background: rgba(255, 255, 255, 0.14); color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px; padding: 6px 8px; font-size: 14px;
}
.topbar select.role-switch option { color: #1a1f2c; }
.topbar .mode-badge {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}
.topbar .tour-btn {
  background: #ffce3a; color: #2a1a00; border: 1px solid #e8b520;
  padding: 5px 12px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: 13px;
}
.topbar .tour-btn:hover { background: #f5c020; }
@media (max-width: 720px) {
  .topbar .tour-btn { padding: 4px 9px; font-size: 12px; }
}

/* ----- layout ----- */
.layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar {
  width: 220px; background: white; border-right: 1px solid var(--c-border);
  padding: 12px 0;
}
.sidebar .nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; cursor: pointer; color: var(--c-text);
  border-left: 3px solid transparent;
}
.sidebar .nav-item:hover { background: #f0f4fa; }
.sidebar .nav-item.active { background: #eaf2fc; border-left-color: var(--c-primary); font-weight: 600; }
.sidebar .nav-item .icon { width: 22px; text-align: center; font-size: 16px; }
.sidebar .nav-section { font-size: 11px; text-transform: uppercase; color: var(--c-muted); padding: 14px 16px 4px; letter-spacing: 0.04em; }

.main { flex: 1; padding: 18px 24px; max-width: 1200px; }
.main h1 { margin: 0 0 6px; font-size: 22px; }
.main h2 { font-size: 17px; margin: 22px 0 10px; }
.main .subtitle { color: var(--c-muted); margin-bottom: 18px; font-size: 14px; }

/* mobile: collapse sidebar to bottom nav */
@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; order: 99;
    position: fixed; bottom: 0; left: 0;
    display: flex; padding: 0; border-top: 1px solid var(--c-border); border-right: none;
    background: white;
    overflow-x: auto;
  }
  .sidebar .nav-section { display: none; }
  .sidebar .nav-item {
    flex: 1 0 auto; flex-direction: column; gap: 2px; padding: 6px 10px;
    border-left: none; border-top: 3px solid transparent;
    font-size: 11px; min-width: 70px; text-align: center; justify-content: center;
  }
  .sidebar .nav-item.active { border-left: none; border-top-color: var(--c-primary); background: #eaf2fc; }
  .sidebar .nav-item .icon { font-size: 20px; }
  .main { padding: 14px; padding-bottom: 86px; }
}

/* ----- cards / grid ----- */
.card {
  background: var(--c-card); border: 1px solid var(--c-border);
  border-radius: var(--r-lg); padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }

/* ----- KPI cards ----- */
.kpi-card { padding: 16px; }
.kpi-card .kpi-name { font-size: 13px; color: var(--c-muted); margin-bottom: 4px; }
.kpi-card .kpi-pair { display: flex; align-items: baseline; gap: 14px; margin-top: 8px; }
.kpi-card .kpi-before {
  font-size: 13px; color: var(--c-muted);
  text-decoration: line-through;
}
.kpi-card .kpi-arrow { color: var(--c-muted); font-size: 14px; }
.kpi-card .kpi-after {
  font-size: 30px; font-weight: 700; color: var(--c-primary-dark);
  line-height: 1;
}
.kpi-card .kpi-after .unit { font-size: 14px; font-weight: 500; color: var(--c-muted); margin-left: 2px; }
.kpi-card .kpi-delta {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; margin-top: 10px;
}
.kpi-card .kpi-delta.up   { background: #e6f6ee; color: #1d7a44; }
.kpi-card .kpi-delta.down { background: #fde6ee; color: #a92a4d; }
.kpi-card .kpi-delta.flat { background: #ecf0f6; color: #6c7589; }
.kpi-card .kpi-source {
  font-size: 11px; color: var(--c-muted); margin-top: 8px; line-height: 1.4;
  border-top: 1px solid var(--c-border); padding-top: 8px;
}

/* ----- tables ----- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--c-border); text-align: left; vertical-align: middle; }
th { background: #f0f4fa; font-weight: 600; font-size: 13px; color: var(--c-text); }
td { font-size: 14px; }

/* ----- buttons ----- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--r-md);
  border: 1px solid var(--c-primary); background: var(--c-primary); color: white;
  cursor: pointer; font-weight: 500; font-size: 14px;
}
.btn:hover { background: var(--c-primary-dark); border-color: var(--c-primary-dark); }
.btn.btn-secondary { background: white; color: var(--c-primary); }
.btn.btn-secondary:hover { background: #eaf2fc; }
.btn.btn-warn { background: var(--c-warn); border-color: var(--c-warn); color: #2a1a00; }
.btn.btn-danger { background: var(--c-danger); border-color: var(--c-danger); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* status pills */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.pill.present  { background: #e6f6ee; color: #1d7a44; }
.pill.late     { background: #fff5e1; color: #95560a; }
.pill.permitted{ background: #e3eefd; color: #144e9c; }
.pill.sick     { background: #f3e1ff; color: #61177f; }
.pill.absent   { background: #fde6ee; color: #a92a4d; }
.pill.pass     { background: #e6f6ee; color: #1d7a44; }
.pill.warn     { background: #fff5e1; color: #95560a; }
.pill.fail     { background: #fde6ee; color: #a92a4d; }
.pill.muted    { background: #ecf0f6; color: #6c7589; }

/* ----- forms ----- */
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-row label { font-size: 13px; color: var(--c-muted); font-weight: 500; }
.form-row input, .form-row select, .form-row textarea {
  padding: 9px 11px; border: 1px solid var(--c-border); border-radius: var(--r-md);
  background: white; font-size: 14px;
}
.form-row textarea { min-height: 70px; resize: vertical; }

/* alerts / banners */
.banner {
  padding: 10px 14px; border-radius: var(--r-md);
  font-size: 14px; margin-bottom: 14px;
}
.banner.info  { background: #e3eefd; color: #144e9c; }
.banner.warn  { background: #fff5e1; color: #95560a; }
.banner.error { background: #fde6ee; color: #a92a4d; }

.empty {
  text-align: center; padding: 32px 12px; color: var(--c-muted); font-size: 14px;
}

/* nutrition badge variants */
.nutri-detail { font-size: 12px; color: var(--c-muted); margin-top: 4px; }
.nutri-detail b { color: var(--c-text); }

/* Print-only header rendered by modules that support paper export (KPI Lead,
   Ward Dash). Hidden on screen; shown in print to give the printout a clear
   identity (ward, period, generated-at) — UBND officer can hand it to leaders. */
.print-header { display: none; }
.no-print { /* opt-in marker for chrome the module wants to suppress on paper */ }

/* @media print — hide app chrome, expand main, render print-only headers.
   Goal: any module printed (Cmd+P or "In báo cáo" button) yields a clean A4
   page with just the report content + a header strip. */
@media print {
  /* Per TT 01/2011/TT-BNV + NĐ 30/2020/NĐ-CP: Vietnamese state docs use
     Times New Roman 14pt. Apply to body + all descendants; section heads
     can scale via em. */
  :root { font-size: 14pt; }
  html, body {
    background: white !important; color: black !important;
    font-family: "Times New Roman", Times, serif !important;
    font-size: 14pt !important;
    line-height: 1.4;
  }
  body *, table, th, td, p, span, div, h1, h2, h3, h4, h5, h6, li, code {
    font-family: "Times New Roman", Times, serif !important;
  }
  .topbar, .sidebar, .no-print { display: none !important; }
  .layout { display: block !important; min-height: 0 !important; }
  .main { padding: 0 !important; max-width: none !important; }
  .main h1, .main h2 { color: black !important; page-break-after: avoid; }
  /* Heading scale relative to 14pt body. */
  .main h1 { font-size: 18pt; font-weight: 700; }
  .main h2 { font-size: 16pt; font-weight: 700; }
  .main h3 { font-size: 14pt; font-weight: 700; }
  .main .subtitle { font-size: 13pt; }
  .card {
    box-shadow: none !important;
    border: 1px solid #444 !important;
    page-break-inside: avoid;
    background: white !important;
  }
  .banner.info { background: #f0f0f0 !important; color: black !important; border: 1px solid #444 !important; }
  .kpi-card .kpi-after { color: black !important; }
  .pill { border: 1px solid #444; }
  .print-header {
    display: block;
    border-bottom: 2px solid #000;
    padding-bottom: 8px;
    margin-bottom: 14px;
  }
  .print-header h1 { font-size: 18pt; margin: 0 0 2pt; }
  .print-header .meta { font-size: 12pt; color: #333; }
  /* Tables: keep body 14pt; header can be slightly bolder but same size. */
  table { font-size: 14pt; }
  th { font-weight: 700; background: #f0f0f0 !important; }
  td { font-size: 14pt; }
  /* Code blocks not used in printed reports per VN standard — fall back to TNR
     for any inline <code> rather than monospace, to match document feel. */
  code { font-family: "Times New Roman", Times, serif !important; font-size: 13pt; }
  /* Avoid splitting KPI grids across pages where possible. */
  .grid { display: grid !important; }
  .grid .card { break-inside: avoid; }
  a[href]::after { content: ''; }
}

/* ---- Tom Select theme → match app inputs (loaded AFTER tom-select.min.css) ---- */
.ts-wrapper { font-size: 13px; }
.ts-control {
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 5px 8px;
  min-height: 34px;
  color: var(--c-text);
  background: #fff;
}
.ts-wrapper.focus .ts-control,
.ts-control:focus-within {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 2px rgba(10, 92, 186, 0.15);
}
.ts-dropdown {
  border: 1px solid var(--c-border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(20, 30, 60, 0.12);
  font-size: 13px;
  margin-top: 3px;
}
.ts-dropdown .option { padding: 7px 12px; color: var(--c-text); }
.ts-dropdown .active { background: var(--c-primary); color: #fff; }
.ts-dropdown .option.selected { background: #eef4ff; color: var(--c-text); }
.ts-dropdown .no-results { color: var(--c-muted); padding: 8px 12px; }
.ts-wrapper .ts-control > .item { color: var(--c-text); }
.ts-wrapper.multi .ts-control > .item {
  background: #eef4ff; border: 1px solid #c7d9f5; border-radius: 4px; color: var(--c-primary-dark);
}

/* ---- Button variants (lib/ui/button.js — D-187). .btn base = primary already. ---- */
.btn-primary { background: var(--c-primary); border-color: var(--c-primary); color: var(--c-text-invert); }
.btn-primary:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); }
.btn-danger { background: var(--c-danger); border-color: var(--c-danger); color: var(--c-text-invert); }
.btn-danger:hover { filter: brightness(0.92); }
.btn-ghost { background: transparent; border-color: var(--c-border); color: var(--c-text); }
.btn-ghost:hover { background: var(--c-primary-subtle); border-color: var(--c-primary); }
.btn-sm { padding: var(--sp-1) var(--sp-3); font-size: var(--fs-sm); }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---- Field + controls (lib/ui/field.js — D-187) — replaces per-module INP/inputRow ---- */
.ui-field { margin-bottom: var(--sp-3); }
.ui-field-label { display: block; font-size: var(--fs-sm); color: var(--c-muted); margin-bottom: var(--sp-1); }
.ui-field-hint { font-size: var(--fs-xs); color: var(--c-muted); margin-top: 2px; }
.ui-req { color: var(--c-danger); }
.ui-input {
  width: 100%; padding: 6px 8px;
  border: 1px solid var(--c-border); border-radius: var(--r-sm);
  font-size: var(--fs-base); background: #fff; color: var(--c-text);
}
.ui-input:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 2px var(--c-primary-subtle); }
