/* ==========================================================================
   Ember theme (Owner 2026-11-29): matte black + a light mode on the same layout.
   Light values on :root, .dark overrides (class on <html>, saved in localStorage "sh-theme", default dark).
   The old variable names (--surface, --border, --primary …) stay so every screen follows the theme.
   ========================================================================== */
:root {
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #F7F7F8;
  --text: #18181B;
  --muted: #63636B;
  --faint-text: #6E6E76;
  --faint: #A1A1AA;
  --year: #8E8E96;
  --border: #E4E4E7;
  --line: #ECECEE;
  --line-strong: #E4E4E7;
  --icon: #71717A;
  --card-a: #FFFFFF;
  --card-b: #FAFAFA;
  --card-line: #ECECEE;
  --card-hi: inset 0 1px 0 rgba(255, 255, 255, 1);
  --card-shadow: 0 1px 2px rgba(24, 24, 27, .04);
  --act-a: #FFFFFF;
  --act-b: #F1F1F3;
  --act-line: #E4E4E7;
  --act-shadow: 0 1px 2px rgba(24, 24, 27, .08), 0 2px 6px rgba(24, 24, 27, .05);
  --count-active: #68686F;
  --hover: rgba(24, 24, 27, .04);
  --field: #F4F4F5;
  --inverse-bg: #18181B;
  --inverse-text: #FAFAFA;
  --yellow: #FACC15;
  --green: #34D399;
  --blue: #60A5FA;
  --pink: #F472B6;
  --ok: #15803D;
  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --on-primary: #FFFFFF;
  --success: #15803D;
  --success-bg: #DCFCE7;
  --warning: #B45309;
  --warning-bg: #FEF3C7;
  --danger: #B91C1C;
  --danger-bg: #FEE2E2;
  --red-text: #B91C1C;
  --green-text: #15803D;
  --blue-text: #1D4ED8;
  --amber-text: #B45309;
  --red-bg: #FEF2F2;
  --green-bg: #F0FDF4;
  --blue-bg: #EFF6FF;
  --amber-bg: #FFFBEB;
  --plot-bg: transparent;
  --radius: 14px;
  --side-w: 264px;
  --side-w-closed: 68px;
  --font: "Inter", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "Noto Sans Thai", ui-monospace, monospace;
  color-scheme: light;
}
.dark {
  --bg: #000000;
  --surface: #0E0E10;
  --surface-2: #141416;
  --text: #EDEDEF;
  --muted: #8B8B94;
  --faint-text: #7A7A82;
  --faint: #5E5E66;
  --year: #5E5E66;
  --border: #26262A;
  --line: #1D1D20;
  --line-strong: #2A2A2E;
  --icon: #8B8B94;
  --card-a: #141415;
  --card-b: #0A0A0B;
  --card-line: #1D1D20;
  --card-hi: inset 0 1px 0 rgba(255, 255, 255, .06);
  --card-shadow: 0 0 0 transparent;
  --act-a: #2A2A2E;
  --act-b: #1B1B1E;
  --act-line: #323236;
  --act-shadow: inset 0 1px 0 rgba(255, 255, 255, .07), 0 1px 2px rgba(0, 0, 0, .6);
  --count-active: #9A9AA3;
  --hover: rgba(255, 255, 255, .05);
  --field: #101012;
  --inverse-bg: #1B1B1E;
  --inverse-text: #EDEDEF;
  --ok: #4ADE80;
  --primary: #3B82F6;
  --primary-hover: #60A5FA;
  --on-primary: #FFFFFF;
  --success: #4ADE80;
  --success-bg: rgba(74, 222, 128, .12);
  --warning: #FBBF24;
  --warning-bg: rgba(250, 204, 21, .12);
  --danger: #F87171;
  --danger-bg: rgba(248, 113, 113, .13);
  --red-text: #F87171;
  --green-text: #4ADE80;
  --blue-text: #60A5FA;
  --amber-text: #FBBF24;
  --red-bg: rgba(248, 113, 113, .10);
  --green-bg: rgba(74, 222, 128, .10);
  --blue-bg: rgba(96, 165, 250, .10);
  --amber-bg: rgba(250, 204, 21, .10);
  --plot-bg: #000000;
  color-scheme: dark;
}
/* paper stays paper: print preview, A4 sheets and QR labels always use the light set */
.print-overlay, .qc-label-sheet, .a4-sheet {
  --surface: #FFFFFF; --surface-2: #F7F7F8; --text: #18181B; --muted: #52525B; --faint-text: #6E6E76; --border: #D4D4D8;
  --line: #E4E4E7; --line-strong: #D4D4D8; --inverse-bg: #18181B; --inverse-text: #FAFAFA;
  --red-text: #B91C1C; --green-text: #15803D; --blue-text: #1D4ED8; --amber-text: #B45309;
  --red-bg: #FEF2F2; --green-bg: #F0FDF4; --blue-bg: #EFF6FF; --amber-bg: #FFFBEB;
  --success: #15803D; --success-bg: #DCFCE7; --warning: #B45309; --warning-bg: #FEF3C7; --danger: #B91C1C; --danger-bg: #FEE2E2;
  color-scheme: light;
}
@media print {
  :root, .dark {
    --bg: #FFFFFF; --surface: #FFFFFF; --surface-2: #F7F7F8; --text: #000000; --muted: #52525B; --border: #D4D4D8;
    --red-text: #B91C1C; --green-text: #15803D; --blue-text: #1D4ED8; --amber-text: #B45309;
    color-scheme: light;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s ease, color .25s ease;
}
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.num, .stat-val, .nav-count, .mono { font-family: var(--mono); }

/* icons: thin grey lines (stroke 1.8), no emoji in the frame */
.ic { width: 18px; height: 18px; flex: 0 0 18px; fill: none; stroke: var(--icon); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dot { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.dark .dot { filter: drop-shadow(0 0 4px currentColor) drop-shadow(0 0 8px currentColor); }
.c-yellow { color: var(--yellow); } .c-green { color: var(--green); } .c-blue { color: var(--blue); } .c-pink { color: var(--pink); }
.c-grey { color: var(--faint); }
.dark .c-grey { filter: none; }

/* ---------- layout: sidebar attached to the screen edge ---------- */
.app-layout { min-height: 100vh; }

.sidebar {
  position: fixed; z-index: 30; top: 0; bottom: 0; left: 0;
  width: var(--side-w); display: flex; flex-direction: column;
  background: var(--bg); border-right: 1px solid var(--line); color: var(--text);
  transition: width .3s cubic-bezier(.4, 0, .2, 1), transform .3s cubic-bezier(.4, 0, .2, 1), background-color .25s ease;
  overflow: hidden;
}
.sidebar.closed { width: var(--side-w-closed); }
.side-sec { padding: 12px; border-bottom: 1px solid var(--line); }
.side-sec:last-child { border-bottom: 0; }
.side-sec.grow { flex: 1; overflow-y: auto; overflow-x: hidden; scrollbar-width: none; }
.side-sec.grow::-webkit-scrollbar { display: none; }

.brand-row { display: flex; align-items: center; justify-content: space-between; height: 64px; padding-top: 0; padding-bottom: 0; }
.logo { display: flex; align-items: center; gap: 10px; white-space: nowrap; overflow: hidden; padding-left: 6px; min-width: 0; }
.logo-mark { width: 28px; height: 28px; flex: 0 0 28px; border-radius: 9px; display: grid; place-items: center; background: linear-gradient(180deg, var(--act-a), var(--act-b)); border: 1px solid var(--act-line); }
.logo-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-title { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
.brand-sub { margin: 0; font-size: 11px; color: var(--muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; }
.sidebar.closed .brand-row { justify-content: center; }
.sidebar.closed .logo { display: none; }

.icon-btn { width: 36px; height: 36px; flex: 0 0 36px; display: inline-grid; place-items: center; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--text); cursor: pointer; padding: 0; transition: background-color .15s ease; position: relative; }
.icon-btn:hover { background: var(--hover); }
.icon-btn[aria-expanded="true"] { background: linear-gradient(180deg, var(--act-a), var(--act-b)); border-color: var(--act-line); box-shadow: var(--act-shadow); }
.icon-btn .alert-dot { position: absolute; top: 7px; right: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--pink); }
.dark .icon-btn .alert-dot { box-shadow: 0 0 6px var(--pink); }

.search { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 8px 0 10px; border-radius: 10px; background: var(--field); border: 1px solid var(--line); cursor: text; }
.search:focus-within { border-color: var(--blue); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; padding: 0; }
.search input::placeholder { color: var(--muted); }
.kbd { font-family: var(--mono); font-size: 11px; color: var(--muted); padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line); white-space: nowrap; }
.sidebar.closed .search { justify-content: center; padding: 0; cursor: pointer; }
.sidebar.closed .search input, .sidebar.closed .search .kbd { display: none; }

.sec-title { font-family: var(--mono); font-size: 11px; color: var(--faint-text); letter-spacing: .04em; margin: 2px 8px 6px; white-space: nowrap; }
.sidebar.closed .sec-title { visibility: hidden; height: 0; margin: 0; }

.nav-list { display: flex; flex-direction: column; gap: 2px; padding: 0; }
.nav-btn, .nav-group {
  position: relative; display: flex; align-items: center; gap: 10px; width: 100%; min-height: 36px; padding: 6px 10px;
  border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--text);
  text-align: left; font: inherit; font-size: 13.5px; cursor: pointer; white-space: nowrap; transition: background-color .15s ease;
}
.nav-btn:hover, .nav-group:hover { background: var(--hover); }
.nav-btn.active { background: linear-gradient(180deg, var(--act-a), var(--act-b)); border-color: var(--act-line); box-shadow: var(--act-shadow); font-weight: 600; }
.nav-btn .label, .nav-group .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-count { font-size: 11px; color: var(--faint-text); white-space: nowrap; }
.nav-btn.active .nav-count { color: var(--count-active); }
.chev { width: 16px; height: 16px; flex: 0 0 16px; fill: none; stroke: var(--icon); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s ease; }
.nav-group[aria-expanded="true"] .chev { transform: rotate(180deg); }
.nav-sub { margin: 2px 0 6px 19px; padding-left: 12px; border-left: 1px solid var(--line); display: none; flex-direction: column; gap: 2px; }
.nav-sub.open { display: flex; }
.nav-sub .nav-btn { min-height: 32px; font-size: 13px; }
.sidebar.closed .nav-btn, .sidebar.closed .nav-group { justify-content: center; padding: 0; }
.sidebar.closed .nav-btn .label, .sidebar.closed .nav-btn .nav-count, .sidebar.closed .nav-group .label, .sidebar.closed .chev { display: none; }
.sidebar.closed .nav-sub { display: none !important; }
.nav-hidden { display: none !important; }

.dept { display: flex; align-items: center; gap: 12px; height: 32px; padding: 0 12px; border-radius: 10px; white-space: nowrap; }
.dept .name { flex: 1; color: var(--text); font-size: 13px; }
.dept .nav-count { font-family: var(--mono); }
.sidebar.closed .dept { justify-content: center; padding: 0; }
.sidebar.closed .dept .name, .sidebar.closed .dept .nav-count { display: none; }

.side-foot { display: flex; align-items: center; gap: 8px; }
.user-box { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.avatar { width: 32px; height: 32px; flex: 0 0 32px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(180deg, var(--act-a), var(--act-b)); border: 1px solid var(--act-line); }
.user-box .who { min-width: 0; flex: 1; line-height: 1.3; }
.user-box .who > * { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box .role { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.user-box .icon-btn { width: 30px; height: 30px; flex-basis: 30px; }
.sidebar.closed .side-foot { flex-direction: column; }
.sidebar.closed .user-box { flex-direction: column; }
.sidebar.closed .user-box .who { display: none; }

/* ---------- main area ---------- */
.main-area { margin-left: var(--side-w); min-height: 100vh; display: flex; flex-direction: column; min-width: 0; transition: margin-left .3s cubic-bezier(.4, 0, .2, 1); }
.sidebar.closed ~ .main-area { margin-left: var(--side-w-closed); }

.topbar {
  position: sticky; top: 0; z-index: 20; height: 64px; display: flex; align-items: center; gap: 10px;
  padding: 0 24px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar-left { flex: 1; min-width: 0; }
.page-title { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 15px; font-weight: 600; }
.page-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-sub { margin: 0; padding: 14px 28px 0; font-size: 12.5px; color: var(--muted); max-width: 1280px; }
.topbar-controls { display: flex; align-items: center; gap: 8px; }
.menu-btn { display: none; }

.filter-pill { display: flex; align-items: center; gap: 6px; background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; height: 36px; font-size: 12.5px; color: var(--muted); }
.filter-pill select { border: none; background: transparent; font-family: var(--mono); font-size: 12.5px; font-weight: 600; color: var(--text); cursor: pointer; outline: none; padding: 0; width: auto; }
.filter-pill select option { background: var(--surface); color: var(--text); }

.notif-wrap { position: relative; }
.notif-pop { position: absolute; right: 0; top: 46px; width: 340px; display: none; z-index: 45; padding: 8px 0; border-radius: 16px; background: linear-gradient(180deg, var(--card-a), var(--card-b)); border: 1px solid var(--card-line); box-shadow: var(--card-hi), 0 12px 32px rgba(0, 0, 0, .18); }
.notif-pop.open { display: block; }
.notif-head { padding: 6px 16px 8px; font-weight: 600; }
.notif-list { list-style: none; margin: 0; padding: 0; }
.notif-list li { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); }
.notif-list button { all: unset; display: flex; align-items: center; gap: 12px; width: 100%; cursor: pointer; }
.notif-list li:hover { background: var(--hover); }
.notif-list .meta { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.content-wrap { padding: 20px 28px 48px; max-width: 1280px; width: 100%; }
.scrim { display: none; }

/* ---------- home dashboard (Ember) ---------- */
.home-hero { margin: 8px 0 26px; }
.home-hero .date { font-family: var(--mono); font-size: 52px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.1; margin: 0; }
.home-hero .date .year { color: var(--year); }
.home-hero .sub-line { font-family: var(--mono); font-size: 13px; color: var(--muted); margin-top: 10px; }
.home-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.ecard {
  border-radius: 20px; padding: 22px; min-width: 0;
  background: linear-gradient(180deg, var(--card-a), var(--card-b));
  border: 1px solid var(--card-line); box-shadow: var(--card-hi), var(--card-shadow);
}
.ecard-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; margin-bottom: 14px; }
.ecard-title { font-family: var(--mono); font-size: 12px; color: var(--muted); letter-spacing: .03em; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.ecard-link { all: unset; cursor: pointer; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.ecard-link:hover { color: var(--text); }
.ecard-link:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
.big { font-family: var(--mono); font-size: 36px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.15; }
.big.ph { font-size: 22px; color: var(--muted); }
.note { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 6px; }
.ecard-head .note { margin-top: 0; }
.note.ok { color: var(--ok); }
.erows { list-style: none; margin: 0 -22px; padding: 0; }
.erows li { display: flex; align-items: center; gap: 12px; padding: 11px 22px; border-top: 1px solid var(--line); }
.erows .grow { flex: 1; min-width: 0; }
.erows .grow > div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.erows .meta { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.erows li.is-done .grow > div:first-child { color: var(--muted); }
.check { width: 18px; height: 18px; flex: 0 0 18px; border-radius: 6px; border: 1.5px solid var(--faint); display: grid; place-items: center; }
.check.done { border-color: var(--ok); background: var(--ok); }
.check.done::after { content: ""; width: 8px; height: 4px; border: solid var(--bg); border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }
.ebar { height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; margin-top: 14px; }
.ebar > i { display: block; height: 100%; width: 0; border-radius: 6px; background: linear-gradient(90deg, var(--yellow), var(--green)); }
.echart { position: relative; height: 196px; padding: 10px 12px 6px; border-radius: 14px; background: var(--plot-bg); box-shadow: inset 0 0 0 1px var(--card-line); }
.echart svg { display: block; overflow: visible; }
.echart .empty { position: absolute; inset: 10px 12px 28px; display: grid; place-items: center; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.legend { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.legend svg { width: 28px; height: 8px; overflow: visible; }
.dark .legend line { filter: drop-shadow(0 0 3px #F472B6) drop-shadow(0 0 6px #60A5FA); }

/* ---------- small screens: the menu becomes a drawer ---------- */
@media (max-width: 900px) {
  .home-grid { grid-template-columns: minmax(0, 1fr); }
  .home-hero .date { font-size: 40px; }
  .content-wrap { padding: 18px 16px 40px; }
  .page-sub { padding: 12px 16px 0; }
}
@media (max-width: 760px) {
  .sidebar, .sidebar.closed { width: var(--side-w); transform: translateX(-100%); visibility: hidden; transition: transform .3s cubic-bezier(.4, 0, .2, 1), visibility 0s linear .3s; }
  .sidebar.drawer { transform: none; visibility: visible; transition: transform .3s cubic-bezier(.4, 0, .2, 1), visibility 0s; }
  .sidebar.closed .logo { display: flex; }
  .main-area, .sidebar.closed ~ .main-area { margin-left: 0; }
  .menu-btn { display: inline-grid; }
  #btnCollapse { display: none; }
  .topbar { padding: 0 10px; height: auto; min-height: 64px; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
  .topbar-controls { flex-wrap: wrap; }
  .scrim.show { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, .45); }
  .notif-pop { position: fixed; left: 12px; right: 12px; top: 64px; width: auto; }
  .home-hero .date { font-size: 34px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
@media print {
  .sidebar, .topbar, .scrim, .page-sub { display: none !important; }
  .main-area { margin-left: 0 !important; }
}

/* Cards & Stats */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.stat-val {
  font-size: 23px;
  font-weight: 700;
  margin: 4px 0 2px;
  color: var(--text);
}

.stat-sub {
  font-size: 12px;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
}

.card-subtitle {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

/* Forms & Inputs */
.quick-form {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 14px;
  margin-bottom: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 10px;
  align-items: end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group.span-2 {
  grid-column: span 2;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  font-family: inherit;
  font-size: 13.5px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(2, 132, 199, 0.25);
  border-color: var(--primary);
}

.kpi-check-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  padding: 9px 12px;
  background: var(--blue-bg);
  border: 1px solid #bae6fd;
  border-radius: 8px;
  align-items: center;
}

.kpi-check-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.kpi-check-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--success);
  cursor: pointer;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 7px 13px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-outline:hover {
  background: var(--surface-2);
}

.btn-success {
  background: var(--success);
  color: #ffffff;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--faint-text);
  padding: 4px 7px;
  font-size: 12px;
}

.btn-danger-ghost:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

.btn:disabled,
.chk-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.link-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link-btn:hover {
  color: var(--primary-hover);
}

/* MRP Calculator & Stock Dropzone */
.bom-plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 10px;
}

.bom-plan-card {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: border-color 0.15s, background 0.15s;
}

.bom-plan-card.active-plan {
  border-color: var(--primary);
  background: var(--blue-bg);
}

.qty-stepper {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.qty-stepper button {
  width: 26px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}

.qty-stepper input {
  width: 52px;
  text-align: center;
  font-weight: 700;
  padding: 4px;
}

.stock-dropzone {
  border: 2px dashed #38bdf8;
  background: var(--blue-bg);
  border-radius: 10px;
  padding: 18px 20px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.stock-dropzone:hover,
.stock-dropzone.dragover {
  background: var(--blue-bg);
  border-color: #0284c7;
}

.buy-qty-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  background: var(--danger-bg);
  color: var(--red-text);
}

.loc-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
}

.alert-panel {
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
  border: 1px solid #fca5a5;
  background: var(--red-bg);
}

.alert-panel.amber {
  border-color: #fcd34d;
  background: var(--amber-bg);
}

/* Company Email Login Overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, var(--inverse-bg) 0%, #1e293b 100%);
  z-index: 250;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-overlay.open {
  display: flex;
}

.login-card {
  width: min(460px, 100%);
  background: var(--surface);
  border-radius: 14px;
  padding: 28px 26px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
}

input[type="email"],
input[type="password"] {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}

.quick-login-box {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}

.quick-login-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.quick-acct-btn {
  text-align: left;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: border-color 0.15s, background 0.15s;
}

.quick-acct-btn:hover {
  border-color: var(--primary);
  background: var(--blue-bg);
}

.quick-acct-btn strong {
  font-size: 12px;
  color: var(--text);
}

.quick-acct-btn span {
  font-size: 11px;
  color: var(--muted);
}

/* Collapsible secondary forms & Role-clean Viewer mode */
details.form-collapse {
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
}

details.form-collapse > summary {
  padding: 10px 14px;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--primary);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

details.form-collapse > summary::-webkit-details-marker {
  display: none;
}

details.form-collapse[open] > summary {
  border-bottom: 1px solid var(--line);
}

details.form-collapse .quick-form {
  margin: 0;
  border: none;
}

.chip-btn {
  border: 1px solid #bae6fd;
  background: var(--blue-bg);
  color: var(--blue-text);
  border-radius: 999px;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 9px;
  cursor: pointer;
}

.chip-btn:hover {
  background: var(--blue-bg);
}

/* Viewer Role: clean read-only dashboard without entry forms or delete buttons */
body.role-viewer .quick-form,
body.role-viewer details.form-collapse,
body.role-viewer .btn-danger-ghost,
body.role-viewer .write-only {
  display: none !important;
}

body.role-viewer .chk-btn,
body.role-viewer input[data-mat-loc],
body.role-viewer input[data-mat-min],
body.role-viewer input[data-mrp-stock-key],
body.role-viewer input[data-ck-qty],
body.role-viewer input[data-ck-note],
body.role-viewer #ckBomSelect,
body.role-viewer .s5-score-inp,
body.role-viewer input[name="audit_note"] {
  pointer-events: none;
  opacity: 0.8;
}

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.pill-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill-tab {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  padding: 5px 11px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.pill-tab.active {
  background: var(--inverse-bg);
  color: #ffffff;
  border-color: var(--text);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--surface);
}

th, td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-2);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

tr:hover td {
  background: var(--surface-2);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.center {
  text-align: center;
}

.total-row td {
  background: var(--surface-2) !important;
  font-weight: 700;
  border-top: 2px solid var(--border);
}

/* Badges & Checkboxes */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-green { background: var(--success-bg); color: var(--green-text); }
.badge-amber { background: var(--warning-bg); color: var(--amber-text); }
.badge-red { background: var(--danger-bg); color: var(--red-text); }
.badge-blue { background: var(--blue-bg); color: var(--blue-text); }
.badge-slate { background: var(--surface-2); color: var(--muted); }

.chk-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  padding: 0;
}

.chk-btn.on {
  background: var(--success-bg);
  border-color: #86efac;
  color: var(--green-text);
}

.chk-btn.off-alert {
  background: var(--danger-bg);
  border-color: #fca5a5;
  color: var(--red-text);
}

.cell-fail {
  background: var(--danger-bg) !important;
  color: var(--red-text);
  font-weight: 700;
}

.cell-pass {
  color: var(--green-text);
  font-weight: 600;
}

/* QC Inspection (menu: ตรวจ QC สินค้า) */
.qc-ck-box {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  background: var(--surface-2);
}

.qc-ck-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
  flex-wrap: wrap;
}

.qc-ck-row:last-child {
  border-bottom: none;
}

.qc-ck-label {
  font-size: 13.5px;
  font-weight: 600;
}

.qc-opts {
  display: flex;
  gap: 6px;
}

.qc-opt {
  position: relative;
  cursor: pointer;
}

.qc-opt input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.qc-opt span {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  background: var(--surface);
  user-select: none;
  white-space: nowrap;
}

.qc-opt input:focus-visible + span {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

.qc-opt-pass input:checked + span { background: var(--success-bg); border-color: #16a34a; color: var(--green-text); font-weight: 700; }
.qc-opt-fail input:checked + span { background: var(--danger-bg); border-color: #dc2626; color: var(--red-text); font-weight: 700; }
.qc-opt-na input:checked + span { background: var(--line-strong); border-color: var(--muted); color: var(--text); font-weight: 700; }
.qc-opt input:disabled + span { cursor: default; opacity: 0.8; }

.qc-photo-box {
  margin-top: 10px;
}

.qc-photo-btn {
  cursor: pointer;
}

.qc-photo-empty {
  font-size: 12.5px;
  color: var(--muted);
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  text-align: center;
}

.qc-photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}

.qc-photo-item {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.qc-photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.qc-photo-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.75);
  color: #ffffff;
  cursor: pointer;
  font-size: 13px;
}

.qc-photo-tag {
  position: absolute;
  left: 4px;
  bottom: 4px;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.7);
  color: #ffffff;
}

.qc-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.qc-submit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.qc-drive-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 10px;
}

.qc-drive-bar.on { background: var(--success-bg); }
.qc-drive-bar.warn { background: var(--warning-bg); }
.qc-drive-bar.off { background: var(--surface-2); color: var(--muted); }

.qc-modal-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.qc-detail-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  align-items: start;
}

.qc-qr-box {
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.qc-qr-svg svg {
  width: 100%;
  max-width: 200px;
  height: auto;
}

.qc-qr-code {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.5px;
}

.qc-qr-url {
  font-size: 10.5px;
  color: var(--muted);
  word-break: break-all;
}

.qc-info-table th {
  text-align: left;
  width: 32%;
  color: var(--muted);
  font-weight: 600;
  white-space: normal;
}

.qc-section-title {
  margin: 16px 0 8px;
  font-size: 14px;
}

.qc-modal-write {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.qc-modal-write input[type="text"] {
  flex: 1;
  min-width: 200px;
}

/* QC sticker (80 x 50 mm, cut along the dashed line) */
.qc-label-sheet {
  display: flex;
  flex-wrap: wrap;
  gap: 6mm;
}

.qc-label {
  width: 80mm;
  height: 50mm;
  border: 1px dashed #334155;
  padding: 3mm;
  display: flex;
  gap: 3mm;
  align-items: center;
  box-sizing: border-box;
  page-break-inside: avoid;
  break-inside: avoid;
}

.qc-label-qr {
  width: 38mm;
  height: 38mm;
  flex: 0 0 38mm;
}

.qc-label-qr svg {
  width: 100%;
  height: 100%;
}

.qc-label-info {
  font-size: 9pt;
  line-height: 1.35;
  overflow: hidden;
}

.qc-label-brand {
  font-size: 7pt;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.qc-label-code {
  font-size: 12pt;
  font-weight: 800;
}

.qc-label-item {
  font-weight: 700;
  max-height: 2.8em;
  overflow: hidden;
}

.qc-label-result {
  margin-top: 1mm;
  font-weight: 800;
  font-size: 10pt;
}

.qc-label-result.fail { color: #b91c1c; }

.qc-label-hint {
  width: 100%;
  font-size: 10px;
  color: #475569;
}

.qc-report-head {
  display: grid;
  grid-template-columns: 1fr 34mm;
  gap: 4mm;
  align-items: start;
}

.qc-report-qr {
  text-align: center;
  font-size: 10px;
  font-weight: 700;
}

.qc-report-qr svg {
  width: 32mm;
  height: 32mm;
}

.qc-report-photos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3mm;
  margin-top: 10px;
}

.qc-report-photos div {
  text-align: center;
  font-size: 10px;
  break-inside: avoid;
}

.qc-report-photos img {
  width: 100%;
  height: 50mm;
  object-fit: cover;
  border: 1px solid #94a3b8;
}

/* Modal & Print Overlay */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  background: var(--surface);
  border-radius: 12px;
  width: min(980px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
}

.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--inverse-bg);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  z-index: 300; /* above the login overlay (250) so login errors are visible */
  display: none;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.toast.show {
  display: block;
}

/* Print Sheet */
.print-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  z-index: 150;
  display: none;
  flex-direction: column;
  align-items: safe center; /* a 210 mm sheet wider than a phone stays scrollable from its left edge */
  overflow: auto;
  padding: 24px;
}

.print-overlay.open {
  display: flex;
}

.print-toolbar {
  width: min(210mm, 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--inverse-bg);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.a4-sheet {
  width: 210mm;
  min-height: 297mm;
  background: #ffffff;
  color: #000000;
  padding: 14mm 15mm;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.a4-sheet h1 {
  margin: 0 0 4px;
  font-size: 18px;
  text-align: center;
}

.a4-sheet .a4-sub {
  text-align: center;
  font-size: 13px;
  margin-bottom: 14px;
}

.a4-sheet table {
  font-size: 11.5px;
}

.a4-sheet th, .a4-sheet td {
  border: 1px solid #334155;
  padding: 5px 7px;
}

.a4-sheet table.compact-print {
  font-size: 9.8px;
  table-layout: auto;
}

.a4-sheet table.compact-print th,
.a4-sheet table.compact-print td {
  padding: 3px 4px;
}

.sign-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-top: 32px;
  text-align: center;
  font-size: 12.5px;
}

@media print {
  @page {
    size: A4;
    margin: 10mm;
  }
  /* A4 sheet open: print ONLY the sheet. display:none (not visibility:hidden) so the hidden
     app layout takes no space and the sheet starts on page 1 without blank leading pages. */
  body:has(.print-overlay.open) > *:not(.print-overlay) {
    display: none !important;
  }
  .print-overlay.open {
    position: static;
    background: none;
    padding: 0;
    display: block !important;
  }
  .print-toolbar {
    display: none !important;
  }
  .qc-label,
  .qc-report-photos img {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .a4-sheet {
    width: 100%;
    min-height: 0;
    padding: 0;
    box-shadow: none;
  }
}

@media (max-width: 900px) {
  .form-group.span-2 {
    grid-column: span 1;
  }
  .qc-detail-grid {
    grid-template-columns: 1fr;
  }
  .qc-opts {
    width: 100%;
  }
  .qc-opt {
    flex: 1;
  }
  .qc-opt span {
    display: block;
    text-align: center;
    padding: 8px 4px;
  }
  .modal-head {
    flex-wrap: wrap;
    gap: 8px;
  }
}

/* Multi-user: "a teammate saved something" banner */
.change-banner {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 260;
  display: none;
  align-items: center;
  gap: 10px;
  max-width: min(680px, calc(100vw - 24px));
  padding: 10px 12px 10px 16px;
  background: var(--inverse-bg);
  color: #f8fafc;
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.35);
  font-size: 13.5px;
}

.change-banner.show {
  display: flex;
}

.change-banner .btn {
  white-space: nowrap;
  padding: 6px 12px;
}

.change-banner-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--faint-text);
  font-size: 15px;
  cursor: pointer;
  padding: 4px 6px;
}

@media (max-width: 600px) {
  .change-banner {
    flex-wrap: wrap;
    bottom: 10px;
  }
}

@media print {
  .change-banner {
    display: none !important;
  }
}

/* Forced first-login password change */
.pwd-forced-note {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--amber-bg);
  border: 1px solid #fdba74;
  color: var(--amber-text);
  font-size: 13px;
  line-height: 1.5;
}


/* ==========================================================================
   Ember polish for the 12 screens (phase 1: colours, cards, tables, forms follow the theme)
   ========================================================================== */
.card, .stat-card {
  background: linear-gradient(180deg, var(--card-a), var(--card-b));
  border: 1px solid var(--card-line);
  box-shadow: var(--card-hi), var(--card-shadow);
}
.card { border-radius: 20px; padding: 20px 22px; }
.stat-card { border-radius: 16px; }
.stat-label, .card-subtitle { color: var(--muted); }
.stat-val { font-weight: 600; letter-spacing: -0.03em; }
.card-title { font-weight: 600; }
.table-wrap { border-color: var(--line); border-radius: 12px; }
table { background: transparent; }
th, td { border-bottom-color: var(--line); }
th { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 12.5px; }
tr:hover td { background: var(--hover); }
.total-row td { background: var(--surface-2) !important; }
input[type="text"], input[type="number"], input[type="date"], input[type="email"], input[type="password"], input[type="search"], select, textarea {
  background: var(--field); border-color: var(--border); color: var(--text);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
.form-group label { color: var(--muted); }
.quick-form { background: var(--surface-2); border-color: var(--line); border-radius: 14px; }
.btn { border-radius: 10px; }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--hover); }
.btn-primary, .btn-success { color: var(--on-primary); }
.pill-tab { background: var(--surface-2); color: var(--muted); border-color: var(--line); }
.pill-tab.active { background: linear-gradient(180deg, var(--act-a), var(--act-b)); color: var(--text); border-color: var(--act-line); box-shadow: var(--act-shadow); }
.chip-btn { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.badge-slate { background: var(--surface-2); color: var(--muted); }
.modal-backdrop { background: rgba(0, 0, 0, .55); }
.modal-box { background: var(--surface); color: var(--text); border: 1px solid var(--card-line); border-radius: 20px; }
.modal-head { border-bottom-color: var(--line); }
.login-overlay { background: var(--bg); }
.login-card { background: linear-gradient(180deg, var(--card-a), var(--card-b)); border: 1px solid var(--card-line); box-shadow: var(--card-hi), 0 20px 50px rgba(0, 0, 0, .25); border-radius: 20px; color: var(--text); }
.toast, .change-banner { background: var(--inverse-bg); color: var(--inverse-text); border: 1px solid var(--line-strong); }
.dark .chk-btn { background: var(--field); }
.a4-sheet th { color: var(--text); font-weight: 700; }
.nav-empty { margin: 8px 10px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.sidebar.closed .nav-empty { display: none; }
