/* ระบบจัดการหอพักเลิศภักดี — แดง / ขาว / เทา ทันสมัย */
:root {
  /* Brand */
  --red-50:  #FEF2F2;
  --red-100: #FEE2E2;
  --red-300: #FCA5A5;
  --red-500: #DC2626;
  --red-600: #B91C1C;
  --red-700: #991B1B;
  --red-900: #450A0A;

  /* Grayscale */
  --gray-0:  #FFFFFF;
  --gray-50: #FAFAFA;
  --gray-75: #F5F5F5;
  --gray-100:#F3F4F6;
  --gray-200:#E5E7EB;
  --gray-300:#D1D5DB;
  --gray-400:#9CA3AF;
  --gray-500:#6B7280;
  --gray-600:#4B5563;
  --gray-700:#374151;
  --gray-800:#1F2937;
  --gray-900:#111827;

  /* Semantic */
  --success-500:#16A34A;
  --success-600:#15803D;
  --warning-500:#F59E0B;
  --info-500:#0EA5E9;

  --bg: var(--gray-50);
  --surface: var(--gray-0);
  --text: var(--gray-900);
  --text-muted: var(--gray-500);
  --border: var(--gray-200);

  --shadow-sm: 0 1px 2px rgba(15,23,42,0.04), 0 1px 3px rgba(15,23,42,0.06);
  --shadow-md: 0 4px 12px rgba(15,23,42,0.08), 0 2px 4px rgba(15,23,42,0.04);
  --shadow-lg: 0 12px 32px rgba(15,23,42,0.12), 0 4px 8px rgba(15,23,42,0.04);
  --shadow-red: 0 8px 24px rgba(220,38,38,0.20);

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;

  --header-h: 60px;
  --bottom-h: 64px;
  --side-w: 240px;

  --gradient-red: linear-gradient(135deg, #DC2626 0%, #B91C1C 100%);
  --gradient-red-dark: linear-gradient(135deg, #991B1B 0%, #450A0A 100%);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: 'IBM Plex Sans Thai', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; cursor: pointer; }
button { font-family: inherit; cursor: pointer; }
ul { list-style: none; }
input, select, textarea { font-family: inherit; }

/* Background pattern (modern dotted/mesh subtle) */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    radial-gradient(circle at 20% 0%, rgba(220, 38, 38, 0.04), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(220, 38, 38, 0.03), transparent 40%),
    radial-gradient(circle at 1px 1px, rgba(15,23,42,0.06) 1px, transparent 0);
  background-size: auto, auto, 24px 24px;
  pointer-events: none;
}

/* ─── App layout ──────────────────────────────────────────── */
.app {
  min-height: 100vh;
  min-height: 100dvh;
}

/* Top bar */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
  height: calc(var(--header-h) + env(safe-area-inset-top));
}

.topbar__menu, .icon-btn {
  background: transparent;
  border: 0;
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  color: var(--gray-700);
  transition: background .15s ease, color .15s ease;
}
.topbar__menu:hover, .icon-btn:hover { background: var(--gray-100); color: var(--red-600); }

.topbar__brand {
  display: flex; align-items: center; gap: 10px;
  flex: 1; min-width: 0;
}
.topbar__logo {
  width: 38px; height: 38px;
  background: var(--gradient-red);
  border-radius: 12px;
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--shadow-red);
}
.topbar__title { display: flex; flex-direction: column; min-width: 0; }
.topbar__title strong { font-weight: 700; font-size: 16px; line-height: 1.2; color: var(--gray-900); }
.topbar__title small { color: var(--text-muted); font-size: 12px; line-height: 1.2; }

.topbar__actions { display: flex; gap: 4px; }

/* Side navigation */
.sidenav {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: var(--side-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 60;
  padding: 18px 0 24px;
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform .25s ease;
  overflow-y: auto;
}
.sidenav.open { transform: translateX(0); }

.sidenav__header {
  padding: 4px 18px 22px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.sidenav__logo {
  width: 44px; height: 44px;
  background: var(--gradient-red);
  border-radius: 14px;
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 16px;
  box-shadow: var(--shadow-red);
}
.sidenav__header strong { display: block; font-weight: 700; }
.sidenav__header small { color: var(--text-muted); font-size: 12px; }

.sidenav__list { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.sidenav__link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--gray-700);
  font-weight: 500;
  font-size: 14.5px;
  transition: background .15s ease, color .15s ease;
}
.sidenav__link:hover { background: var(--gray-100); color: var(--red-600); }
.sidenav__link.active {
  background: var(--gradient-red);
  color: #fff;
  box-shadow: var(--shadow-red);
}
.sidenav__link .ico {
  width: 22px; text-align: center;
  font-size: 16px;
}
.sidenav__footer { margin-top: auto; padding: 12px 22px; color: var(--text-muted); font-size: 11px; border-top: 1px solid var(--border); }

.scrim {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.4);
  z-index: 55;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.scrim.show { opacity: 1; pointer-events: auto; }

/* Main content */
.main {
  padding: calc(var(--header-h) + env(safe-area-inset-top) + 12px) 16px calc(var(--bottom-h) + 24px);
  max-width: 1200px;
  margin: 0 auto;
}

/* Bottom nav (mobile) */
.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--border);
  height: calc(var(--bottom-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav__item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  color: var(--gray-500);
  font-size: 11px;
  font-weight: 500;
  position: relative;
}
.bottomnav__item.active { color: var(--red-600); }
.bottomnav__item.active::before {
  content: '';
  position: absolute; top: 0;
  width: 32px; height: 3px;
  background: var(--red-500);
  border-radius: 0 0 3px 3px;
}

/* Desktop layout: hide bottomnav, persistent sidenav */
@media (min-width: 900px) {
  .topbar__menu { display: none; }
  .sidenav { transform: translateX(0); box-shadow: none; }
  .scrim { display: none; }
  .main { padding-left: calc(var(--side-w) + 24px); padding-right: 24px; max-width: 100%; }
  .bottomnav { display: none; }
  .topbar__brand { padding-left: var(--side-w); }
  .topbar { left: 0; }
}

/* ─── Components ──────────────────────────────────────────── */

/* Hero stats card */
.hero {
  background: var(--gradient-red);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 22px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-red);
}
.hero::before {
  content: '';
  position: absolute;
  inset: -40px -40px auto auto;
  width: 220px; height: 220px;
  background: radial-gradient(circle, rgba(255,255,255,0.18), transparent 70%);
  pointer-events: none;
}
.hero::after {
  content: '';
  position: absolute;
  inset: auto auto -80px -80px;
  width: 200px; height: 200px;
  background: radial-gradient(circle, rgba(0,0,0,0.10), transparent 70%);
  pointer-events: none;
}
.hero h2 {
  font-weight: 600; font-size: 14px; opacity: 0.9; margin-bottom: 8px;
  letter-spacing: 0.02em;
}
.hero__big { font-size: 38px; font-weight: 700; line-height: 1; margin-bottom: 6px; }
.hero__caption { font-size: 13.5px; opacity: 0.85; }
.hero__row { display: flex; gap: 18px; margin-top: 18px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.18); }
.hero__row > div { flex: 1; }
.hero__row strong { display: block; font-size: 22px; font-weight: 700; }
.hero__row small { font-size: 12px; opacity: 0.85; }

/* Stat cards */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin: 18px 0;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat__label { color: var(--text-muted); font-size: 12.5px; font-weight: 500; }
.stat__value { font-size: 26px; font-weight: 700; color: var(--gray-900); margin-top: 4px; line-height: 1.1; }
.stat__sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.stat__icon {
  position: absolute; top: 12px; right: 12px;
  width: 36px; height: 36px;
  border-radius: 12px;
  background: var(--red-50); color: var(--red-600);
  display: grid; place-items: center;
  font-size: 18px;
}
.stat--red .stat__value { color: var(--red-600); }
.stat--success .stat__value { color: var(--success-500); }

/* Section heading */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 22px 0 10px;
  gap: 12px;
}
.section-head h3 { font-size: 17px; font-weight: 700; color: var(--gray-900); }
.section-head .meta { font-size: 13px; color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  background: var(--gray-100);
  color: var(--gray-800);
  border: 1px solid transparent;
  transition: all .15s ease;
  cursor: pointer;
  text-decoration: none;
  min-height: 40px;
}
.btn:hover { background: var(--gray-200); }
.btn--primary {
  background: var(--gradient-red);
  color: #fff;
  box-shadow: var(--shadow-red);
}
.btn--primary:hover { background: var(--gradient-red-dark); transform: translateY(-1px); }
.btn--ghost {
  background: transparent; border: 1px solid var(--border);
}
.btn--ghost:hover { background: var(--gray-50); border-color: var(--red-300); color: var(--red-600); }
.btn--sm { padding: 6px 12px; font-size: 13px; min-height: 32px; }
.btn--icon { width: 40px; height: 40px; padding: 0; border-radius: 12px; }
.btn--block { width: 100%; }
.btn--share {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #DC2626 0%, #B91C1C 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(220,38,38,0.25);
  transition: all 0.2s;
  min-height: 46px;
}
.btn--share:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(220,38,38,0.35); }
.btn--share:active { transform: scale(0.97); }
.btn--share-green {
  background: linear-gradient(135deg, #16A34A 0%, #15803D 100%);
  box-shadow: 0 4px 14px rgba(22,163,74,0.25);
}
.btn--share-green:hover { box-shadow: 0 6px 20px rgba(22,163,74,0.35); }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card__head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.card__title { font-weight: 700; font-size: 15px; }

/* Room grid */
.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.room {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 10px 10px;
  text-align: center;
  position: relative;
  transition: all .15s ease;
  cursor: pointer;
  min-height: 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.room:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--red-300); }
.room__num { font-size: 16px; font-weight: 700; color: var(--gray-900); }
.room__label { font-size: 11px; color: var(--gray-700); font-weight: 500; margin-top: 1px; }
.room__name { font-size: 11.5px; color: var(--gray-400); margin-top: auto; padding-top: 6px; line-height: 1.3; min-height: 14px; }
.room__amenity { display: flex; gap: 3px; justify-content: center; margin-top: 6px; }
.room__amenity span {
  display: inline-block;
  background: var(--gray-100); color: var(--gray-600);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 6px;
}
.room__status {
  position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px;
  border-radius: 50%;
}
.room--unpaid .room__status { background: var(--red-500); }
.room--paid .room__status { background: var(--success-500); }
.room--partial .room__status { background: var(--warning-500); }
.room--vacant .room__status { background: var(--gray-300); }

.floor-head {
  display: flex; align-items: center; gap: 10px;
  margin: 18px 0 8px;
  font-weight: 600;
  color: var(--gray-700);
}
.floor-head::before {
  content: ''; width: 3px; height: 18px; background: var(--red-500); border-radius: 2px;
}

/* Tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th, table.tbl td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
table.tbl thead th { background: var(--gray-50); font-weight: 600; color: var(--gray-700); white-space: nowrap; }
table.tbl tbody tr:hover { background: var(--red-50); }
table.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl__num { text-align: right; font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--gray-100);
  color: var(--gray-700);
}
.badge--unpaid { background: var(--red-50); color: var(--red-700); }
.badge--paid { background: #DCFCE7; color: #166534; }
.badge--partial { background: #FEF3C7; color: #92400E; }
.badge--air { background: #DBEAFE; color: #1E40AF; }
.badge--re { background: #F0E7FF; color: #6B21A8; }
.badge--fridge { background: #E0F2FE; color: #075985; }

/* Form */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--gray-700); }
.field input, .field select, .field textarea {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 14.5px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  outline: none;
  transition: border .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--red-500);
  box-shadow: 0 0 0 3px rgba(220,38,38,0.12);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Modal */
.modal {
  position: fixed; inset: 0;
  z-index: 100;
  display: grid; place-items: center;
}
.modal[hidden], .toast[hidden] { display: none; }   /* fix: hidden attribute ถูก override โดย display rule */
.modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(15,23,42,0.6);
  backdrop-filter: blur(6px);
}
.modal__panel {
  position: relative;
  background: var(--surface);
  border-radius: 22px;
  width: min(92vw, 540px);
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
  padding: 22px;
  z-index: 1;
  animation: scaleIn .2s ease;
}
@keyframes scaleIn { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal__head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.modal__title { font-size: 18px; font-weight: 700; }
.modal__close {
  background: var(--gray-100); border: 0;
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 16px; color: var(--gray-700);
}

/* Modal tabs */
.modal-tabs {
  display: flex; gap: 4px;
  margin-bottom: 16px;
  background: var(--gray-100);
  border-radius: 12px;
  padding: 4px;
}
.modal-tab {
  flex: 1;
  padding: 9px 14px;
  border: 0; background: transparent;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  transition: all .15s ease;
}
.modal-tab:hover { color: var(--gray-700); }
.modal-tab.active {
  background: var(--surface);
  color: var(--red-600);
  box-shadow: var(--shadow-sm);
}

/* Asset list */
.asset-row {
  display: grid;
  grid-template-columns: 1fr 1.5fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--gray-100);
}
.asset-row:last-child { border-bottom: 0; }
.asset-row input, .asset-row select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.asset-row input:focus, .asset-row select:focus {
  border-color: var(--red-500);
  box-shadow: 0 0 0 2px rgba(220,38,38,0.10);
}
.asset-row select { padding: 8px 6px; }
@media (max-width: 500px) {
  .asset-row {
    grid-template-columns: 1fr 1fr;
  }
  .asset-row input:nth-child(1) { grid-column: 1 / -1; }
  .asset-row input:nth-child(2) { grid-column: 1 / 2; }
}

/* Meter tabs */
.meter-tabs {
  display: flex; gap: 0;
  margin-bottom: 16px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.meter-tab {
  flex: 1;
  padding: 12px 16px;
  border: 0; background: var(--gray-50);
  font-size: 14.5px;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  transition: all .15s ease;
}
.meter-tab:first-child { border-right: 1px solid var(--border); }
.meter-tab:hover { background: var(--gray-100); color: var(--gray-700); }
.meter-tab.active {
  background: var(--gradient-red);
  color: #fff;
}

/* Meter inline input cell */
.meter-input-col { background: rgba(220,38,38,0.05) !important; }
.meter-input-cell { background: rgba(220,38,38,0.04); }
.meter-input {
  width: 90px;
  padding: 7px 8px;
  border: 1.5px solid var(--red-300);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  text-align: right;
  font-variant-numeric: tabular-nums;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border .15s ease, box-shadow .15s ease;
}
.meter-input:focus {
  border-color: var(--red-500);
  box-shadow: 0 0 0 3px rgba(220,38,38,0.15);
}
.meter-input::placeholder { color: var(--gray-300); }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--bottom-h) + 24px); left: 50%;
  transform: translateX(-50%);
  background: var(--gray-900);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  animation: slideUp .2s ease;
}
.toast.error { background: var(--red-600); }
.toast.success { background: var(--success-500); }
@keyframes slideUp { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Filters chip row */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--gray-100);
  border: 1px solid transparent;
  color: var(--gray-700);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.chip.active { background: var(--red-500); color: #fff; }

/* Loading */
.loading { padding: 40px 0; text-align: center; color: var(--text-muted); }
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--gray-200); border-top-color: var(--red-500);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Bar chart for analytics */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 200px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
}
.bar-chart__col {
  flex: 1;
  background: var(--red-100);
  border-radius: 6px 6px 0 0;
  position: relative;
  min-height: 4px;
  transition: background .15s ease;
}
.bar-chart__col:hover { background: var(--red-500); }
.bar-chart__col::after {
  content: attr(data-label);
  position: absolute;
  bottom: -22px;
  left: 50%; transform: translateX(-50%);
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Progress bar for collection tracking */
.progress-bar {
  height: 12px;
  background: var(--gray-100);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success-500), #22C55E);
  border-radius: 99px;
  transition: width 0.6s ease;
  min-width: 2px;
}

/* Bill detail layout (printable) */
/* ── Bill paper shared ── */
.bill-paper {
  background: white;
  padding: 28px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}
.bill-paper__badge {
  position: absolute; top: 14px; right: 14px;
  font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 99px;
}
.bill-paper__head { text-align: center; padding-bottom: 14px; margin-bottom: 16px; }
.bill-paper__head h2 { font-size: 20px; font-weight: 700; }
.bill-paper__head small { font-size: 12px; display: block; margin-top: 4px; }
.bill-paper__title { text-align: center; padding: 6px; margin-bottom: 14px; font-weight: 700; border-radius: 6px; }

.bill-paper table { width: 100%; border-collapse: collapse; }
.bill-paper table th, .bill-paper table td { padding: 8px; font-size: 14px; }
.bill-paper .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Red theme (ใบแจ้งหนี้) ── */
.bill-paper--red { border-top: 4px solid var(--red-500); }
.bill-paper__badge--red { background: var(--red-50); color: var(--red-600); }
.bill-paper__head--red { border-bottom: 2px solid var(--red-500); }
.bill-paper__head--red small { color: var(--gray-500); }
.bill-paper__title--red { background: var(--red-500); color: white; }
.bill-paper--red table th { text-align: left; background: var(--red-50); color: var(--red-700); border-bottom: 1px solid var(--red-100); }
.bill-paper--red table td { border-bottom: 1px solid var(--gray-100); }
.total--red { font-size: 18px; font-weight: 700; background: var(--red-50); color: var(--red-700); }

/* ── Green theme (ใบเสร็จรับเงิน) ── */
.bill-paper--green { border-top: 4px solid var(--success-500); }
.bill-paper__head--green { border-bottom: 2px solid var(--success-500); }
.bill-paper__head--green h2 { color: var(--success-600); }
.bill-paper__title--green { background: var(--success-500); color: white; }
.bill-paper--green table th { text-align: left; background: #F0FDF4; color: var(--success-600); border-bottom: 1px solid #DCFCE7; }
.bill-paper--green table td { border-bottom: 1px solid var(--gray-100); }
.total--green { font-size: 18px; font-weight: 700; background: #F0FDF4; color: var(--success-600); }

/* ── Pay section in bill (bank info left + QR right) ── */
.pay-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px dashed var(--gray-300);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: end;
}
.bank-info {
  font-size: 12.5px;
  color: var(--gray-700);
  line-height: 1.65;
}
.bank-info__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--red-600);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.bank-info strong { color: var(--gray-900); font-weight: 600; }
.bank-info .acct-no {
  font-size: 15px;
  font-weight: 700;
  color: var(--red-700);
  letter-spacing: 0.5px;
  margin: 2px 0;
  font-variant-numeric: tabular-nums;
}
.qr-box { text-align: center; }
.qr-box img {
  width: 120px; height: auto;        /* สูงอัตโนมัติ รักษาสัดส่วนต้นฉบับ กัน QR ถูกบีบแบน (object-fit ไม่ทำงานตอนแชร์ผ่าน html2canvas) */
  display: block;
  border-radius: 6px;
  background: white;
}
.qr-box small {
  font-size: 10px;
  color: var(--gray-500);
  margin-top: 3px;
  display: block;
}
.due-note {
  margin-top: 12px;
  text-align: center;
  font-size: 12px;
  color: var(--gray-500);
}
.due-note strong { color: var(--red-600); }

/* Mobile: stack pay-section vertically */
@media (max-width: 480px) {
  .pay-section { grid-template-columns: 1fr; gap: 12px; }
  .qr-box { justify-self: center; }
}

/* ── Pet Widget (Among Us Edition) ── */
#petWidget {
  position: fixed;
  bottom: 80px;
  right: 16px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
@media (min-width: 900px) { #petWidget { bottom: 20px; right: 24px; } }

.pet-bubble {
  background: white;
  border: 2px solid var(--gray-200);
  border-radius: 16px 16px 4px 16px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  animation: petFadeIn 0.3s ease;
  max-width: 170px;
  text-align: center;
}

.pet-body {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  user-select: none;
  filter: drop-shadow(0 3px 8px rgba(0,0,0,0.2));
}
.pet-grabbing {
  cursor: grabbing !important;
  animation: none !important;
  filter: drop-shadow(0 8px 20px rgba(0,0,0,0.35)) !important;
  z-index: 10;
}
.pet-walking { animation: none !important; cursor: grab; }
.pet-walking .pet-foot-l { animation: petStepL 0.3s ease-in-out infinite; }
.pet-walking .pet-foot-r { animation: petStepR 0.3s ease-in-out infinite; }
@keyframes petStepL {
  0%,100% { transform: translateY(0) translateX(0); }
  50% { transform: translateY(-6px) translateX(3px); }
}
@keyframes petStepR {
  0%,100% { transform: translateY(-6px) translateX(-3px); }
  50% { transform: translateY(0) translateX(0); }
}
.pet-flying  { animation: none !important; pointer-events: none; }
.pet-svg { display: block; }

.pet-mood--happy   { animation: petBounce 2s ease-in-out infinite; }
.pet-mood--neutral { animation: petBounce 3s ease-in-out infinite; }
.pet-mood--sad     { animation: petSad 2.5s ease-in-out infinite; }
.pet-mood--critical { animation: petShake 0.4s ease-in-out infinite; }

.pet-action { animation: petJump 0.5s ease !important; }

/* Sparkle animation inside SVG */
.pet-sparkle-svg { animation: petSparkleRotate 2s ease-in-out infinite; transform-origin: 62px 16px; }
@keyframes petSparkleRotate {
  0%,100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Panel */
.pet-panel {
  background: white;
  border-radius: 18px;
  box-shadow: 0 6px 30px rgba(0,0,0,0.18);
  width: 240px;
  margin-bottom: 6px;
  overflow: hidden;
  animation: petFadeIn 0.25s ease;
}
.pet-panel__header {
  padding: 12px 14px;
  background: linear-gradient(135deg, #FEE2E2, #FECACA);
  display: flex;
  align-items: center;
  gap: 10px;
}
.pet-panel__avatar {
  width: 42px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.pet-panel__info { flex: 1; min-width: 0; }
.pet-panel__name { font-weight: 700; font-size: 15px; display: block; }
.pet-panel__badges { display: flex; gap: 4px; margin-top: 3px; }
.pet-badge {
  font-weight: 600;
  font-size: 10px;
  background: white;
  padding: 1px 7px;
  border-radius: 8px;
  color: var(--red-500);
}
.pet-badge--species { color: var(--gray-500); }
.pet-panel__close { margin-left: auto; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--gray-400); align-self: flex-start; }

/* Color picker */
.pet-panel__colors {
  display: flex;
  gap: 5px;
  padding: 8px 14px 4px;
  justify-content: center;
  flex-wrap: wrap;
}
.pet-color-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  padding: 0;
  box-shadow: inset 0 -2px 4px rgba(0,0,0,0.15);
}
.pet-color-dot:hover { transform: scale(1.2); }
.pet-color-dot--active { border-color: #333; box-shadow: 0 0 0 2px white, 0 0 0 4px #333; }
.pet-color-dot--white { border: 2px solid var(--gray-300); }

/* Stats */
.pet-panel__stats { padding: 8px 14px 4px; }
.pet-stat { margin-bottom: 5px; }
.pet-stat span { font-size: 11px; color: var(--gray-600); }
.pet-bar { height: 8px; background: var(--gray-100); border-radius: 99px; overflow: hidden; margin-top: 2px; }
.pet-bar__fill { height: 100%; border-radius: 99px; transition: width 0.5s ease; }
.pet-bar--hunger { background: linear-gradient(90deg, #F97316, #FB923C); }
.pet-bar--happy  { background: linear-gradient(90deg, #EAB308, #FACC15); }
.pet-bar--clean  { background: linear-gradient(90deg, #06B6D4, #22D3EE); }

/* Action buttons */
.pet-panel__actions {
  display: flex;
  gap: 6px;
  padding: 8px 14px 6px;
  justify-content: center;
}
.pet-btn {
  flex: 1;
  padding: 8px 4px 6px;
  border: 2px solid var(--gray-200);
  border-radius: 14px;
  background: white;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.pet-btn span { font-size: 20px; display: block; }
.pet-btn small { font-size: 10px; color: var(--gray-500); display: block; margin-top: 1px; }
.pet-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.pet-btn:active { transform: scale(0.95); }
.pet-btn--feed:hover { border-color: #F97316; background: #FFF7ED; }
.pet-btn--play:hover { border-color: #EAB308; background: #FEFCE8; }
.pet-btn--clean:hover { border-color: #06B6D4; background: #ECFEFF; }

/* Footer */
.pet-panel__footer {
  text-align: center;
  padding: 4px 14px 10px;
  display: flex;
  justify-content: space-between;
}
.pet-panel__footer small { font-size: 10px; color: var(--gray-400); }

/* Particles */
.pet-particle {
  position: absolute;
  bottom: 60px;
  font-size: 18px;
  pointer-events: none;
  animation: petParticleUp 1.2s ease-out forwards;
  z-index: 10;
}
@keyframes petParticleUp {
  0% { opacity: 1; transform: translateY(0) translateX(0) scale(1); }
  60% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-80px) translateX(var(--drift, 0px)) scale(0.5) rotate(20deg); }
}

/* Bounce reaction text */
.pet-bounce-text {
  position: fixed;
  font-size: 15px;
  font-weight: 700;
  color: #E53935;
  pointer-events: none;
  z-index: 9999;
  text-shadow: 0 1px 3px rgba(0,0,0,0.15);
  animation: petBounceTextUp 0.9s ease-out forwards;
  transform: translateX(-50%);
}
@keyframes petBounceTextUp {
  0% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.3); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-35px) scale(0.7); }
}

/* Mood animations */
@keyframes petBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
@keyframes petSad {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(2px) rotate(-3deg); }
  75% { transform: translateY(2px) rotate(3deg); }
}
@keyframes petShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
@keyframes petJump {
  0% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-22px) scale(1.15); }
  50% { transform: translateY(-22px) scale(1.15); }
  80% { transform: translateY(4px) scale(0.95); }
  100% { transform: translateY(0) scale(1); }
}
@keyframes petFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media print {
  /* ซ่อน UI ทั้งหมด */
  .topbar, .bottomnav, .sidenav, .scrim, .no-print, .modal__head, #petWidget { display: none !important; }
  body, html { background: white !important; }
  body::before { display: none !important; }
  #app { display: block !important; }

  /* ซ่อน main content ด้านหลัง */
  .main { display: none !important; }

  /* Modal → เต็มหน้ากระดาษ */
  .modal {
    position: static !important;
    display: block !important;
    z-index: auto !important;
  }
  .modal__backdrop { display: none !important; }
  .modal__panel {
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    animation: none !important;
  }

  /* Bill paper → พอดีกระดาษ */
  .bill-paper {
    box-shadow: none !important;
    border-radius: 0 !important;
    border: 1px solid #ccc !important;
    padding: 20px !important;
    page-break-inside: avoid;
    margin-bottom: 16px !important;
  }
  .bill-paper--red { border-top: 4px solid #DC2626 !important; }
  .bill-paper--green { border-top: 4px solid #16A34A !important; }

  /* ใบเสร็จขึ้นหน้าใหม่ */
  .bill-paper--green { page-break-before: auto; }
}

/* ─── File Uploads: Photo Grid & Document List ─────────────── */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 8px;
}
.photo-slot {
  position: relative;
  aspect-ratio: 1;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  background: var(--gray-50);
  transition: border-color 0.2s, background 0.2s;
}
.photo-slot:hover {
  border-color: var(--red-500);
  background: var(--red-50);
}
.photo-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-slot__placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--gray-400);
  font-size: 12px;
  pointer-events: none;
}
.photo-slot__placeholder svg { width: 24px; height: 24px; }
.photo-slot__remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: none;
  font-size: 14px;
  line-height: 22px;
  text-align: center;
  cursor: pointer;
  display: none;
  z-index: 2;
}
.photo-slot:hover .photo-slot__remove { display: block; }
.photo-slot__remove:hover { background: var(--red-500); }

.doc-list { margin-top: 8px; }
.doc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--gray-50);
  margin-bottom: 6px;
  font-size: 13px;
}
.doc-item__icon { font-size: 20px; flex-shrink: 0; }
.doc-item__info { flex: 1; min-width: 0; }
.doc-item__name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.doc-item__meta { color: var(--text-muted); font-size: 11px; }
.doc-item__actions { display: flex; gap: 4px; }
.doc-upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-sm);
  background: var(--gray-50);
  color: var(--gray-500);
  cursor: pointer;
  font-size: 13px;
  transition: border-color 0.2s, background 0.2s;
  width: 100%;
  margin-top: 6px;
}
.doc-upload-btn:hover {
  border-color: var(--red-500);
  background: var(--red-50);
  color: var(--red-500);
}
