@font-face {
  font-family: 'Phetsarath OT';
  src: local('Phetsarath OT'), url('fonts/phetsarath_ot.ttf') format('truetype');
  font-display: swap;
}

:root {
  --brand: #0f3d5e;
  --brand-2: #1b6ca8;
  --accent: #ffc107;
  --surface: #ffffff;
  --app-bg: #f3f6fa;
  --bs-primary: #1b6ca8;
  --bs-primary-rgb: 27, 108, 168;
  --bs-link-color: #1b6ca8;
  --bs-link-color-rgb: 27, 108, 168;
  --bs-body-font-family: 'Inter', 'Noto Sans Lao', 'Phetsarath OT', 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --bs-border-radius: .6rem;
  --bs-border-radius-lg: .9rem;
}

body { background: var(--app-bg); min-height: 100vh; display: flex; flex-direction: column; }
.app-main { flex: 1 0 auto; }
.mode-admin .app-main { padding-bottom: 5.5rem !important; }
@media (min-width: 768px) { .mode-admin .app-main { padding-bottom: 1.5rem !important; } }

.btn-primary {
  --bs-btn-bg: var(--brand-2); --bs-btn-border-color: var(--brand-2);
  --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand);
  --bs-btn-active-bg: var(--brand); --bs-btn-active-border-color: var(--brand);
}
.text-brand { color: var(--brand-2) !important; }
.form-control, .form-select { padding: .6rem .85rem; }
.form-control:focus, .form-select:focus { border-color: var(--brand-2); box-shadow: 0 0 0 .2rem rgba(27, 108, 168, .15); }

/* ---------- Navbar ---------- */
.app-navbar {
  background: linear-gradient(120deg, var(--brand) 0%, var(--brand-2) 100%);
  box-shadow: 0 4px 18px rgba(15, 61, 94, .18);
}
.app-navbar .nav-link { color: rgba(255, 255, 255, .8); font-weight: 500; }
.app-navbar .nav-link:hover { color: #fff; }
.app-navbar .nav-link.active { color: var(--brand) !important; background: #fff; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; display: inline-grid; place-items: center;
  background: var(--accent); color: var(--brand); font-weight: 800; letter-spacing: .5px;
}
.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255, 255, 255, .7); }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
  display: flex; justify-content: space-around;
  background: #fff; border-top: 1px solid #e5e9f0;
  padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 20px rgba(15, 61, 94, .08);
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-decoration: none; color: #6c7a89; font-size: .7rem; padding: .3rem 0; border-radius: .6rem;
}
.bottom-nav a i { font-size: 1.25rem; }
.bottom-nav a.active { color: var(--brand-2); font-weight: 600; background: rgba(27, 108, 168, .08); }

/* ---------- Page head ---------- */
.page-icon {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-size: 1.35rem;
  color: #fff; background: linear-gradient(135deg, var(--brand-2), var(--brand));
  box-shadow: 0 6px 16px rgba(27, 108, 168, .3);
}

/* ---------- Cards ---------- */
.card { border: 0; border-radius: 1rem; box-shadow: 0 2px 12px rgba(15, 61, 94, .06); }
.card-header { background: transparent; border-bottom: 1px solid #eef1f5; padding: 1rem 1.25rem; }
.stat-card { position: relative; overflow: hidden; }
.stat-icon {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem; flex-shrink: 0;
}
a .stat-icon { transition: transform .15s ease; }
a:hover .stat-icon { transform: translateY(-2px); }
.min-w-0 { min-width: 0; }
.stat-card .stat-value { font-size: clamp(1.15rem, 2.4vw, 1.6rem); font-weight: 700; line-height: 1.2; word-break: break-all; }
.stat-card .stat-label { color: #6c7a89; font-size: .85rem; }
.bg-soft-primary { background: rgba(27, 108, 168, .12); color: var(--brand-2); }
.bg-soft-success { background: rgba(25, 135, 84, .12); color: #198754; }
.bg-soft-danger { background: rgba(220, 53, 69, .12); color: #dc3545; }
.bg-soft-warning { background: rgba(255, 193, 7, .18); color: #b58100; }
.bg-soft-info { background: rgba(13, 202, 240, .14); color: #0a8ea8; }

/* ---------- Tables ---------- */
.table-app { margin: 0; }
.table-app thead th {
  background: #f6f8fb; color: #5b6b7c; font-weight: 600; font-size: .82rem; white-space: nowrap;
  border-bottom: 1px solid #e6ebf1; padding: .8rem .9rem;
}
.table-app td { padding: .75rem .9rem; vertical-align: middle; border-color: #f0f2f6; }
.table-app tbody tr:hover { background: #f8fbff; }
.table-app tfoot td { background: #fff8e1; font-weight: 700; border-top: 2px solid #ffe08a; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: 'Inter', ui-monospace, monospace; letter-spacing: .3px; }

/* ตารางบนมือถือ: แสดงเป็นการ์ด */
@media (max-width: 767.98px) {
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td, .table-stack tfoot { display: block; width: 100%; }
  .table-stack tr { padding: .75rem 1rem; border-bottom: 1px solid #eef1f5; }
  .table-stack td { border: 0; padding: .2rem 0; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
  .table-stack td::before { content: attr(data-label); color: #6c7a89; font-size: .82rem; text-align: left; flex-shrink: 0; }
  .table-stack td.td-actions { justify-content: flex-end; padding-top: .5rem; }
  .table-stack td.td-actions::before { content: none; }
  .table-stack td.td-hide-sm { display: none; }
  .table-stack tfoot tr { background: #fff8e1; }
  .table-stack tfoot td { background: transparent; border-top: 0; }
}

/* ---------- Auth (login) ---------- */
.mode-auth {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(255, 193, 7, .25), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(27, 108, 168, .55), transparent 60%),
    linear-gradient(135deg, #0b2a42 0%, #0f3d5e 45%, #1b6ca8 100%);
  display: flex; align-items: center; justify-content: center; padding: 1.25rem;
}
.auth-wrap { width: 100%; max-width: 980px; }
.auth-card { border-radius: 1.5rem; overflow: hidden; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); }
.auth-side {
  background: linear-gradient(160deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, 0)), linear-gradient(135deg, #0f3d5e, #1b6ca8);
  color: #fff; position: relative; overflow: hidden;
}
.auth-side::after {
  content: ''; position: absolute; width: 340px; height: 340px; border-radius: 50%;
  right: -120px; bottom: -120px; background: rgba(255, 193, 7, .18);
}
.auth-side::before {
  content: ''; position: absolute; width: 200px; height: 200px; border-radius: 50%;
  left: -60px; top: -60px; background: rgba(255, 255, 255, .06);
}
.auth-side .feature { display: flex; gap: .75rem; align-items: flex-start; margin-bottom: 1rem; position: relative; z-index: 1; }
.auth-side .feature i { font-size: 1.2rem; color: var(--accent); }
.auth-form { background: #fff; }
.auth-form .form-floating > .form-control { border-radius: .8rem; }
.auth-form .input-icon { position: relative; }
.btn-auth {
  padding: .8rem 1rem; font-weight: 600; border-radius: .8rem;
  background: linear-gradient(120deg, var(--brand), var(--brand-2)); border: 0; color: #fff;
  box-shadow: 0 10px 24px rgba(27, 108, 168, .35); transition: transform .15s ease, box-shadow .15s ease;
}
.btn-auth:hover, .btn-auth:focus { color: #fff; transform: translateY(-1px); box-shadow: 0 14px 30px rgba(27, 108, 168, .45); }
.auth-switch { color: rgba(255, 255, 255, .75); }
.auth-switch a { color: #fff; font-weight: 600; }
.toggle-pass { position: absolute; right: .6rem; top: 50%; transform: translateY(-50%); z-index: 5; }

/* ---------- Customer ---------- */
.balance-hero {
  background: linear-gradient(130deg, var(--brand) 0%, var(--brand-2) 70%, #2a8bd1 100%);
  color: #fff; border-radius: 1.25rem; position: relative; overflow: hidden;
  box-shadow: 0 16px 36px rgba(15, 61, 94, .28);
}
.balance-hero::after {
  content: ''; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%;
  background: rgba(255, 255, 255, .08);
}
.balance-hero .amount { font-size: clamp(1.8rem, 6vw, 2.8rem); font-weight: 700; letter-spacing: -.5px; }
.chip-acc { background: rgba(255, 255, 255, .15); border-radius: 999px; padding: .25rem .75rem; font-size: .85rem; }

/* ---------- Misc ---------- */
.confirm-icon {
  width: 64px; height: 64px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center;
  background: rgba(220, 53, 69, .1); color: #dc3545; font-size: 1.8rem;
}
.empty-state { padding: 3rem 1rem; text-align: center; color: #8a97a6; }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .5rem; opacity: .5; }
.app-footer { border-top: 1px solid #e6ebf1; background: #fff; }
.mode-admin .app-footer { padding-bottom: 6rem !important; }
@media (min-width: 768px) { .mode-admin .app-footer { padding-bottom: 1.5rem !important; } }
.clock { font-variant-numeric: tabular-nums; }
.step-pill { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 700; font-size: .85rem; }
.amount-input { font-size: 1.5rem; font-weight: 700; text-align: right; }
@media print {
  .app-navbar, .bottom-nav, .no-print, .toast-container { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
