:root {
  --ldb-navy: #003087;
  --ldb-gold: #c8a951;
  --bg: #f2f5fa;
  --bg-card: #ffffff;
  --text: #1a2433;
  --text-muted: #6b7280;
  --border: #e2e8f0;
  --hover: rgba(0, 48, 135, 0.05);
  --shadow: 0 1px 3px rgba(15, 30, 60, 0.08), 0 4px 14px rgba(15, 30, 60, 0.06);
}
:root[data-theme="dark"] {
  --bg: #0f1623;
  --bg-card: #1a2333;
  --text: #e7ecf4;
  --text-muted: #94a3b8;
  --border: #2b3a52;
  --hover: rgba(200, 169, 81, 0.08);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'Noto Sans Lao', 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
a { color: var(--ldb-navy); }
:root[data-theme="dark"] a { color: #7fb3ff; }

/* ===== ຮູບພື້ນຫຼັງ ໃຊ້ທຸກໜ້າ ===== */
/* ໜ້າພາຍໃນ: ຮູບຈາງໆ ເພື່ອໃຫ້ອ່ານເນື້ອຫາໄດ້ຊັດ */
body.has-app-bg::before {
  content: ''; position: fixed; inset: 0; z-index: -2;
  background-image: var(--app-bg);
  background-size: cover; background-position: center; background-attachment: fixed;
}
body.has-app-bg::after {
  content: ''; position: fixed; inset: 0; z-index: -1;
  background: rgba(242, 245, 250, 0.90);
}
:root[data-theme="dark"] body.has-app-bg::after { background: rgba(15, 22, 35, 0.92); }
body.has-app-bg { background: transparent; }
body.has-app-bg .card,
body.has-app-bg .stat-card { background: rgba(255, 255, 255, 0.96); }
:root[data-theme="dark"] body.has-app-bg .card,
:root[data-theme="dark"] body.has-app-bg .stat-card { background: rgba(26, 35, 51, 0.96); }

/* ===== LOGIN ===== */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #00246b 0%, #003087 55%, #1a4dad 100%);
  padding: 1rem;
  position: relative;
}
/* ໜ້າ login: ສະແດງຮູບແຈ້ງ ແລະ ເຫັນເຕັມໃບ (ບໍ່ຕັດຂອບ) */
body.has-app-bg .login-wrap {
  background: #071a3d;
  overflow: hidden;
}
/* ຊັ້ນ 1: ຮູບຂະຫຍາຍເຕັມຈໍ + ມົວ ໃຊ້ຕື່ມຊ່ອງຫວ່າງສອງຂ້າງ */
body.has-app-bg .login-wrap::before {
  content: ''; position: absolute; inset: -3%; z-index: 0;
  background-image: var(--app-bg);
  background-size: cover; background-position: center;
  filter: blur(22px) brightness(0.55) saturate(1.1);
  transform: scale(1.06);
}
/* ຊັ້ນ 2: ຮູບຈິງ ເຫັນເຕັມໃບ ບໍ່ຖືກຕັດ */
body.has-app-bg .login-wrap::after {
  content: ''; position: absolute; inset: 0; z-index: 0;
  background-image: var(--app-bg);
  background-size: contain; background-position: center; background-repeat: no-repeat;
}
body.has-app-bg .login-box {
  position: relative; z-index: 1;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}
:root[data-theme="dark"] body.has-app-bg .login-box { background: rgba(26, 35, 51, 0.95); }

/* ຈໍກວ້າງ: ແບ່ງພື້ນທີ່ — ຮູບຢູ່ຊ້າຍ, ກ່ອງ login ຢູ່ຂວາ (ບໍ່ທັບກັນ) */
@media (min-width: 1000px) {
  body.has-app-bg .login-wrap { justify-content: flex-end; padding-right: 4vw; }
  body.has-app-bg .login-wrap::after { right: 32%; }   /* ຮູບຢູ່ 68% ຊ້າຍ */
}
/* ຈໍນ້ອຍ: ຮູບເຕັມ ກ່ອງຢູ່ກາງ (ທັບໄດ້ ເພາະບໍ່ມີບ່ອນ) */
@media (max-width: 999px) {
  body.has-app-bg .login-box { background: rgba(255, 255, 255, 0.97); }
}
.login-box {
  background: var(--bg-card);
  border-radius: 1rem;
  padding: 2.2rem 2rem;
  width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.login-logo { text-align: center; margin-bottom: 1.4rem; }
.login-logo-img { height: 64px; margin-bottom: 0.6rem; }
.login-title { font-size: 1.15rem; font-weight: 700; color: var(--ldb-navy); }
:root[data-theme="dark"] .login-title { color: #9dbdf5; }
.login-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }
.login-field { margin-bottom: 0.9rem; }
.login-field label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 0.3rem; }
.login-field input {
  width: 100%; padding: 0.65rem 0.85rem;
  border: 1.5px solid var(--border); border-radius: 0.5rem;
  font-family: inherit; font-size: 0.95rem;
  background: var(--bg-card); color: var(--text);
}
.login-field input:focus { outline: none; border-color: var(--ldb-navy); }
/* ຊ່ອງລະຫັດຜ່ານ + ປຸ່ມຕາ */
.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 2.7rem !important; }
.pass-eye {
  position: absolute; right: 0.4rem; top: 50%; transform: translateY(-50%);
  background: transparent; border: none; cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 0.35rem 0.45rem;
  border-radius: 0.35rem; opacity: 0.55; color: var(--text);
}
.pass-eye:hover { opacity: 1; background: var(--hover); }
.pass-eye.on { opacity: 1; color: var(--ldb-navy); }
:root[data-theme="dark"] .pass-eye.on { color: #9dbdf5; }

/* ຈົດຈຳໄອດີ */
.remember-row {
  display: flex; align-items: center; gap: 0.45rem;
  font-size: 0.83rem; margin-bottom: 0.9rem; cursor: pointer;
  user-select: none;
}
.remember-row input { cursor: pointer; width: 15px; height: 15px; }

.login-error {
  background: #fdecea; color: #c62828;
  padding: 0.55rem 0.8rem; border-radius: 0.5rem;
  font-size: 0.82rem; margin-bottom: 0.8rem;
}
.login-foot { margin-top: 1rem; text-align: center; font-size: 0.72rem; color: var(--text-muted); }

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--ldb-navy); color: #fff;
  border: none; border-radius: 0.5rem;
  padding: 0.55rem 1.2rem; font-family: inherit; font-size: 0.88rem; font-weight: 600;
  cursor: pointer; transition: background 0.15s;
}
.btn-primary:hover { background: #00246b; }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent; color: var(--ldb-navy);
  border: 1px solid var(--border); border-radius: 0.5rem;
  padding: 0.5rem 1rem; font-family: inherit; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: background 0.15s;
}
:root[data-theme="dark"] .btn-ghost { color: #9dbdf5; }
.btn-ghost:hover { background: var(--hover); }
.spinner {
  display: inline-block; width: 13px; height: 13px;
  border: 2px solid rgba(255, 255, 255, 0.4); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== HEADER ===== */
.header {
  background: var(--ldb-navy);
  color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1.2rem;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}
.header-left { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
.logo-img { height: 40px; border-radius: 0.375rem; background: #fff; padding: 2px; }
.logo-text { font-size: 0.98rem; font-weight: 700; line-height: 1.25; }
.logo-sub { font-size: 0.7rem; opacity: 0.85; }
.header-right { display: flex; align-items: center; gap: 0.5rem; }
.user-badge {
  background: rgba(255, 255, 255, 0.15);
  padding: 0.3rem 0.8rem; border-radius: 1rem; font-size: 0.78rem;
  white-space: nowrap;
}
.header .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, 0.35); }
.header .btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }

/* ===== LAYOUT ===== */
.main { max-width: 1280px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1rem;
}
.page-head h2 { font-size: 1.15rem; color: var(--ldb-navy); }
:root[data-theme="dark"] .page-head h2 { color: #9dbdf5; }
.page-head-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.card-header {
  font-size: 0.92rem; font-weight: 700; color: var(--ldb-navy);
  margin-bottom: 0.7rem;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.4rem;
}
:root[data-theme="dark"] .card-header { color: #9dbdf5; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* ===== FILTERS ===== */
.filter-row { display: flex; flex-wrap: wrap; gap: 0.7rem; align-items: flex-end; }
.filter-group { display: flex; flex-direction: column; gap: 0.25rem; }
.filter-group label { font-size: 0.72rem; font-weight: 600; color: var(--text-muted); }
.filter-group select, .filter-group input {
  padding: 0.45rem 0.6rem; border: 1.5px solid var(--border); border-radius: 0.45rem;
  font-family: inherit; font-size: 0.85rem;
  background: var(--bg-card); color: var(--text);
  min-width: 130px;
}
.filter-group select:focus, .filter-group input:focus { outline: none; border-color: var(--ldb-navy); }
.filter-group-btn { flex-direction: row; gap: 0.4rem; }

/* ===== MULTI-SELECT (ເລືອກໄດ້ຫຼາຍລາຍການ) ===== */
.ms { position: relative; min-width: 150px; }
.ms-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 0.4rem;
  padding: 0.45rem 0.6rem; border: 1.5px solid var(--border); border-radius: 0.45rem;
  background: var(--bg-card); color: var(--text);
  font-family: inherit; font-size: 0.85rem; cursor: pointer; text-align: left;
}
.ms-btn:hover { border-color: var(--ldb-navy); }
.ms.open .ms-btn { border-color: var(--ldb-navy); }
.ms.has-sel .ms-btn { border-color: var(--ldb-navy); font-weight: 600; }
.ms-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-caret { flex: none; font-size: 0.7rem; opacity: 0.7; }
.ms-panel {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 60;
  min-width: 100%; max-width: 320px; max-height: 300px; overflow: auto;
  background: var(--bg-card); border: 1.5px solid var(--border); border-radius: 0.5rem;
  box-shadow: 0 10px 30px rgba(15, 30, 60, 0.18); padding: 0.35rem;
}
.ms.open .ms-panel { display: block; }
.ms-tools { display: flex; gap: 0.3rem; padding: 0.15rem 0.15rem 0.4rem; border-bottom: 1px solid var(--border); margin-bottom: 0.3rem; }
.ms-tool {
  flex: 1; background: transparent; border: 1px solid var(--border); border-radius: 0.35rem;
  padding: 0.25rem; font-family: inherit; font-size: 0.72rem; font-weight: 600;
  color: var(--ldb-navy); cursor: pointer;
}
:root[data-theme="dark"] .ms-tool { color: #9dbdf5; }
.ms-tool:hover { background: var(--hover); }
.ms-opt {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.35rem 0.4rem; border-radius: 0.35rem; cursor: pointer; font-size: 0.83rem;
}
.ms-opt:hover { background: var(--hover); }
.ms-opt input { cursor: pointer; flex: none; }
.ms-opt span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* stat card ທີ່ກົດກັ່ນຕອງໄດ້ */
.stat-click { cursor: pointer; transition: transform 0.12s, box-shadow 0.12s; }
.stat-click:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(15,30,60,0.14); }
.stat-click.stat-on {
  outline: 2.5px solid var(--ldb-navy); outline-offset: -1px;
  background: var(--hover);
}
:root[data-theme="dark"] .stat-click.stat-on { outline-color: #7fb3ff; }

/* ===== VIEW PILLS (3 ມຸມມອງ) ===== */
.view-pills {
  display: flex; flex-wrap: wrap; gap: 0.45rem;
  margin-bottom: 1rem;
}
.view-pill {
  background: var(--bg-card); color: var(--text);
  border: 1.5px solid var(--border); border-radius: 2rem;
  padding: 0.5rem 1.1rem; font-family: inherit; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
}
.view-pill:hover { border-color: var(--ldb-navy); }
.view-pill.active {
  background: var(--ldb-navy); color: #fff; border-color: var(--ldb-navy);
}

/* ===== HERO CARD (ກຣາຟຫຼັກ ມຸມມອງ 01) ===== */
.card-hero {
  border-top: 3px solid var(--ldb-gold);
}
.card-hero .card-header { font-size: 1rem; }

/* ===== MODE SWITCH (ສະຫຼັບໂໝດກຣາຟ) ===== */
.switch-row { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }

.mode-switch {
  display: inline-flex; gap: 0;
  border: 1.5px solid var(--ldb-navy); border-radius: 2rem; overflow: hidden;
}
.mode-btn {
  background: transparent; color: var(--ldb-navy);
  border: none; padding: 0.28rem 0.85rem;
  font-family: inherit; font-size: 0.76rem; font-weight: 700;
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
:root[data-theme="dark"] .mode-switch { border-color: #7fb3ff; }
:root[data-theme="dark"] .mode-btn { color: #9dbdf5; }
.mode-btn.active { background: var(--ldb-navy); color: #fff; }
:root[data-theme="dark"] .mode-btn.active { background: #2a4d94; color: #fff; }

/* ===== BADGES (ສິດລຸ້ນໂຊກ) ===== */
.badge {
  display: inline-block; padding: 0.15rem 0.55rem;
  border-radius: 1rem; font-size: 0.72rem; font-weight: 700;
  white-space: nowrap;
}
.badge-napi { background: rgba(45, 125, 50, 0.12); color: #2d7d32; }
.badge-season { background: rgba(200, 169, 81, 0.18); color: #b8860b; }
.badge-no { background: rgba(198, 40, 40, 0.12); color: #c62828; }
.badge-missing { background: rgba(245, 124, 0, 0.14); color: #e07000; }

.search-input {
  width: 100%; padding: 0.5rem 0.7rem;
  border: 1.5px solid var(--border); border-radius: 0.45rem;
  font-family: inherit; font-size: 0.85rem;
  background: var(--bg-card); color: var(--text);
}
.search-input:focus { outline: none; border-color: var(--ldb-navy); }

/* ===== STAT CARDS ===== */
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.8rem;
  margin: 1rem 0;
}
@media (max-width: 860px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--ldb-navy);
  border-radius: 0.6rem;
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; }
.stat-value { font-size: 1.7rem; font-weight: 700; color: var(--ldb-navy); margin-top: 0.15rem; }
:root[data-theme="dark"] .stat-value { color: #9dbdf5; }

/* ===== UNIT LINKS ===== */
.unit-links { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.unit-link-btn {
  display: inline-flex; align-items: center; gap: 0.3rem;
  border: 1px solid var(--border); border-radius: 0.45rem;
  padding: 0.38rem 0.75rem; font-size: 0.8rem; font-weight: 600;
  color: var(--ldb-navy); text-decoration: none;
  transition: background 0.15s;
}
:root[data-theme="dark"] .unit-link-btn { color: #9dbdf5; }
.unit-link-btn:hover { background: var(--hover); }
.unit-link-btn.unit-link-active {
  background: var(--ldb-navy); color: #fff; border-color: var(--ldb-navy);
}
/* ໜ່ວຍທີ່ບໍ່ມີສິດເປີດ — ສະແດງ ແຕ່ກົດບໍ່ໄດ້ */
.unit-link-btn.unit-link-locked {
  opacity: 0.5; cursor: not-allowed; color: var(--text-muted);
  background: var(--hover); border-style: dashed;
}
.unit-link-btn.unit-link-locked:hover { background: var(--hover); }

/* ກ່ອງຈັບສະຫຼາກ ເມື່ອບໍ່ມີສິດ */
.draw-launch.draw-locked { opacity: 0.6; cursor: not-allowed; }
.draw-launch.draw-locked:hover { transform: none; border-color: var(--border); box-shadow: none; }
:root[data-theme="dark"] .unit-link-btn.unit-link-active { background: #2a4d94; color: #fff; }

/* ===== ປ້າຍສິດຜູ້ໃຊ້ ===== */
.role-badge {
  padding: 0.28rem 0.7rem; border-radius: 1rem;
  font-size: 0.72rem; font-weight: 700; white-space: nowrap;
}
.role-admin { background: var(--ldb-gold); color: #3a2c00; }
.role-user { background: rgba(255,255,255,0.22); color: #fff; border: 1px solid rgba(255,255,255,0.4); }

.alert-info {
  background: rgba(3,105,161,0.08); border: 1px solid rgba(3,105,161,0.35); color: var(--ldb-navy);
  border-radius: 0.5rem; padding: 0.6rem 0.9rem; font-size: 0.83rem;
}
:root[data-theme="dark"] .alert-info { color: #9dbdf5; border-color: #2a4d94; background: rgba(42,77,148,0.18); }

/* ===== ແຈ້ງເຕືອນ ເລກບັນຊີຊ້ຳ ===== */
.dup-warn {
  background: #fff4f4; border: 1px solid #f3b9b9; color: #8a2020;
  border-left: 4px solid #c62828; border-radius: 0.6rem;
  padding: 0.8rem 1rem; margin-bottom: 1rem; font-size: 0.83rem;
}
:root[data-theme="dark"] .dup-warn { background: #3a1414; border-color: #6b2626; color: #f0b8b8; }
.dup-head { font-size: 0.9rem; }
.dup-sub { font-size: 0.76rem; opacity: 0.85; margin-top: 0.3rem; }
.dup-warn code {
  background: rgba(0,0,0,0.07); padding: 0.05rem 0.3rem; border-radius: 0.25rem;
  font-family: 'Noto Sans Lao', monospace; font-size: 0.76rem;
}
:root[data-theme="dark"] .dup-warn code { background: rgba(255,255,255,0.12); }
.dup-list { margin-top: 0.55rem; display: flex; flex-direction: column; gap: 0.45rem; }
.dup-group {
  background: rgba(255,255,255,0.6); border-radius: 0.4rem; padding: 0.4rem 0.55rem;
}
:root[data-theme="dark"] .dup-group { background: rgba(255,255,255,0.06); }
.dup-key { font-size: 0.79rem; font-weight: 700; margin-bottom: 0.2rem; }
.dup-item {
  display: grid; grid-template-columns: minmax(140px,auto) 1fr auto; gap: 0.6rem;
  font-size: 0.77rem; padding: 0.12rem 0;
}
.dup-acc { font-family: 'Noto Sans Lao', monospace; font-weight: 600; }
.dup-actions {
  display: flex; flex-wrap: wrap; gap: 0.7rem; align-items: center;
  margin-top: 0.6rem; padding-top: 0.55rem; border-top: 1px solid rgba(198,40,40,0.2);
}
.dup-toggle { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; font-weight: 600; }
.dup-toggle input { cursor: pointer; width: 15px; height: 15px; }

/* ແຖວທີ່ຊ້ຳ ໃນຖານຂໍ້ມູນດິບ */
tbody tr.row-dup { background: rgba(198, 40, 40, 0.07); }
tbody tr.row-dup:hover { background: rgba(198, 40, 40, 0.13); }
.dup-tag {
  background: #c62828; color: #fff; border-radius: 0.8rem;
  padding: 0.02rem 0.4rem; font-size: 0.66rem; font-weight: 700;
}

/* ===== ແຖບການກັ່ນຕອງທີ່ກຳລັງໃຊ້ ===== */
.active-filters {
  display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center;
  margin-bottom: 1rem;
}
.af-label { font-size: 0.78rem; font-weight: 700; color: var(--text-muted); }
.filter-chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: var(--ldb-navy); color: #fff;
  border-radius: 2rem; padding: 0.3rem 0.5rem 0.3rem 0.8rem;
  font-size: 0.78rem; font-weight: 600;
}
.filter-chip .chip-x {
  cursor: pointer; font-weight: 700; line-height: 1;
  background: rgba(255,255,255,0.25); border-radius: 50%;
  width: 16px; height: 16px; display: inline-flex; align-items: center; justify-content: center;
}
.filter-chip .chip-x:hover { background: rgba(255,255,255,0.5); }
.chip-clear {
  background: transparent; border: 1px solid var(--border); color: var(--text-muted);
  border-radius: 2rem; padding: 0.3rem 0.8rem; font-family: inherit;
  font-size: 0.76rem; font-weight: 600; cursor: pointer;
}
.chip-clear:hover { background: var(--hover); }

/* legend / ກຣາຟ ທີ່ກົດກັ່ນຕອງໄດ້ */
.chart-legend-item.pickable { cursor: pointer; padding: 0.1rem 0.35rem; border-radius: 0.35rem; }
.chart-legend-item.pickable:hover { background: var(--hover); }
.chart-legend-item.picked { background: var(--hover); outline: 1.5px solid var(--ldb-navy); }
.chart-hint { font-size: 0.7rem; color: var(--text-muted); font-weight: 400; }

/* ===== TABLES ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
thead th {
  background: var(--ldb-navy); color: #fff;
  padding: 0.5rem 0.6rem; text-align: left; font-weight: 600;
  white-space: nowrap; position: sticky; top: 0;
}
tbody td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--hover); }
.row-total { font-weight: 700; background: var(--hover); }

/* ຫົວຖັນທີ່ກົດຮຽງໄດ້ */
.th-sortable { cursor: pointer; user-select: none; }
.th-sortable:hover { background: #00246b; }
.th-sort-idle { opacity: 0.45; }
.th-active { background: #00246b; }

/* ແຖວທີ່ກາງອອກໄດ້ */
.row-expandable { cursor: pointer; }
.caret { display: inline-block; width: 0.8rem; color: var(--ldb-navy); font-size: 0.7rem; }
:root[data-theme="dark"] .caret { color: #9dbdf5; }
.row-sub > td { background: var(--hover); padding: 0.7rem 1rem !important; }
.row-sub:hover { background: var(--hover); }
.sub-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 760px) { .sub-grid { grid-template-columns: 1fr; } }
.sub-title { font-size: 0.78rem; font-weight: 700; color: var(--ldb-navy); margin-bottom: 0.3rem; }
:root[data-theme="dark"] .sub-title { color: #9dbdf5; }
.sub-table { font-size: 0.78rem; }
.sub-table thead th {
  background: transparent; color: var(--text-muted);
  border-bottom: 1px solid var(--border); position: static;
  padding: 0.25rem 0.45rem; font-size: 0.72rem;
}
.sub-table tbody td { padding: 0.28rem 0.45rem; }

/* progress bar ເປົ້າໝາຍ */
.progress-wrap {
  background: var(--border); border-radius: 1rem;
  height: 8px; min-width: 70px; overflow: hidden;
}
.progress-bar { height: 100%; background: #2d7d32; border-radius: 1rem; }

/* ===== CHART LEGEND ===== */
.chart-legend { display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; justify-content: center; }
.chart-legend-item { display: flex; align-items: center; gap: 0.3rem; font-size: 0.76rem; }
.chart-legend-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* ===== ALERTS + TOAST ===== */
.alert-warning {
  background: #fff8e6; border: 1px solid #f0d48a; color: #8a6d1a;
  border-radius: 0.5rem; padding: 0.6rem 0.9rem; font-size: 0.85rem;
}
:root[data-theme="dark"] .alert-warning { background: #3a3312; border-color: #6b5c22; color: #e8d48a; }
#toast-container {
  position: fixed; bottom: 1.2rem; right: 1.2rem; z-index: 1000;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.toast {
  background: #1f2937; color: #fff;
  padding: 0.65rem 1.1rem; border-radius: 0.5rem;
  font-size: 0.85rem; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  animation: toastIn 0.25s ease;
}
.toast.error { background: #c62828; }
.toast.warning { background: #f57c00; }
.toast.success { background: #2d7d32; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.fade-in { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.text-muted { color: var(--text-muted); }

/* ===== CARD ຮູບ ຜະລິດຕະພັນ / ເຄື່ອງຊຳລ້ວຍ ===== */
.img-card-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.8rem;
}
.img-card {
  border: 1px solid var(--border); border-radius: 0.6rem;
  padding: 0.8rem 0.6rem; text-align: center; background: var(--bg-card);
  transition: transform 0.15s, box-shadow 0.15s;
}
.img-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.img-card img { width: 84px; height: 84px; object-fit: contain; margin: 0 auto 0.5rem; display: block; }
.img-card .ic-fallback {
  width: 84px; height: 84px; margin: 0 auto 0.5rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--hover); border-radius: 0.5rem; font-size: 2.2rem;
}
.img-card .ic-name { font-size: 0.82rem; font-weight: 600; color: var(--ldb-navy); min-height: 2.2em; }
:root[data-theme="dark"] .img-card .ic-name { color: #9dbdf5; }
.img-card .ic-count { font-size: 1.4rem; font-weight: 700; color: var(--text); margin-top: 0.2rem; }
.img-card .ic-unit { font-size: 0.72rem; font-weight: 400; color: var(--text-muted); }

/* ===== ກ່ອງບອກສາເຫດຮູບບໍ່ຂຶ້ນ (ເຫັນສະເພາະ admin) ===== */
.img-diag {
  margin-top: 1rem; padding: 0.8rem 1rem;
  background: #fff8e6; border: 1px solid #f0d48a; color: #8a6d1a;
  border-radius: 0.6rem; font-size: 0.82rem;
}
:root[data-theme="dark"] .img-diag { background: #3a3312; border-color: #6b5c22; color: #e8d48a; }
.img-diag-names { margin-top: 0.35rem; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.img-diag-names code {
  background: rgba(0,0,0,0.07); padding: 0.15rem 0.5rem; border-radius: 0.3rem;
  font-size: 0.8rem; font-family: 'Noto Sans Lao', monospace;
}
:root[data-theme="dark"] .img-diag-names code { background: rgba(255,255,255,0.12); }
.img-diag code { font-family: 'Noto Sans Lao', monospace; }

/* ລາຍການວັນທີຜິດປົກກະຕິ */
.dw-bad-list { margin-top: 0.45rem; display: flex; flex-direction: column; gap: 0.15rem; }
.dw-bad-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 0.6rem;
  font-size: 0.78rem; padding: 0.18rem 0.4rem;
  background: rgba(0,0,0,0.04); border-radius: 0.3rem;
}
:root[data-theme="dark"] .dw-bad-row { background: rgba(255,255,255,0.07); }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.76rem; }

/* ===== ກ່ອງເລີ່ມຈັບສະຫຼາກ ===== */
.draw-card { border-top-color: #e91e63; }
.draw-launch-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8rem; }
@media (max-width: 860px) { .draw-launch-grid { grid-template-columns: 1fr; } }
.draw-launch {
  border: 1.5px solid var(--border); border-radius: 0.75rem;
  padding: 1rem; text-align: center; cursor: pointer;
  background: linear-gradient(160deg, rgba(3,105,161,0.06), rgba(3,105,161,0.02));
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.draw-launch:hover { transform: translateY(-3px); border-color: var(--ldb-navy); box-shadow: var(--shadow); }
.draw-launch-gold { background: linear-gradient(160deg, rgba(200,169,81,0.16), rgba(200,169,81,0.04)); }
.draw-launch-gold:hover { border-color: var(--ldb-gold); }
.dl-emoji { font-size: 2.2rem; line-height: 1; }
.dl-title { font-size: 1rem; font-weight: 700; color: var(--ldb-navy); margin-top: 0.3rem; }
:root[data-theme="dark"] .dl-title { color: #9dbdf5; }
.dl-sub { font-size: 0.75rem; color: var(--text-muted); }
.dl-prizes { font-size: 0.75rem; margin-top: 0.4rem; color: var(--text); }
.dl-pool { font-size: 0.8rem; font-weight: 700; margin-top: 0.5rem; color: #2d7d32; }
.dl-btn { margin-top: 0.6rem; width: 100%; }

/* ===== ໜ້າຈໍຈັບສະຫຼາກ (full screen) ===== */
.draw-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(200,169,81,0.28), transparent 55%),
    radial-gradient(ellipse at 85% 85%, rgba(0,90,220,0.35), transparent 55%),
    linear-gradient(140deg, #00174d 0%, #002b7a 45%, #001033 100%);
  background-size: cover; background-position: center;
  color: #fff; overflow: hidden;        /* ຊ່ອນຮູບທີ່ລ້ນຂອບຊ້າຍ */
}
.draw-overlay.has-bg::before {
  content: ''; position: absolute; inset: 0;
  background-image: var(--draw-bg);
  background-size: cover; background-position: center;
  opacity: 0.35; pointer-events: none;
}
.confetti-canvas { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.draw-inner { position: relative; z-index: 2; max-width: 1240px; margin: 0 auto; padding: 1.2rem 1.2rem 2rem; }

.draw-topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.draw-title {
  font-size: 1.5rem; font-weight: 700;
  background: linear-gradient(90deg, #ffe9a8, #fff, #ffd766);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 2px 20px rgba(255, 215, 102, 0.25);
}
.draw-top-actions { display: flex; gap: 0.5rem; }
.draw-icon-btn {
  background: rgba(255,255,255,0.14); color: #fff; border: 1px solid rgba(255,255,255,0.28);
  border-radius: 0.5rem; width: 38px; height: 38px; font-size: 1rem; cursor: pointer;
}
.draw-icon-btn:hover { background: rgba(255,255,255,0.28); }

.draw-progress { margin: 0.8rem 0 1rem; font-size: 0.85rem; }
.draw-progress-bar { height: 8px; background: rgba(255,255,255,0.18); border-radius: 1rem; overflow: hidden; margin-top: 0.3rem; }
#drawProgressFill { height: 100%; width: 0%; border-radius: 1rem; background: linear-gradient(90deg, #ffd766, #ffb020); transition: width 0.4s; }

.draw-body { display: grid; grid-template-columns: 1fr 320px; gap: 1.2rem; }
@media (max-width: 900px) { .draw-body { grid-template-columns: 1fr; } }

.draw-stage {
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.16);
  border-radius: 1rem; padding: 1.4rem; text-align: center;
  backdrop-filter: blur(6px);
}
.draw-prize { margin-bottom: 1rem; }
.dp-img { font-size: 4rem; line-height: 1; min-height: 110px; display: flex; align-items: center; justify-content: center; }
.dp-img img { max-height: 150px; max-width: 220px; object-fit: contain; filter: drop-shadow(0 8px 24px rgba(0,0,0,0.45)); }
.dp-name { font-size: 1.5rem; font-weight: 700; color: #ffd766; }
.dp-rank { font-size: 0.9rem; opacity: 0.85; }

.draw-reel {
  margin: 1.2rem auto; padding: 1.4rem 1rem;
  border-radius: 0.9rem; min-height: 150px;
  background: linear-gradient(180deg, rgba(0,0,0,0.35), rgba(0,0,0,0.15));
  border: 2px solid rgba(255,215,102,0.45);
  display: flex; flex-direction: column; justify-content: center;
}
.reel-label { font-size: 0.8rem; letter-spacing: 0.08em; opacity: 0.8; text-transform: uppercase; }
.reel-name {
  font-size: clamp(1.4rem, 4vw, 2.6rem); font-weight: 700; margin: 0.4rem 0;
  min-height: 1.4em; word-break: break-word;
}
.reel-name.spinning { color: #cfe4ff; opacity: 0.9; }
.reel-name.winner { color: #fff; text-shadow: 0 0 26px rgba(255,215,102,0.85); animation: winnerPop 0.5s ease; }
@keyframes winnerPop { 0% { transform: scale(0.6); opacity: 0; } 60% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
.reel-sub { font-size: 0.9rem; opacity: 0.9; }

.draw-countdown {
  font-size: clamp(4rem, 16vw, 9rem); font-weight: 700; color: #ffd766;
  text-shadow: 0 0 40px rgba(255,215,102,0.7); animation: cdPulse 1s ease infinite;
}
@keyframes cdPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.16); } }

.draw-actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; margin-top: 0.6rem; }
.btn-draw {
  background: linear-gradient(90deg, #ffb020, #ffd766); color: #2a1c00;
  border: none; border-radius: 2rem; padding: 0.75rem 1.8rem;
  font-family: inherit; font-size: 1rem; font-weight: 700; cursor: pointer;
  box-shadow: 0 6px 22px rgba(255,176,32,0.4); transition: transform 0.12s;
}
.btn-draw:hover { transform: translateY(-2px); }
.btn-draw:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-draw-ghost {
  background: rgba(255,255,255,0.14); color: #fff;
  border: 1px solid rgba(255,255,255,0.3); box-shadow: none;
}

.draw-winners {
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.16);
  border-radius: 1rem; padding: 1rem; max-height: 70vh; overflow: auto;
}
.dw-head { font-weight: 700; margin-bottom: 0.6rem; color: #ffd766; }
.dw-empty { opacity: 0.6; font-size: 0.85rem; }
.dw-item {
  display: flex; gap: 0.6rem; align-items: center;
  padding: 0.5rem; border-radius: 0.5rem; margin-bottom: 0.4rem;
  background: rgba(255,255,255,0.09); animation: fadeIn 0.35s ease;
  cursor: pointer; transition: background 0.15s, transform 0.12s;
}
.dw-item:hover { background: rgba(255,255,255,0.2); transform: translateX(-2px); }
.dw-arrow { margin-left: auto; opacity: 0.6; font-size: 1.2rem; flex: none; }

/* ---- ລາຍລະອຽດຜູ້ຖືກລາງວັນ ---- */
.winner-detail {
  position: fixed; inset: 0; z-index: 2200;
  background: rgba(0, 8, 26, 0.72); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.wd-box {
  position: relative; width: 100%; max-width: 460px; max-height: 88vh; overflow: auto;
  background: linear-gradient(160deg, #0b2a63, #071a3d);
  border: 1.5px solid rgba(255, 215, 102, 0.55);
  border-radius: 1rem; padding: 1.4rem; color: #fff;
  box-shadow: 0 24px 70px rgba(0,0,0,0.55);
  animation: winnerPop 0.28s ease;
}
.wd-close {
  position: absolute; top: 0.7rem; right: 0.7rem;
  background: rgba(255,255,255,0.15); color: #fff; border: none;
  width: 32px; height: 32px; border-radius: 0.5rem; cursor: pointer; font-size: 0.9rem;
}
.wd-close:hover { background: rgba(255,255,255,0.32); }
.wd-prize { text-align: center; margin-bottom: 0.6rem; }
.wd-prize img { max-height: 92px; max-width: 150px; object-fit: contain; }
.wd-emoji { font-size: 3rem; }
.wd-prize-name { color: #ffd766; font-weight: 700; font-size: 0.92rem; margin-top: 0.3rem; }
.wd-name {
  text-align: center; font-size: 1.3rem; font-weight: 700;
  padding-bottom: 0.8rem; margin-bottom: 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.18);
  word-break: break-word;
}
.wd-row {
  display: flex; justify-content: space-between; gap: 0.8rem;
  padding: 0.42rem 0; border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 0.85rem;
}
.wd-row:last-child { border-bottom: none; }
.wd-k { opacity: 0.75; flex: none; }
.wd-v { text-align: right; font-weight: 600; word-break: break-word; }
.wd-eye {
  background: rgba(255,215,102,0.2); color: #ffd766;
  border: 1px solid rgba(255,215,102,0.45); border-radius: 1rem;
  padding: 0.1rem 0.5rem; font-family: inherit; font-size: 0.7rem;
  cursor: pointer; margin-left: 0.35rem;
}
.wd-eye:hover { background: rgba(255,215,102,0.35); }
.dw-icon { font-size: 1.4rem; flex: none; width: 34px; text-align: center; }
.dw-icon img { width: 32px; height: 32px; object-fit: contain; }
.dw-info { text-align: left; min-width: 0; }
.dw-name { font-size: 0.86rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dw-meta { font-size: 0.72rem; opacity: 0.85; }

@media (max-width: 640px) {
  .logo-sub { display: none; }
  .stat-value { font-size: 1.35rem; }
  .main { padding: 0.8rem 0.6rem 2.5rem; }
  .draw-inner { padding: 0.8rem 0.7rem 2rem; }
  .draw-stage { padding: 1rem 0.7rem; }
}

/* ===== 🎉 ຄົນດີໃຈ PNG — ທ້າຍລະດູການ (ມຸມຊ້າຍລຸ່ມ) ===== */

/* ວາງຢູ່ມຸມຊ້າຍລຸ່ມ — ຍຶດໄປຊ້າຍໃຫ້ພ້ນຊ່ອງລາຍຊື່ */
.celeb-overlay {
  position: absolute;
  bottom: 0;
  left: -280px;                          /* ດັນຊ້າຍຕື່ມ — ຫຼີກຊ່ອງຊື່ຜູ້ໂຊກດີ */
  z-index: 120;
  pointer-events: all;
  will-change: transform, opacity;       /* ແກ້ page shake */
  animation: celebSlideIn 0.5s cubic-bezier(.22,1,.36,1);
}
@keyframes celebSlideIn {
  from { opacity: 0; transform: translateX(-80px) translateY(30px); }
  to   { opacity: 1; transform: translateX(0) translateY(0); }
}
.celeb-overlay.celeb-fade-out {
  animation: celebSlideOut 0.4s ease forwards;
}
@keyframes celebSlideOut {
  to { opacity: 0; transform: translateX(-80px) translateY(20px); }
}

/* Wrapper ຮູບ — ບໍ່ມີ card box */
.celeb-box {
  position: relative;
  display: inline-block;
  cursor: pointer;
  padding: 0;
  background: none;
  border: none;
  box-shadow: none;
}

/* ຮູບ PNG ຄົນດີໃຈ */
.celeb-img-wrap {
  display: block;
  line-height: 0;
}
.celeb-png {
  height: 680px;
  max-height: 88vh;
  width: auto;
  object-fit: contain;
  object-position: bottom;
  display: block;
  will-change: transform;               /* GPU layer — ບໍ່ໃຫ້ layout shift */
  backface-visibility: hidden;          /* ແກ້ໜ້າກະຕຸກ */
  -webkit-backface-visibility: hidden;
  animation: celebBounce 0.7s ease-in-out infinite alternate;
  filter: drop-shadow(0 8px 24px rgba(0,0,0,0.55));
}
@keyframes celebBounce {
  0%   { transform: translateY(0)     translateZ(0) scale(1)    rotate(-1deg); }
  100% { transform: translateY(-12px) translateZ(0) scale(1.03) rotate(1deg);  }
}
.celeb-fallback {
  font-size: 7rem;
  line-height: 1;
  display: block;
  will-change: transform;
  animation: celebBounce 0.7s ease-in-out infinite alternate;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,0.4));
}

/* ຊ່ອງ text ທັງໝົດ — ເຊື່ອງໄວ້ (ຂໍ້ມູນສະແດງໃນ reel ແລ້ວ) */
.celeb-headline,
.celeb-sub,
.celeb-winner-name,
.celeb-hint { display: none; }

/* Sparkles ລອຍຢູ່ຮອບຮູບ */
.celeb-spark {
  position: absolute;
  font-size: 1.4rem;
  animation: sparkFloat linear infinite;
  pointer-events: none;
  z-index: 2;
}
@keyframes sparkFloat {
  0%   { transform: translateY(0)     scale(1);    opacity: 0.9;  }
  50%  { transform: translateY(-28px) scale(1.3);  opacity: 1;    }
  100% { transform: translateY(0)     scale(0.75); opacity: 0.6;  }
}

/* ຈໍນ້ອຍ (mobile) */
@media (max-width: 640px) {
  .celeb-overlay { left: -140px; }
  .celeb-png { height: 420px; max-height: 72vh; }
  .celeb-spark { font-size: 1.1rem; }
}
