/* ============================================================
   Village Management System v3 — Modern UI
   Sidebar layout · Responsive · Light theme · Indigo→Purple
   ============================================================ */

/* ============================================================
   Tickets V3 (Session 35) — แจ้งซ่อม/ร้องเรียน + media gallery + lightbox
   ============================================================ */

/* ── Type toggle on form ── */
.ticket-form .ttype-toggle {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.ticket-form .ttype-opt input { position: absolute; opacity: 0; pointer-events: none; }
.ticket-form .ttype-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; border: 2px solid var(--border, #e5e7eb); border-radius: 12px;
  background: #fff; cursor: pointer; transition: all .15s ease;
}
.ticket-form .ttype-card:hover { border-color: var(--primary, #4f46e5); transform: translateY(-1px); }
.ticket-form .ttype-opt input:checked + .ttype-card {
  border-color: var(--primary, #4f46e5);
  background: linear-gradient(135deg, rgba(99,102,241,.08), rgba(139,92,246,.08));
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.ticket-form .ttype-icon { font-size: 32px; line-height: 1; }
.ticket-form .ttype-card small { display: block; color: var(--muted, #64748b); font-size: 12px; margin-top: 2px; }
@media (max-width: 600px) {
  .ticket-form .ttype-toggle { grid-template-columns: 1fr; }
}

/* Ticket type pill in show page */
.ttype-badge {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; margin-right: 6px; vertical-align: middle;
}

/* Permit info card */
.permit-card {
  background: linear-gradient(135deg, rgba(16,185,129,.04), rgba(5,150,105,.04));
  border-color: rgba(16,185,129,.25);
}
.permit-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin: 14px 0;
}
.permit-row { display: flex; gap: 12px; align-items: flex-start; }
.permit-icon {
  font-size: 24px; line-height: 1;
  width: 40px; height: 40px; border-radius: 10px;
  background: rgba(16,185,129,.12);
  display: grid; place-items: center; flex-shrink: 0;
}
.permit-label { font-size: 12px; color: var(--muted, #64748b); text-transform: uppercase; letter-spacing: .3px; }
.permit-val   { font-size: 14.5px; font-weight: 600; color: var(--text, #1f2937); margin-top: 2px; word-break: break-word; }

.permit-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.permit-actions .btn-success { background: #10b981; border: none; color: #fff; }
.permit-actions .btn-success:hover { background: #059669; }

.permit-approved {
  margin-top: 14px; padding: 12px 16px;
  background: rgba(16,185,129,.1); border-left: 4px solid #10b981;
  border-radius: 8px; font-size: 14px;
}
.permit-rejected {
  margin-top: 14px; padding: 12px 16px;
  background: rgba(239,68,68,.08); border-left: 4px solid #ef4444;
  border-radius: 8px; font-size: 14px;
}

/* ── Multi-file uploader on form ── */
.media-uploader { display: block; }
.media-drop {
  display: flex; align-items: center; gap: 14px;
  width: 100%; padding: 22px; border: 2px dashed var(--border, #cbd5e1);
  border-radius: 12px; background: var(--bg, #f8fafc); cursor: pointer;
  text-align: left; transition: all .15s;
}
.media-drop:hover { border-color: var(--primary, #4f46e5); background: rgba(99,102,241,.04); }
.media-drop.drag-over { border-color: var(--primary, #4f46e5); background: rgba(99,102,241,.08); transform: scale(1.01); }
.media-drop-icon { font-size: 36px; }
.media-hint { font-size: 12px; color: var(--muted, #64748b); margin-top: 4px; }

.media-previews {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  margin-top: 12px;
}
.media-preview {
  position: relative; border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px; overflow: hidden; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.media-thumb {
  position: relative; aspect-ratio: 1 / 1; background: #f1f5f9;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.media-thumb img, .media-thumb video {
  width: 100%; height: 100%; object-fit: cover;
}
.media-thumb-audio { background: linear-gradient(135deg, #fef3c7, #fde68a); }
.media-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.25); color: #fff; font-size: 32px;
  pointer-events: none;
}
.media-meta { padding: 6px 8px; }
.media-name {
  font-size: 12px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.media-size { font-size: 11px; color: var(--muted, #64748b); }
.media-remove {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0,0,0,.65); color: #fff; border: none; cursor: pointer;
  font-size: 12px; display: grid; place-items: center;
  transition: background .12s;
}
.media-remove:hover { background: var(--danger, #dc2626); }

/* ── Attachment gallery on show page ── */
.att-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
.att-tile {
  position: relative; padding: 0; aspect-ratio: 1 / 1;
  border: 1px solid var(--border, #e5e7eb); border-radius: 10px; overflow: hidden;
  background: #f1f5f9; cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.att-tile:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,.12); }
.att-tile img, .att-tile video {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.att-tile-video::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.55), transparent 50%);
  pointer-events: none;
}
.att-play {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(255,255,255,.95); color: #111;
  display: grid; place-items: center; font-size: 18px;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  pointer-events: none;
}
.att-cap {
  position: absolute; left: 8px; right: 8px; bottom: 6px;
  font-size: 11px; color: #fff; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}

.att-audio-list { display: grid; gap: 10px; }
.att-audio {
  padding: 10px 14px; border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px; background: var(--bg, #f8fafc);
}
.att-audio-name { font-size: 13.5px; font-weight: 500; margin-bottom: 6px; }
.att-audio audio { width: 100%; }

.att-doc-list { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.att-doc {
  display: flex; gap: 12px; align-items: center;
  padding: 10px 14px; border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px; text-decoration: none; color: var(--text, #1f2937);
  background: #fff; transition: all .15s;
}
.att-doc:hover { border-color: var(--primary, #4f46e5); transform: translateY(-1px); }
.att-doc small { color: var(--muted, #64748b); font-size: 11px; }

/* ── Lightbox modal — image/video viewer ── */
.lb-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(15, 23, 42, .92);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; padding: 20px;
  animation: lbFadeIn .2s ease;
}
.lb-overlay[hidden] { display: none; }
@keyframes lbFadeIn { from { opacity: 0; } to { opacity: 1; } }

.lb-stage {
  max-width: min(1400px, 95vw); max-height: 80vh;
  display: flex; align-items: center; justify-content: center;
}
.lb-stage img, .lb-stage video {
  max-width: 100%; max-height: 80vh; object-fit: contain;
  border-radius: 8px; box-shadow: 0 12px 48px rgba(0,0,0,.6);
}
.lb-stage video { background: #000; }
.lb-caption {
  margin-top: 14px; color: rgba(255,255,255,.85);
  font-size: 14px; max-width: 90vw; text-align: center;
}
.lb-close {
  position: absolute; top: 16px; right: 16px;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,.15); color: #fff;
  border: none; font-size: 20px; cursor: pointer;
  transition: background .15s;
}
.lb-close:hover { background: rgba(255,255,255,.3); }


/* ─── PEAK-style horizontal top nav (Session 26) ─────────── */
.tn-bar {
  background: var(--card, #fff);
  border-bottom: 1px solid var(--border, #e5e7eb);
  position: sticky; top: 0; z-index: 200;
  font-family: inherit;
}
.tn-row { display: flex; align-items: center; padding: 0 24px; }
.tn-row-top {
  height: 56px; gap: 14px; justify-content: space-between;
  border-bottom: 1px solid var(--border, #f1f5f9);
}
.tn-row-nav {
  min-height: 48px; gap: 4px; overflow: visible;
  background: linear-gradient(180deg, #fbfcfe 0%, #fff 100%);
  position: relative; /* anchor for absolute dropdowns */
}

/* Brand */
.tn-brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; min-width: 0; }
.tn-brand:hover { text-decoration: none; }
.tn-logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: grid; place-items: center; color: #fff;
  font-size: 18px; flex-shrink: 0; overflow: hidden;
}
.tn-logo img { width: 100%; height: 100%; object-fit: cover; }
.tn-brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.tn-brand-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.tn-brand-sub { font-size: 11px; color: var(--muted, #64748b); }

/* Right-side actions */
.tn-actions { display: flex; align-items: center; gap: 8px; }
.tn-search-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; border: 1px solid var(--border, #e5e7eb); background: var(--bg, #f8fafc);
  border-radius: 999px; cursor: pointer; font-size: 13px; color: var(--muted, #6b7280);
}
.tn-search-btn:hover { background: #fff; border-color: #cbd5e1; }
.tn-search-btn kbd {
  font-family: ui-monospace, monospace; font-size: 11px;
  background: #fff; border: 1px solid var(--border); padding: 1px 6px; border-radius: 4px;
}
.tn-search-label { display: inline; }
.tn-icon-btn, .tn-icon-btn-wrap > .tn-icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: 50%;
  background: transparent; border: none; cursor: pointer;
  color: var(--text, #1f2937); position: relative;
}
.tn-icon-btn:hover { background: var(--bg, #f1f5f9); }
.tn-icon-btn-wrap { position: relative; }
.tn-user {
  display: flex; align-items: center; gap: 10px; padding-left: 10px; margin-left: 4px;
  border-left: 1px solid var(--border);
}
.tn-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.tn-user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.tn-user-name { font-size: 13px; font-weight: 600; max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tn-user-role { font-size: 11px; color: var(--muted, #6b7280); }

/* Menu items */
.tn-mobile-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; padding: 0 8px; color: var(--text); }
/* IMPORTANT: overflow MUST be visible so dropdowns don't get clipped */
.tn-items { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; overflow: visible; flex: 1; min-width: 0; }
.tn-item, .tn-sub-item { position: relative; }
.tn-item > a, .tn-item > .tn-trigger {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 14px; height: 38px; border-radius: 8px;
  font-size: 14px; font-weight: 500;
  color: var(--text, #334155); text-decoration: none;
  background: none; border: none; cursor: pointer; white-space: nowrap;
  position: relative;
  transition: background .15s ease, color .15s ease;
}
.tn-item > a:hover, .tn-item > .tn-trigger:hover {
  background: var(--bg, #f1f5f9); text-decoration: none; color: var(--primary, #4f46e5);
}
/* Active state with underline indicator */
.tn-item.active > a, .tn-item.active > .tn-trigger {
  background: var(--brand-soft, #eef2ff); color: var(--primary, #4f46e5); font-weight: 600;
}
.tn-item.active > a::after, .tn-item.active > .tn-trigger::after {
  content: ''; position: absolute; bottom: -8px; left: 14px; right: 14px;
  height: 3px; background: var(--primary, #4f46e5); border-radius: 2px 2px 0 0;
}
/* Open dropdown — show ring around trigger */
.tn-item.open > .tn-trigger {
  background: var(--brand-soft, #eef2ff); color: var(--primary, #4f46e5);
}
.tn-emoji { font-size: 16px; line-height: 1; }
.tn-chev { font-size: 10px; opacity: .55; margin-left: 2px; transition: transform .2s ease; }
.tn-item.open > .tn-trigger > .tn-chev { transform: rotate(180deg); opacity: .9; }

/* ─── Top-level Dropdown ─────────────────────────────── */
/* NOTE: NO transform here — would create a containing block for position:fixed
   children, breaking the nested-submenu portal-style positioning */
.tn-dropdown {
  position: absolute; top: 100%; left: 0; margin-top: 6px;
  width: max-content; min-width: 240px; max-width: min(340px, calc(100vw - 24px));
  max-height: 78vh; overflow-y: auto; overflow-x: hidden;
  background: #fff; border: 1px solid var(--border, #e5e7eb);
  border-radius: 12px; box-shadow: 0 12px 32px rgba(15, 23, 42, .15), 0 2px 6px rgba(15, 23, 42, .06);
  padding: 6px; z-index: 250;
  display: none;
  opacity: 0;
  transition: opacity .15s ease;
}
.tn-item.open > .tn-dropdown {
  display: block; animation: tnFadeIn .15s ease forwards;
}
.tn-item.tn-align-right > .tn-dropdown { left: auto; right: 0; }

@keyframes tnFadeIn {
  to { opacity: 1; }
}

/* Thin, soft scrollbar (only when content overflows) */
.tn-dropdown::-webkit-scrollbar { width: 6px; }
.tn-dropdown::-webkit-scrollbar-track { background: transparent; }
.tn-dropdown::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, .25); border-radius: 999px;
}
.tn-dropdown::-webkit-scrollbar-thumb:hover { background: rgba(99, 102, 241, .45); }
.tn-dropdown { scrollbar-width: thin; scrollbar-color: rgba(99,102,241,.25) transparent; }

/* ─── Sub-items inside dropdown ──────────────────────── */
.tn-sub-item { display: block; position: relative; }
.tn-sub-item > a, .tn-sub-item > .tn-trigger {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border-radius: 8px; font-size: 14px;
  color: var(--text, #1f2937); text-decoration: none;
  background: none; border: none; cursor: pointer; text-align: left;
  transition: background .15s ease, color .15s ease, transform .12s ease;
  position: relative;
}
.tn-sub-item > a:hover, .tn-sub-item > .tn-trigger:hover {
  background: linear-gradient(90deg, rgba(99,102,241,.10), rgba(139,92,246,.06));
  color: var(--primary, #4f46e5);
  text-decoration: none;
}
.tn-sub-item.active > a, .tn-sub-item.active > .tn-trigger {
  background: var(--brand-soft, #eef2ff); color: var(--primary, #4f46e5); font-weight: 600;
}
/* Highlight nested-trigger when its submenu is open */
.tn-sub-item.open > .tn-trigger {
  background: linear-gradient(90deg, rgba(99,102,241,.14), rgba(139,92,246,.08));
  color: var(--primary, #4f46e5);
}
.tn-sub-item.has-children > .tn-trigger::after {
  content: '▸'; margin-left: auto; opacity: .5; font-size: 11px;
  transition: opacity .2s ease, color .2s ease;
}
.tn-sub-item.open.has-children > .tn-trigger::after {
  opacity: 1; color: var(--primary, #4f46e5);
}

/* ─── Nested submenu — SIDEWAYS POP with smart flip (no parent scroll) ─── */
/* Parent dropdown removed scroll cap so sideways nested has room */
.tn-item > .tn-dropdown { max-height: 80vh; }

.tn-sub-item > .tn-dropdown {
  position: fixed;            /* escapes parent overflow:auto */
  top: 0; left: 0;            /* JS sets exact coords on open */
  display: none;
  min-width: 220px; max-width: 280px;
  max-height: 70vh; overflow-y: auto; overflow-x: hidden;
  background: #fff; border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .18);
  padding: 6px; margin: 0;
  z-index: 260;
  opacity: 0; transform: translateX(-4px);
  transition: opacity .15s ease, transform .15s ease;
}
.tn-sub-item.open > .tn-dropdown {
  display: block;
  animation: tnSlideIn .15s ease forwards;
}
.tn-sub-item.tn-flip-left > .tn-dropdown {
  transform: translateX(4px);   /* slide from right when flipped */
}
.tn-sub-item.tn-flip-left.open > .tn-dropdown {
  animation: tnSlideInRev .15s ease forwards;
}
@keyframes tnSlideIn    { to { opacity: 1; transform: translateX(0); } }
@keyframes tnSlideInRev { to { opacity: 1; transform: translateX(0); } }
.tn-sub-item > .tn-dropdown > .tn-sub-item > a,
.tn-sub-item > .tn-dropdown > .tn-sub-item > .tn-trigger {
  font-size: 13.5px; padding: 7px 12px;
}

.tn-divider {
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border, #e5e7eb), transparent);
  margin: 6px 8px;
}

/* Section label inside dropdown — small uppercase */
.tn-section {
  padding: 10px 14px 4px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px;
  color: var(--muted, #94a3b8); text-transform: uppercase;
  user-select: none;
}
.tn-section:first-child { padding-top: 4px; }

/* Subtle separator between top-nav items */
.tn-items > .tn-item + .tn-item { margin-left: 1px; }

/* "ออกจากหมู่บ้าน" button — push to right + distinct red-ish hue */
.tn-item.tn-leave { margin-left: auto; }
.tn-item.tn-leave > a {
  color: var(--danger, #dc2626);
  background: var(--danger-bg, #fef2f2);
  border: 1px solid #fecaca;
}
.tn-item.tn-leave > a:hover {
  background: var(--danger, #dc2626);
  color: #fff;
  border-color: var(--danger, #dc2626);
}
/* Force danger-styling even if .active gets attached (path /villages/* always matches) */
.tn-item.tn-leave.active > a {
  background: var(--danger-bg, #fef2f2) !important;
  color: var(--danger, #dc2626) !important;
  font-weight: 500 !important;
}
.tn-item.tn-leave.active > a::after { display: none !important; }
.tn-item.tn-leave.active > a:hover {
  background: var(--danger, #dc2626) !important;
  color: #fff !important;
}
@media (max-width: 600px) {
  .tn-item.tn-leave { margin-left: 0; margin-top: 12px; }
  .tn-item.tn-leave > a { justify-content: center; }
}

/* Brand gradient on active state (replaces flat brand-soft) */
.tn-item.active > a, .tn-item.active > .tn-trigger {
  background: linear-gradient(135deg, rgba(99,102,241,.12), rgba(139,92,246,.12));
  color: var(--primary, #4f46e5); font-weight: 600;
}

/* Focus ring for keyboard navigation (accessibility) */
.tn-item > a:focus-visible, .tn-item > .tn-trigger:focus-visible,
.tn-sub-item > a:focus-visible, .tn-sub-item > .tn-trigger:focus-visible,
.tn-icon-btn:focus-visible, .tn-search-btn:focus-visible {
  outline: 2px solid var(--primary, #4f46e5);
  outline-offset: 2px;
}

/* Badges on nav items (Session 28) */
.tn-badge {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px; padding: 0 6px;
  background: var(--danger, #dc2626); color: #fff;
  font-size: 11px; font-weight: 700; border-radius: 999px;
  margin-left: 4px;
}
.tn-sub-item .tn-badge { margin-left: auto; }

/* Hide old sidebar/topbar when top nav is in use */
body[data-layout-mode="topnav"] .sidebar,
body[data-layout-mode="topnav"] .sidebar-backdrop,
body[data-layout-mode="topnav"] .topbar { display: none !important; }
body[data-layout-mode="topnav"] .app { display: block !important; }
body[data-layout-mode="topnav"] .main { width: 100%; }
body[data-layout-mode="topnav"] .content { padding: 24px; max-width: 1400px; margin: 0 auto; }

/* ============================================================
   RESPONSIVE — 4 breakpoints
   - desktop (>1200px) : full nav with labels
   - laptop (901-1200) : tighter spacing
   - tablet (601-900)  : icons + short labels, search becomes icon
   - mobile (<=600)    : hamburger drawer with backdrop
   ============================================================ */

/* Laptop — tighter padding so all 7 items fit */
@media (max-width: 1200px) {
  .tn-item > a, .tn-item > .tn-trigger { padding: 9px 10px; }
  .tn-brand-title { max-width: 180px; }
  .tn-search-label { font-size: 12px; }
}

/* Tablet — labels shrink, search becomes icon-only */
@media (max-width: 900px) {
  .tn-row-top { padding: 0 14px; gap: 8px; }
  .tn-row-nav { padding: 0 8px; }
  .tn-brand-sub { display: none; }
  .tn-brand-title { max-width: 160px; font-size: 14px; }
  .tn-search-btn { padding: 7px 10px; }
  .tn-search-label { display: none; }
  .tn-search-btn kbd { display: none; }
  .tn-user-meta { display: none; }
  .tn-item > a, .tn-item > .tn-trigger { padding: 8px 10px; font-size: 13.5px; }
  .tn-emoji { font-size: 15px; }
}

/* Mobile (≤600px) — full drawer overlay */
@media (max-width: 600px) {
  .tn-row-top { height: 52px; padding: 0 10px; }
  .tn-brand-title { max-width: 120px; font-size: 13px; }
  .tn-actions { gap: 4px; }
  .tn-icon-btn { width: 40px; height: 40px; }
  .tn-mobile-toggle {
    display: inline-grid; place-items: center;
    width: 42px; height: 42px;
    border-radius: 50%; background: var(--bg, #f1f5f9);
    transition: background .15s;
  }
  .tn-mobile-toggle:hover { background: var(--border, #e5e7eb); }

  .tn-row-nav { padding: 0; height: auto; background: transparent; border: none; }
  .tn-row-nav .tn-items {
    display: none;
    position: fixed; top: 52px; left: 0; right: 0; bottom: 0;
    background: #fff;
    flex-direction: column; gap: 0; align-items: stretch;
    padding: 16px; overflow-y: auto;
    z-index: 240;
    box-shadow: 0 -4px 30px rgba(0,0,0,.12);
    animation: tnSlideUp .25s ease;
  }
  .tn-row-nav.open .tn-items { display: flex; }

  /* Backdrop overlay */
  .tn-row-nav.open::before {
    content: ''; position: fixed; inset: 52px 0 0 0;
    background: rgba(15, 23, 42, 0.35); z-index: 239;
    animation: tnFadeBackdrop .25s ease;
  }

  .tn-item { width: 100%; }
  .tn-item > a, .tn-item > .tn-trigger {
    width: 100%; justify-content: flex-start; height: 48px;
    padding: 12px 16px; font-size: 15px; border-radius: 10px;
  }
  .tn-item.active > a::after, .tn-item.active > .tn-trigger::after {
    /* swap underline → left border on mobile */
    bottom: auto; top: 0; left: 0; right: auto;
    width: 4px; height: auto; bottom: 0;
    border-radius: 0 4px 4px 0;
  }
  .tn-chev { margin-left: auto !important; }

  .tn-dropdown {
    position: static; box-shadow: none; border: none; margin: 4px 0 4px 16px;
    padding: 0; max-height: none; min-width: 0;
    border-left: 2px solid var(--border, #e5e7eb);
    padding-left: 8px; opacity: 1; transform: none;
  }
  .tn-sub-item > a, .tn-sub-item > .tn-trigger {
    padding: 12px 14px; font-size: 14px; min-height: 44px;
  }
  .tn-sub-item > a:hover { padding-left: 14px; /* disable slide on touch */ }
  /* Mobile: nested back to inline accordion (sideways pop doesn't fit small screens) */
  .tn-sub-item > .tn-dropdown {
    position: static !important;
    left: auto !important; top: auto !important;
    width: auto !important; min-width: 0; max-width: none;
    max-height: none; overflow: visible;
    background: transparent !important; border: none !important; box-shadow: none !important;
    padding-left: 8px; margin: 4px 0 4px 16px;
    transform: none !important;
  }

  /* User card hidden in mobile top — accessed via menu */
  .tn-user .tn-avatar { width: 32px; height: 32px; font-size: 12px; }
}

/* Smaller phones */
@media (max-width: 380px) {
  .tn-brand-title { max-width: 90px; font-size: 12px; }
  .tn-search-btn { display: none; } /* save space — Ctrl-K still works */
}

/* Animations */
@keyframes tnSlideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes tnFadeBackdrop {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Prevent body scroll when mobile drawer open */
body.tn-drawer-open { overflow: hidden; }

/* Dark theme */
html[data-theme="dark"] .tn-bar { background: #0f172a; border-color: #1e293b; }
html[data-theme="dark"] .tn-row-nav { background: #0b1220; }
html[data-theme="dark"] .tn-search-btn { background: #1e293b; border-color: #334155; color: #cbd5e1; }
html[data-theme="dark"] .tn-search-btn kbd { background: #0f172a; border-color: #334155; color: #cbd5e1; }
html[data-theme="dark"] .tn-item > a, html[data-theme="dark"] .tn-item > .tn-trigger { color: #e2e8f0; }
html[data-theme="dark"] .tn-item > a:hover, html[data-theme="dark"] .tn-item > .tn-trigger:hover { background: #1e293b; }
html[data-theme="dark"] .tn-item.active > a, html[data-theme="dark"] .tn-item.active > .tn-trigger { background: #312e81; color: #c7d2fe; }
html[data-theme="dark"] .tn-dropdown { background: #1e293b; border-color: #334155; }
html[data-theme="dark"] .tn-sub-item > a { color: #e2e8f0; }
html[data-theme="dark"] .tn-sub-item > a:hover { background: #334155; }
html[data-theme="dark"] .tn-icon-btn { color: #e2e8f0; }
html[data-theme="dark"] .tn-icon-btn:hover { background: #1e293b; }
html[data-theme="dark"] .tn-divider { background: #334155; }
/* ────────────────────── End top-nav block ───────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Sarabun:wght@400;500;600;700&display=swap');

* { box-sizing: border-box; }
*::before, *::after { box-sizing: border-box; }

:root {
  /* Brand */
  --brand-1:  #6366f1;
  --brand-2:  #8b5cf6;
  --brand-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --brand-soft: #eef2ff;

  /* Session 63.4: aliases — many components reference --primary / --accent
     but they were never defined in :root → CSS errors / fallbacks everywhere.
     Now mapped to brand colors */
  --primary:      #4f46e5;
  --primary-700:  #4338ca;
  --primary-soft: #eef2ff;
  --accent:       #06c755;       /* LINE green for CTAs */
  --accent-soft:  #dcfce7;

  /* Neutrals */
  --bg:        #f5f7fb;
  --surface:   #ffffff;
  --surface-2: #f9fafb;
  --border:    #e5e7eb;
  --border-strong: #d1d5db;
  --text:      #0f172a;
  --text-2:    #475569;
  --muted:     #94a3b8;

  /* States */
  --success:   #16a34a;
  --success-bg:#dcfce7;
  --warning:   #d97706;
  --warning-bg:#fef3c7;
  --danger:    #dc2626;
  --danger-bg: #fee2e2;
  --info:      #0284c7;
  --info-bg:   #e0f2fe;

  /* Effects */
  --shadow-sm: 0 1px 2px rgba(15,23,42,.04);
  --shadow:    0 4px 14px rgba(15,23,42,.06);
  --shadow-lg: 0 12px 32px rgba(15,23,42,.10);
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;

  /* Layout */
  --sidebar-w: 240px;
}

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Sarabun', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

img { max-width: 100%; }

/* =====================================================
   Layout: Sidebar + Main
   ===================================================== */
.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar (desktop) */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  padding: 22px 22px 18px;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand .logo {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--brand-grad);
  display: grid; place-items: center;
  color: #fff; font-size: 18px;
  box-shadow: 0 4px 12px rgba(99,102,241,.45);
}
.sidebar nav {
  padding: 12px 10px;
  flex: 1;
  overflow-y: auto;
}
.sidebar nav .group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #64748b;
  padding: 14px 12px 6px;
  font-weight: 600;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  margin: 2px 0;
  color: #cbd5e1;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.sidebar nav a:hover {
  background: rgba(255,255,255,.06);
  color: #fff;
  text-decoration: none;
}
.sidebar nav a.active {
  background: var(--brand-grad);
  color: #fff;
  box-shadow: 0 4px 14px rgba(99,102,241,.4);
}
.sidebar nav a svg {
  width: 18px; height: 18px; flex: 0 0 18px;
}
.sidebar .user-card {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex; gap: 12px; align-items: center;
}
.sidebar .user-card .avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--brand-grad);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px;
}
.sidebar .user-card .info { flex: 1; min-width: 0; }
.sidebar .user-card .info .name { color: #fff; font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .user-card .info .role { font-size: 11px; color: #64748b; }
.sidebar .user-card .logout {
  color: #94a3b8; padding: 6px;
  border-radius: 8px;
}
.sidebar .user-card .logout:hover {
  color: #fca5a5; background: rgba(255,255,255,.04); text-decoration: none;
}

/* Main */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.topbar .menu-toggle {
  display: none;
  background: none; border: 0;
  font-size: 22px; cursor: pointer; color: var(--text-2);
  padding: 4px 8px;
}
.content {
  padding: 28px;
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

/* =====================================================
   Mobile responsive
   ===================================================== */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 50;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.5);
    z-index: 40;
  }
  .sidebar.open ~ .sidebar-backdrop { display: block; }
  .topbar .menu-toggle { display: inline-block; }
  .content { padding: 20px 16px; }
}

/* =====================================================
   Cards / Surface
   ===================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card.compact { padding: 16px 18px; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.card-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}
.card-header .subtitle { color: var(--muted); font-size: 13px; }

/* =====================================================
   Page Header
   ===================================================== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 22px;
}
.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 4px 0;
  letter-spacing: -.01em;
}
.page-header .subtitle {
  color: var(--text-2);
  font-size: 14px;
}
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* =====================================================
   Stat tiles (Dashboard)
   ===================================================== */
.stats {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  margin-bottom: 24px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.stat::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 80px; height: 80px;
  background: var(--brand-grad);
  opacity: .1;
  border-radius: 50%;
  transform: translate(28px,-28px);
}
.stat .label {
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
}
.stat .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}
.stat .meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.stat-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand-1);
  display: grid; place-items: center;
  margin-bottom: 12px;
}

/* =====================================================
   Buttons
   ===================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition: transform .05s ease, background .15s ease, box-shadow .15s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--brand-grad);
  color: #fff;
  box-shadow: 0 4px 14px rgba(99,102,241,.32);
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(99,102,241,.45); text-decoration: none; }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); text-decoration: none; }
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #b91c1c; text-decoration: none; }
.btn-ghost {
  background: transparent;
  color: var(--text-2);
  padding: 6px 10px;
  font-weight: 500;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* =====================================================
   Forms
   ===================================================== */
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text);
}
.form-group label .req { color: var(--danger); margin-left: 2px; }
.form-group input[type=text],
.form-group input[type=email],
.form-group input[type=number],
.form-group input[type=password],
.form-group input[type=date],
.form-group input[type=file],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.form-group textarea { min-height: 120px; resize: vertical; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--brand-1);
  box-shadow: 0 0 0 3px rgba(99,102,241,.18);
}
.form-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 12px; margin-top: 5px; }
.field-error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }

.checkbox-group {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  user-select: none;
}
.checkbox-group input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand-1); }
.checkbox-group label { font-weight: 500; margin: 0; cursor: pointer; }

.row-fields { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) { .row-fields { grid-template-columns: 1fr; } }

/* =====================================================
   Alerts / Flash
   ===================================================== */
.alert {
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 14px;
  display: flex; align-items: flex-start; gap: 10px;
  border: 1px solid;
}
.alert .icon { flex: 0 0 18px; margin-top: 1px; }
.alert-error    { background: var(--danger-bg); color: #991b1b; border-color: #fecaca; }
.alert-success  { background: var(--success-bg); color: #14532d; border-color: #bbf7d0; }
.alert-info     { background: var(--info-bg);    color: #075985; border-color: #bae6fd; }
.alert-warning  { background: var(--warning-bg); color: #78350f; border-color: #fde68a; }

/* =====================================================
   Tables
   ===================================================== */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 14px;
}
table.data th, table.data td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data th {
  background: var(--surface-2);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-2);
  font-weight: 600;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--surface-2); }
table.data input[type=text],
table.data input[type=number] {
  padding: 6px 10px;
  font-size: 13.5px;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  background: var(--surface);
}
table.data input:focus {
  outline: none;
  border-color: var(--brand-1);
  box-shadow: 0 0 0 2px rgba(99,102,241,.15);
}
.empty {
  color: var(--muted);
  padding: 36px;
  text-align: center;
  font-size: 14px;
}

/* Tags / Badges */
.tag {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  background: var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}
.tag.create      { background: var(--success-bg); color: #166534; }
.tag.update      { background: var(--warning-bg); color: #92400e; }
.tag.soft_delete { background: var(--danger-bg);  color: #991b1b; }
.tag.login       { background: var(--brand-soft); color: var(--brand-1); }
.tag.logout      { background: #f3e8ff; color: #6b21a8; }
.tag.role-super  { background: linear-gradient(135deg,#a78bfa,#6366f1); color: #fff; }
.tag.role-village{ background: var(--brand-soft); color: var(--brand-1); }

/* Progress bar */
.progress {
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  height: 8px;
  width: 160px;
}
.progress > span {
  display: block;
  height: 100%;
  background: var(--brand-grad);
  transition: width .25s ease;
}

/* =====================================================
   Login / Auth pages
   ===================================================== */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 12% 18%, rgba(99,102,241,.16) 0, transparent 35%),
    radial-gradient(circle at 90% 88%, rgba(139,92,246,.20) 0, transparent 40%);
}
.auth-card {
  width: 420px; max-width: 100%;
  padding: 36px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.auth-card .auth-logo {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--brand-grad);
  display: grid; place-items: center;
  color: #fff; font-size: 26px;
  margin-bottom: 16px;
  box-shadow: 0 8px 22px rgba(99,102,241,.4);
}
.auth-card h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
}
.auth-card .sub {
  color: var(--text-2);
  font-size: 14px;
  margin-bottom: 22px;
}
.auth-link {
  text-align: center; margin-top: 14px;
  font-size: 13px; color: var(--text-2);
}
.auth-link a { color: var(--brand-1); font-weight: 600; }

/* =====================================================
   Lists / Items
   ===================================================== */
.announce-list { list-style: none; padding: 0; margin: 0; }
.announce-list li {
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.announce-list .pin {
  display: inline-block;
  background: var(--warning-bg); color: #92400e;
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  margin-right: 8px; font-weight: 600;
}
.announce-list h3 { margin: 0 0 4px; font-size: 16px; }
.announce-list .meta { color: var(--muted); font-size: 12px; }
.announce-list .body { margin-top: 8px; color: var(--text-2); white-space: pre-wrap; }

/* Audit JSON */
table.data td.json {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 11.5px;
  color: var(--text-2);
  max-width: 360px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Misc */
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.text-muted { color: var(--muted); }
.text-secondary { color: var(--text-2); }
.right { text-align: right; }
.center { text-align: center; }
.flex { display: flex; gap: 8px; align-items: center; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

.copy-link {
  display: flex; align-items: center; gap: 8px;
  padding: 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: var(--surface-2);
  margin: 12px 0;
}
.copy-link input {
  flex: 1; border: 0; background: transparent;
  font-family: ui-monospace, monospace; font-size: 12.5px;
  outline: none;
}

/* =====================================================
   SPA-like nav: top progress bar
   ===================================================== */
.top-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  box-shadow: 0 0 10px rgba(99,102,241,.5);
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
}
.content {
  transition: opacity .15s ease;
}

/* =====================================================
   Toast notifications
   ===================================================== */
.toast-root {
  position: fixed;
  top: 20px; right: 20px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; font-weight: 500;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  transform: translateX(110%);
  opacity: 0;
  transition: all .25s cubic-bezier(.4,0,.2,1);
  min-width: 240px;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary); flex: 0 0 8px;
}
.toast-success .dot { background: var(--success); }
.toast-error   .dot { background: var(--danger); }
.toast-warning .dot { background: var(--warning); }
.toast-info    .dot { background: var(--info); }

/* =====================================================
   Confirm Modal
   ===================================================== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity .2s ease;
  padding: 20px;
}
.modal-backdrop.show { opacity: 1; }
.modal-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 28px;
  max-width: 420px; width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  transform: scale(.95);
  transition: transform .2s ease;
}
.modal-backdrop.show .modal-card { transform: scale(1); }
.modal-icon {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--brand-soft);
  display: grid; place-items: center;
  font-size: 30px;
  margin: 0 auto 16px;
}
.modal-icon.danger { background: var(--danger-bg); }
.modal-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
}
.modal-message {
  color: var(--text-2);
  margin: 0 0 22px;
  font-size: 14px;
  line-height: 1.5;
}
.modal-actions {
  display: flex; gap: 10px; justify-content: center;
}
.modal-actions .btn { min-width: 100px; }

/* =====================================================
   Save indicator (form autosave)
   ===================================================== */
.save-indicator {
  position: fixed;
  top: 16px; right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  display: inline-flex; align-items: center; gap: 6px;
  z-index: 9990;
  transition: all .25s ease;
}
.save-indicator.state-saving { color: var(--brand-1); }
.save-indicator.state-saved  { color: var(--success); }
.save-indicator.state-error  { color: var(--danger); }
.save-indicator.hide { opacity: 0; transform: translateY(-8px); }

/* =====================================================
   Bulk autosave row indicators
   ===================================================== */
table.houses-data tbody tr.row-saving td:first-child::after {
  content: '⏳';
  margin-left: 6px;
  font-size: 12px;
  opacity: .7;
}
table.houses-data tbody tr.row-saved td:first-child::after {
  content: '✓';
  color: var(--success);
  margin-left: 6px;
  font-size: 14px;
  font-weight: 700;
  animation: fadeOut .3s ease 1.4s forwards;
}
table.houses-data tbody tr.row-error td {
  background: var(--danger-bg) !important;
}
table.houses-data tbody tr.row-dirty td {
  background: rgba(245,158,11,.06) !important;
}
@keyframes fadeOut { to { opacity: 0; } }

/* =====================================================
   Global Search Palette (Ctrl+K)
   ===================================================== */
.search-palette {
  position: fixed; inset: 0;
  z-index: 1500;
  opacity: 0;
  transition: opacity .15s ease;
  display: grid; place-items: start center;
  padding-top: 80px;
}
.search-palette.show { opacity: 1; }
.palette-backdrop {
  position: absolute; inset: 0;
  background: rgba(15,23,42,.6);
  backdrop-filter: blur(6px);
}
.palette-card {
  position: relative;
  width: 640px; max-width: calc(100% - 32px);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: translateY(-12px);
  transition: transform .2s ease;
}
.search-palette.show .palette-card { transform: translateY(0); }
.palette-input-wrap {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.palette-icon { font-size: 18px; opacity: .7; }
.palette-input {
  flex: 1; border: 0; outline: 0; background: transparent;
  font-size: 16px; font-family: inherit; color: var(--text);
}
.palette-input::placeholder { color: var(--muted); }
.palette-shortcut {
  font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 7px;
  border-radius: 6px;
  color: var(--text-2);
  font-weight: 600;
}
.palette-results {
  max-height: 420px;
  overflow-y: auto;
  padding: 6px;
}
.palette-empty {
  text-align: center;
  padding: 36px 20px;
  color: var(--muted);
  font-size: 14px;
}
.palette-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  transition: background .12s;
}
.palette-item:hover, .palette-item.is-active {
  background: var(--brand-soft);
  text-decoration: none;
}
.palette-item-icon {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  font-size: 16px;
  background: var(--surface-2);
  border-radius: 8px;
  flex: 0 0 32px;
}
.palette-item.is-active .palette-item-icon {
  background: var(--brand-grad); color: #fff;
}
.palette-item-text { flex: 1; min-width: 0; }
.palette-item-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-item-sub { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-item-badge {
  font-size: 10.5px; font-weight: 600;
  padding: 3px 8px;
  background: var(--surface-2);
  border-radius: 999px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.palette-item.is-active .palette-item-badge {
  background: var(--brand-1); color: #fff;
}

/* Topbar search button */
.topbar-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  font-family: inherit;
  transition: all .12s;
}
.topbar-search:hover {
  background: var(--brand-soft);
  color: var(--brand-1);
  border-color: var(--brand-1);
}
.topbar-search kbd {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10.5px;
  font-family: ui-monospace, monospace;
  color: var(--text-2);
}
@media (max-width: 700px) {
  .topbar-search span { display: none; }
  .topbar-search kbd { display: none; }
}

/* =====================================================
   DARK MODE
   ===================================================== */
html[data-theme="dark"] {
  --bg:        #0b1020;
  --surface:   #131a2c;
  --surface-2: #1b2540;
  --border:    #2a3656;
  --border-strong: #3a4a73;
  --text:      #e6eaf5;
  --text-2:    #a8b2cf;
  --muted:     #6b7796;

  /* Session 63.4: dark-mode primary/accent overrides */
  --primary:      #818cf8;
  --primary-700:  #6366f1;
  --primary-soft: #1f2a55;
  --accent:       #4ade80;
  --accent-soft:  #14532d;

  --brand-soft: #1f2a55;
  --success-bg:#103823;
  --warning-bg:#3b2a08;
  --danger-bg: #3b1216;
  --info-bg:   #0c2c45;

  --shadow:    0 4px 14px rgba(0,0,0,.35);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.45);
}
html[data-theme="dark"] .sidebar { background: #060a16; }
html[data-theme="dark"] .topbar { background: var(--surface); border-color: var(--border); }
html[data-theme="dark"] .palette-input { color: var(--text); }
html[data-theme="dark"] .skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--border) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
}

/* Theme toggle button */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-2);
  transition: all .15s;
}
.theme-toggle:hover { background: var(--brand-soft); color: var(--brand-1); }

/* Sidebar nav badge */
.sidebar nav a .nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 20px; padding: 0 7px;
  background: var(--brand-grad);
  color: #fff;
  font-size: 11px; font-weight: 700;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(99,102,241,.4);
  margin-left: auto;
}
.sidebar nav a.active .nav-badge {
  background: rgba(255,255,255,.25);
  box-shadow: none;
}

/* Skeleton placeholder (for SPA loading) */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--border) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  border-radius: 8px;
  animation: skeleton-pulse 1.4s ease infinite;
  display: inline-block;
}
.skeleton-text { height: 14px; width: 100%; margin-bottom: 8px; }
.skeleton-text.short { width: 40%; }
.skeleton-text.medium { width: 70%; }
.skeleton-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}
@keyframes skeleton-pulse {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* =====================================================
   Session 15 — UX/UI Refresh (Accessibility + Senior-friendly)
   ===================================================== */

/* Bigger base typography for readability */
html, body { font-size: 16px; line-height: 1.7; }
h1 { font-size: 26px; line-height: 1.3; letter-spacing: -.01em; }
h2 { font-size: 20px; line-height: 1.35; }
h3 { font-size: 17px; line-height: 1.4; }
.subtitle { font-size: 14.5px; color: var(--text-2); }

/* Larger touch targets */
.btn, button.btn, a.btn {
  min-height: 44px;
  padding: 10px 18px;
  font-size: 15px;
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: .01em;
}
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 13.5px; }
.btn-xl { min-height: 52px; padding: 14px 26px; font-size: 17px; border-radius: 12px; }

/* Inputs - bigger, calmer, clear focus ring */
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="tel"],
input[type="search"], input[type="url"], select, textarea {
  min-height: 44px;
  padding: 10px 14px;
  font-size: 15px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-1);
  box-shadow: 0 0 0 4px rgba(99,102,241,.18);
}

/* Form labels — bigger, more visible */
.form-group label, label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  display: block;
}

/* Card refresh */
.card {
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.card-header h2 { font-size: 17px; font-weight: 700; }

/* Stack/cluster utility primitives */
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { gap: 8px; } .stack-lg { gap: 22px; }
.cluster { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* =========================================================
   Wizard (4-step progress + content)
   ========================================================= */
.wizard { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.wiz-progress {
  display: flex; padding: 18px 20px; gap: 10px;
  background: linear-gradient(135deg, var(--brand-soft) 0%, #fff 100%);
  border-bottom: 1px solid var(--border);
}
.wiz-step {
  flex: 1; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  font-size: 13.5px; color: var(--text-2);
  background: rgba(255,255,255,.7);
  transition: all .2s;
}
.wiz-step .num {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-2); color: var(--text-2);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.wiz-step.active { background: #fff; color: var(--text); box-shadow: var(--shadow-sm); }
.wiz-step.active .num { background: var(--brand-grad); color: #fff; }
.wiz-step.done .num { background: var(--success); color: #fff; }
.wiz-step.done { color: var(--success); }
.wiz-step.done .num::before { content: "✓"; font-size: 16px; }
.wiz-step.done .num span { display: none; }
.wiz-body { padding: 28px; }
.wiz-footer {
  display: flex; gap: 10px; justify-content: space-between;
  padding: 16px 20px; border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.wiz-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.wiz-tile {
  background: #fff; border: 2px solid var(--border); border-radius: 14px;
  padding: 18px; cursor: pointer; transition: all .15s;
  display: flex; flex-direction: column; gap: 6px;
  text-align: left; min-height: 96px;
}
.wiz-tile:hover { border-color: var(--brand-1); transform: translateY(-2px); box-shadow: var(--shadow); }
.wiz-tile.selected { border-color: var(--brand-1); background: var(--brand-soft); }
.wiz-tile .tile-num { font-size: 11px; color: var(--text-2); font-weight: 700; letter-spacing: .04em; }
.wiz-tile .tile-name { font-size: 16px; font-weight: 700; color: var(--text); }
.wiz-tile .tile-desc { font-size: 12.5px; color: var(--text-2); }

/* =========================================================
   Autocomplete combobox
   ========================================================= */
.combobox { position: relative; }
.combobox input { width: 100%; padding-right: 38px; }
.combobox::after {
  content: "▾"; position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  pointer-events: none; color: var(--muted); font-size: 12px;
}
/* =====================================================
   Session 23 — Collapsible sidebar groups (cleaner UI)
   ===================================================== */
.sidebar nav .nav-group { margin: 4px 0; }
.sidebar nav .nav-group > .group-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; font-size: 12.5px; font-weight: 700;
  color: #94a3b8; text-transform: none; letter-spacing: 0;
  cursor: pointer; user-select: none;
  border-radius: 8px;
  transition: background .15s, color .15s;
  margin: 2px 8px;
}
.sidebar nav .nav-group > .group-header:hover { background: rgba(255,255,255,.05); color: #cbd5e1; }
.sidebar nav .nav-group > .group-header .icon-chevron {
  margin-left: auto; transition: transform .2s;
  font-size: 11px; opacity: .6;
}
.sidebar nav .nav-group.collapsed > .group-header .icon-chevron { transform: rotate(-90deg); }
.sidebar nav .nav-group.collapsed > .group-body { display: none; }
.sidebar nav .nav-group > .group-body { display: block; padding: 0; }
.sidebar nav .nav-group > .group-header .group-icon {
  width: 22px; height: 22px; display: grid; place-items: center;
  background: rgba(255,255,255,.08); border-radius: 6px;
  font-size: 14px; flex-shrink: 0;
}
/* When group is "active" (contains active link), highlight header */
.sidebar nav .nav-group.has-active > .group-header { color: #fff; background: rgba(99,102,241,.12); }
.sidebar nav .nav-group.has-active > .group-header .group-icon { background: var(--brand-1); color: #fff; }

/* Hide inline dropdown — JS will portal it to body */
.combobox .options {
  position: fixed;
  background: var(--surface); border: 1.5px solid var(--brand-1);
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(15,23,42,.25);
  z-index: 99999;          /* above modal/sidebar */
  max-height: 360px; overflow: auto; display: none;
  min-width: 280px; max-width: 90vw;
}
.combobox.open .options { display: block; }
html[data-theme="dark"] .combobox .options { background: var(--surface-2); }
.combobox .opt {
  padding: 10px 14px; cursor: pointer; font-size: 14px;
  border-bottom: 1px solid var(--border);
  display: flex; gap: 12px; align-items: baseline;
}
.combobox .opt:last-child { border-bottom: none; }
.combobox .opt:hover, .combobox .opt[aria-selected="true"] { background: var(--brand-soft); color: var(--brand-1); }
.combobox .opt code { color: var(--text-2); font-size: 12px; min-width: 90px; }
.combobox .opt .sub { color: var(--muted); font-size: 12px; margin-left: auto; }

/* Tree row — งบทดลองแบบขยายดู contact */
.tree-toggle {
  background: none; border: none; cursor: pointer; color: var(--text-2);
  font-size: 14px; padding: 0 6px; min-height: auto;
  width: 24px; height: 24px;
}
.tree-toggle:hover { color: var(--brand-1); background: var(--brand-soft); border-radius: 6px; }
.tree-row.lvl-1 td:first-child { padding-left: 28px; }
.tree-row.lvl-2 td:first-child { padding-left: 52px; }
.tree-row.collapsed { display: none; }
.tree-row.contact-row { background: var(--surface-2); }
.tree-row.contact-row td { padding-top: 6px; padding-bottom: 6px; font-size: 13px; color: var(--text-2); }

/* Pill (status badge) — bigger + clearer */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600;
}
.pill-success { background: var(--success-bg); color: var(--success); }
.pill-warning { background: var(--warning-bg); color: var(--warning); }
.pill-danger  { background: var(--danger-bg);  color: var(--danger); }
.pill-info    { background: var(--info-bg);    color: var(--info); }
.pill-muted   { background: var(--surface-2);  color: var(--text-2); }

/* Journal book selector chips */
.book-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.book-chip {
  padding: 8px 14px; border-radius: 999px;
  background: var(--surface-2); border: 1.5px solid var(--border);
  font-size: 13.5px; font-weight: 600; color: var(--text-2);
  cursor: pointer; user-select: none;
  transition: all .15s;
}
.book-chip:hover { border-color: var(--brand-1); color: var(--brand-1); }
.book-chip.active { background: var(--brand-grad); border-color: transparent; color: #fff; }

/* Formula input visual cue */
.formula-input { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", monospace; }
.formula-input.has-formula { background: linear-gradient(180deg,#fff 60%,#fff8e1 100%); }
.formula-result {
  font-size: 11px; color: var(--text-2); text-align: right; margin-top: 2px;
  font-family: ui-monospace, monospace;
}

/* Card-on-mobile (replace dense tables) */
@media (max-width: 700px) {
  .data-card-mobile thead { display: none; }
  .data-card-mobile, .data-card-mobile tbody, .data-card-mobile tr, .data-card-mobile td { display: block; width: 100%; }
  .data-card-mobile tr {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 12px 14px; margin-bottom: 12px;
  }
  .data-card-mobile td { padding: 4px 0; border: none; }
  .data-card-mobile td::before {
    content: attr(data-label) ": ";
    color: var(--text-2); font-weight: 600; font-size: 13px; margin-right: 6px;
  }
}

/* Higher contrast in dark mode */
html[data-theme="dark"] {
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
}
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: var(--surface-2); color: var(--text);
}
html[data-theme="dark"] .wiz-tile { background: var(--surface-2); }
html[data-theme="dark"] .wiz-tile.selected { background: rgba(99,102,241,.18); }

/* Reduce motion respect */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition: none !important; }
}

/* =====================================================
   Session 17 — Notifications bell + dropdown
   ===================================================== */
.bell-wrap { position: relative; }
.bell-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text-2);
  cursor: pointer; transition: all .15s; position: relative;
}
.bell-btn:hover { background: var(--brand-soft); color: var(--brand-1); }
.bell-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--danger); color: #fff;
  border-radius: 999px; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
  border: 2px solid var(--surface);
}
.bell-panel {
  position: absolute; right: 0; top: calc(100% + 6px);
  width: 380px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-lg);
  display: none; z-index: 100; overflow: hidden;
}
.bell-wrap.open .bell-panel { display: block; }
.bell-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; font-size: 15px; font-weight: 700;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.bell-list { max-height: 480px; overflow: auto; }
.bell-item {
  display: flex; gap: 12px; padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  text-decoration: none; color: var(--text);
  transition: background .12s;
}
.bell-item:hover { background: var(--brand-soft); text-decoration: none; }
.bell-item.unread { background: rgba(99,102,241,.06); }
.bell-item .ico {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-1);
  display: grid; place-items: center; font-size: 16px;
  flex-shrink: 0;
}
.bell-item .body { flex: 1; min-width: 0; }
.bell-item .ttl { font-weight: 600; font-size: 13.5px; line-height: 1.4; }
.bell-item .txt { font-size: 13px; color: var(--text-2); margin-top: 2px;
                  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bell-item .ago { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.bell-item .dot { width: 8px; height: 8px; background: var(--brand-1); border-radius: 50%; flex-shrink: 0; align-self: center; }
.bell-empty { padding: 40px 20px; text-align: center; color: var(--text-2); font-size: 14px; }

/* =====================================================
   Sidebar nav — better effects (hover, active, ripple)
   ===================================================== */
.sidebar nav a {
  position: relative;
  transition: background .18s ease, color .18s ease, transform .12s ease, padding-left .18s ease;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); padding-left: 18px; }
.sidebar nav a.active { background: rgba(99,102,241,.18); color: #fff; box-shadow: inset 3px 0 0 var(--brand-1); }
.sidebar nav a.active::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--brand-grad); border-radius: 0 4px 4px 0;
}
.sidebar nav a:active { transform: scale(.98); }

/* Page transition on SPA nav */
.content { animation: page-fade .25s ease; }
@keyframes page-fade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =====================================================
   Members table specific
   ===================================================== */
.member-row { display:flex; gap:12px; padding:12px 14px; border-bottom:1px solid var(--border); align-items:center; }
.member-row:last-child { border-bottom: none; }
.member-row .avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--brand-grad); color: #fff;
  display: grid; place-items: center; font-weight: 700; flex-shrink: 0;
}
.member-row .info { flex: 1; min-width: 0; }
.member-row .info .name { font-weight: 600; font-size: 14.5px; }
.member-row .info .meta { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.member-row .ctrls { display:flex; gap:8px; align-items:center; }
.member-row select { min-height: 36px; font-size: 13px; padding: 4px 8px; }

/* =====================================================
   Session 16 — LIFF / Mobile (Senior-friendly)
   ===================================================== */

.mobile-shell {
  display: flex; flex-direction: column;
  min-height: 100vh; min-height: 100dvh;
  max-width: 480px; margin: 0 auto;
  background: var(--bg);
  position: relative;
  font-size: 17px; line-height: 1.7;
}
.mobile-shell .m-header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #06c755 0%, #06c755 60%, #03a04a 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.mobile-shell .m-header.theme-village { background: var(--brand-grad); }
.mobile-shell .m-header .back {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255,255,255,.18); color: #fff; text-decoration: none;
  font-size: 22px;
}
.mobile-shell .m-header .title { font-size: 18px; font-weight: 700; flex: 1; min-width: 0;
                                  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mobile-shell .m-header .title small { display: block; font-size: 12px; font-weight: 400; opacity: .85; }
.mobile-shell .m-header .icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255,255,255,.18); color: #fff; border: none; cursor: pointer;
}

.mobile-shell .m-content {
  flex: 1; padding: 16px;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

/* Hero block (greeting) */
.m-hero {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 18px 20px;
  margin-bottom: 14px;
}
.m-hero .label { font-size: 13px; color: var(--text-2); }
.m-hero .greeting { font-size: 22px; font-weight: 700; line-height: 1.3; margin: 4px 0 8px; }
.m-hero .house { font-size: 15px; color: var(--text-2); }

/* Mobile-friendly card list */
.m-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  margin-bottom: 12px;
  display: flex; align-items: center; gap: 14px;
  text-decoration: none; color: var(--text);
}
.m-card .icon {
  width: 52px; height: 52px; border-radius: 14px;
  background: var(--brand-soft); color: var(--brand-1);
  display: grid; place-items: center;
  font-size: 28px; flex-shrink: 0;
}
.m-card .body { flex: 1; min-width: 0; }
.m-card .body .name { font-size: 17px; font-weight: 700; }
.m-card .body .desc { font-size: 14px; color: var(--text-2); margin-top: 2px; }
.m-card .arrow { color: var(--text-2); font-size: 22px; }
.m-card.is-action:active { transform: scale(.98); }

/* Big stat tile (single value) */
.m-stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 18px 20px;
  display: flex; flex-direction: column; gap: 4px;
}
.m-stat .label { font-size: 13px; color: var(--text-2); }
.m-stat .value { font-size: 26px; font-weight: 800; line-height: 1.1; }
.m-stat.danger  .value { color: var(--danger); }
.m-stat.success .value { color: var(--success); }
.m-stat.warning .value { color: var(--warning); }

/* Bottom Navigation (fixed inside shell) */
.m-bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-width: 480px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  z-index: 50;
}
.m-bottom-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; border-radius: 12px;
  text-decoration: none; color: var(--text-2);
  font-size: 11.5px; font-weight: 600;
  min-height: 56px;
}
.m-bottom-nav a svg { width: 26px; height: 26px; }
.m-bottom-nav a.active { color: var(--brand-1); }
.m-bottom-nav a:active { background: var(--brand-soft); }

/* Big primary CTA button (LIFF style) */
.m-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 20px; min-height: 52px; width: 100%;
  border-radius: 14px;
  font-size: 17px; font-weight: 700;
  border: none; cursor: pointer;
  background: var(--brand-grad); color: #fff;
  box-shadow: 0 4px 12px rgba(99,102,241,.25);
}
.m-btn.line { background: linear-gradient(135deg,#06c755 0%, #03a04a 100%); box-shadow: 0 4px 12px rgba(6,199,85,.3); }
.m-btn.ghost { background: transparent; color: var(--brand-1); border: 1.5px solid var(--brand-1); box-shadow: none; }
.m-btn.danger { background: var(--danger); }
.m-btn:active { transform: scale(.97); }

/* Mobile form */
.m-field { margin-bottom: 16px; }
.m-field label { font-size: 14.5px; font-weight: 600; margin-bottom: 6px; display: block; }
.m-field input, .m-field select, .m-field textarea {
  width: 100%; min-height: 52px; font-size: 17px;
  padding: 12px 16px;
  border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
}
.m-field input:focus { outline: none; border-color: var(--brand-1); box-shadow: 0 0 0 4px rgba(99,102,241,.18); }

/* PIN input */
.pin-input {
  display: flex; gap: 10px; justify-content: center;
}
.pin-input input {
  width: 54px; height: 60px; text-align: center;
  font-size: 28px; font-weight: 700;
  border: 2px solid var(--border); border-radius: 12px;
  background: var(--surface);
}

/* Ticket / bill list item */
.m-list-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px 16px;
  margin-bottom: 10px;
  display: flex; gap: 12px; align-items: center;
  text-decoration: none; color: var(--text);
}
.m-list-item .left {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); flex-shrink: 0;
  font-size: 22px;
}
.m-list-item .body { flex: 1; min-width: 0; }
.m-list-item .body .title { font-weight: 700; font-size: 15.5px; line-height: 1.3; }
.m-list-item .body .meta  { font-size: 13px; color: var(--text-2); margin-top: 2px;
                            white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-list-item .right { text-align: right; }
.m-list-item .right .amount { font-weight: 700; font-size: 16px; }
.m-list-item .right .pill { display: inline-block; margin-top: 4px; }

/* Skeleton for LIFF loading */
.liff-loading {
  position: fixed; inset: 0; background: linear-gradient(135deg,#06c755,#04a047);
  color: #fff; display: grid; place-items: center;
  z-index: 9999;
}
.liff-loading .center { text-align: center; padding: 24px; }
.liff-loading .spinner {
  width: 48px; height: 48px; margin: 0 auto 16px;
  border: 4px solid rgba(255,255,255,.25);
  border-top-color: #fff; border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Make body usable if no shell wrapper */
@media (max-width: 480px) {
  .mobile-shell { box-shadow: none; }
}
