:root {
  --ink: #12202c;
  --ink-2: #1a2e3c;
  --ink-3: #243b4c;
  --gold: #e0b44a;
  --gold-dim: #b8922e;
  --mist: #ede8df;
  --paper: #fffcf7;
  --leather: #6b2d35;
  --steel: #5a6b74;
  --ok: #2f6f4e;
  --line: #d5cfc4;
  --shadow: 0 10px 30px rgba(18, 32, 44, 0.08);
  --sidebar: 260px;
  --sidebar-min: 76px;
  --top: 64px;
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
}

body.app-body {
  margin: 0;
  background: var(--mist);
  color: var(--ink);
  font-family: "Figtree", "Segoe UI", sans-serif;
  font-size: 15px;
}

h1, h2, h3, .display {
  font-family: "Syne", "Figtree", sans-serif;
  letter-spacing: -0.03em;
}

.mono, .ticket-no, .stat-value {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  background: linear-gradient(180deg, var(--ink) 0%, #0c1620 100%);
  color: #f4efe6;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: width .22s ease, transform .22s ease;
  border-right: 1px solid rgba(224, 180, 74, .18);
}

body.nav-collapsed .sidebar { width: var(--sidebar-min); }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 14px;
  border-bottom: 1px dashed rgba(224, 180, 74, .35);
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--gold);
  color: var(--ink);
  display: grid;
  place-items: center;
  font-family: "Syne", sans-serif;
  font-weight: 800;
  flex: 0 0 40px;
}

.brand-text { line-height: 1.1; }
.brand-text small { display: block; color: #c9c0b0; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
body.nav-collapsed .brand-text,
body.nav-collapsed .nav-label,
body.nav-collapsed .nav-section { display: none; }

.nav-scroll {
  overflow: auto;
  padding: 12px 10px 24px;
  flex: 1;
}

.nav-section {
  color: #9aa7af;
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  padding: 14px 10px 6px;
}

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #e8e2d6;
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 10px;
  margin-bottom: 2px;
}

.portal-tabs {
  border-bottom: 1px solid var(--line);
  gap: 0;
}

.portal-tabs .nav-item {
  margin-bottom: -1px;
}

.portal-tab-btn {
  display: block;
  color: var(--ink) !important;
  background: transparent;
  text-decoration: none;
  padding: .55rem 1rem;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: .375rem .375rem 0 0;
  font-weight: 600;
}

.portal-tab-btn:hover {
  color: var(--gold-dim) !important;
  background: rgba(255, 252, 247, .85);
}

.portal-tab-btn.active {
  color: var(--ink) !important;
  background: var(--paper);
  border-color: var(--line);
  border-bottom-color: var(--paper);
}

.portal-tabs-wrap .tab-pane {
  display: none;
}

.portal-tabs-wrap .tab-pane.active {
  display: block;
}

.sidebar .nav-link i { width: 18px; text-align: center; color: var(--gold); }
.sidebar .nav-link:hover, .sidebar .nav-link.active {
  background: var(--ink-3);
  color: #fff;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  height: var(--top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: rgba(255, 252, 247, .9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.shell {
  margin-left: var(--sidebar);
  min-height: 100vh;
  transition: margin-left .22s ease;
}

body.nav-collapsed .shell { margin-left: var(--sidebar-min); }

.page {
  padding: 22px 22px 48px;
}

.ticket-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.ticket-card::before {
  content: "";
  display: block;
  height: 14px;
  background:
    radial-gradient(circle at 10px 0, transparent 7px, var(--paper) 8px) 0 0 / 20px 14px repeat-x,
    linear-gradient(var(--gold), var(--gold));
  background-color: var(--gold);
}

.ticket-card .card-body { padding: 18px 20px 20px; }

.page-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.page-title h1 { font-size: 1.7rem; margin: 0; }
.page-title p { margin: 4px 0 0; color: var(--steel); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-value { font-size: 1.6rem; color: var(--ink); }
.stat-label { color: var(--steel); font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; }

.table thead th {
  font-size: .75rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--steel);
  border-bottom-color: var(--line);
}

.table td { vertical-align: middle; }

.btn-gold {
  background: var(--gold);
  color: var(--ink);
  border: 0;
  font-weight: 700;
}

.btn-gold:hover { background: var(--gold-dim); color: #fff; }

.btn-ink {
  background: var(--ink);
  color: #fff;
  border: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #efe6cf;
  color: #6a5314;
}

.chip.ok { background: #d9efe4; color: var(--ok); }
.chip.warn { background: #f3e0c8; color: #8a4b12; }
.chip.bad { background: #f4d7da; color: var(--leather); }

.flash {
  border-left: 4px solid var(--gold);
  background: #fff7e6;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.flash.warn { border-color: #c47b22; background: #fff1de; }
.flash.bad { border-color: var(--leather); background: #fbecee; }

.form-control, .form-select {
  border-color: var(--line);
  border-radius: 10px;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  background: var(--ink);
}

.login-story {
  padding: 56px;
  color: #f6f0e6;
  background:
    radial-gradient(circle at 20% 20%, rgba(224,180,74,.18), transparent 40%),
    linear-gradient(160deg, #12202c, #0a1218);
}

.login-story h1 { font-size: clamp(2rem, 4vw, 3.4rem); max-width: 12ch; }
.login-panel {
  background: var(--mist);
  display: grid;
  place-items: center;
  padding: 28px;
}

.login-card { width: min(420px, 100%); }

.receipt {
  width: 360px;
  margin: 0 auto;
  background: #fff;
  color: #111;
  padding: 18px 16px 28px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.receipt h2 { font-family: "Syne", sans-serif; text-align: center; }
.receipt .dash { border-top: 1px dashed #999; margin: 8px 0; }

@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-105%);
    width: min(84vw, 280px);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-collapsed .sidebar { width: min(84vw, 280px); }
  .shell, body.nav-collapsed .shell { margin-left: 0; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-story { padding: 28px 22px 12px; min-height: 34vh; }
  body.nav-collapsed .brand-text,
  body.nav-collapsed .nav-label,
  body.nav-collapsed .nav-section { display: block; }
}

@media (max-width: 575.98px) {
  .page { padding: 14px 12px 36px; }
  .stat-grid { grid-template-columns: 1fr; }
  .page-title h1 { font-size: 1.35rem; }
}

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 18, .45);
  z-index: 1030;
}

body.nav-open .scrim { display: block; }

.crud-actions {
  flex-wrap: wrap;
  gap: 0.25rem;
}

.crud-actions .btn {
  white-space: nowrap;
}

.rights-grid th,
.rights-grid td {
  vertical-align: middle;
}

.rights-grid td:first-child {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.82rem;
}

.report-book .report-section {
  margin-bottom: 2.5rem;
}

.report-book h2 {
  font-size: 1.15rem;
  margin-bottom: 0.5rem;
}

.report-grid th,
.report-grid td {
  font-size: 0.82rem;
  white-space: nowrap;
}

.report-list {
  display: grid;
  gap: 12px;
}

.report-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.report-card:hover {
  border-color: var(--gold);
  box-shadow: 0 4px 18px rgba(18, 32, 44, 0.08);
  color: inherit;
}

.report-card-icon {
  font-size: 1.5rem;
  color: var(--gold);
  flex-shrink: 0;
}

.report-card-body h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.report-card-body p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--steel);
}

.report-card-arrow {
  margin-left: auto;
  color: var(--steel);
  flex-shrink: 0;
}

.report-cat:first-child {
  margin-top: 0 !important;
}

.report-heatmap .heatmap-cell {
  text-align: center;
  font-size: 0.78rem;
  background: rgba(224, 180, 74, calc(var(--heat, 0) / 100));
}

.dashboard-reports {
  margin-top: 1.5rem;
}

.dashboard-reports h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.payslip-slip {
  max-width: 420px;
  margin: 0 auto;
  padding: 1.5rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.payslip-head h2 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
}

.payslip-meta {
  width: 100%;
  font-size: 0.9rem;
}

.payslip-meta td {
  padding: 0.15rem 0;
}

.payslip-meta td:first-child {
  color: var(--steel);
  width: 38%;
}

.payslip-net td {
  border-top: 2px solid var(--ink);
  padding-top: 0.5rem;
}

@media print {
  .break-before { break-before: page; page-break-before: always; }
  .payslip-slip { border: none; max-width: none; }
  .sidebar, .topbar, .no-print, .scrim, .page-title, header, footer, .nav-scroll, .brand {
    display: none !important;
  }
  .shell, body.nav-collapsed .shell { margin: 0 !important; }
  .page { padding: 0 !important; }
  @page { margin: 0; }
}

/* --- usability fixes --- */
.crud-row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; }
.crud-row-actions .crud-delete { margin-left: auto; }
.list-search { max-width: 420px; }
.flash ul { padding-left: 1.2rem; }
body.nav-collapsed .nav-filter { display: none; }

/* ---------- Checkout ---------- */
.co-tiles { max-height: 60vh; overflow-y: auto; }
.co-cat { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: #6c757d; margin: .5rem 0 .25rem; }
.co-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .5rem; }
.co-tile { display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: .15rem; min-height: 76px; padding: .6rem .7rem;
  border: 1px solid #dee2e6; border-radius: .6rem; background: #fff; cursor: pointer; transition: border-color .1s, box-shadow .1s; }
.co-tile:hover, .co-tile:focus-visible { border-color: #b08d57; box-shadow: 0 0 0 .2rem rgba(176,141,87,.2); outline: none; }
.co-tile:active { transform: scale(.98); }
.co-name { font-weight: 600; line-height: 1.2; }
.co-price { font-size: .85rem; color: #495057; }
.co-stock { font-size: .72rem; color: #6c757d; }
.co-low .co-stock { color: #b02a37; }
.co-line { border-bottom: 1px solid #eee; padding: .5rem 0; }
.co-qty { width: 118px; flex: 0 0 auto; }
.co-results { max-height: 240px; overflow-y: auto; }
@media (min-width: 992px) { .co-sticky { position: sticky; top: 1rem; } }
@media (max-width: 575px) { .co-grid { grid-template-columns: repeat(2, 1fr); } }

/* =========================================================
   Mobile-first layer (phones are the main device)
   ========================================================= */
.bottom-nav { display: none; }
@media (max-width: 991.98px) {
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1035;
    background: var(--ink); border-top: 1px solid rgba(255,255,255,.08);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bn-item {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 58px; color: #c9d2da; text-decoration: none; font-size: .72rem; background: none; border: 0;
  }
  .bn-item i { font-size: 1.3rem; line-height: 1; }
  .bn-item.active, .bn-item:hover, .bn-item:focus-visible { color: var(--gold); }
  .bn-item:focus-visible { outline: 2px solid var(--gold); outline-offset: -4px; }
  body.has-bottom-nav .page { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .topbar { position: sticky; top: 0; z-index: 1020; }
  .sidebar { z-index: 1040; }
  .scrim { z-index: 1036; }
}

/* Touch-friendly controls on phones and tablets */
@media (max-width: 991.98px) {
  .form-control, .form-select { min-height: 44px; font-size: 16px; } /* 16px stops iOS zooming into inputs */
  .form-control-sm, .form-select-sm { min-height: 40px; font-size: 15px; }
  .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .35rem; }
  .btn-sm { min-height: 40px; padding: .35rem .7rem; }
  .btn-link.p-0 { min-height: 0; }
  .page-title { flex-wrap: wrap; gap: .75rem; }
  .page-title > .d-flex, .page-title > div:last-child:not(:first-child) { flex-wrap: wrap; }
  .nav-scroll .nav-link { min-height: 46px; display: flex; align-items: center; }
  .chart-box, canvas { max-width: 100% !important; }
}

/* Lists: tables become stacked cards on small screens (labels come from the column headers, see app.js) */
@media (max-width: 767.98px) {
  .page table.table:not(.no-cards) thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .page table.table:not(.no-cards), .page table.table:not(.no-cards) tbody,
  .page table.table:not(.no-cards) tr, .page table.table:not(.no-cards) td { display: block; width: 100%; }
  .page table.table:not(.no-cards) tr {
    background: #fff; border: 1px solid #e6e1d8; border-radius: 12px; margin-bottom: .75rem;
    padding: .5rem .75rem; box-shadow: 0 1px 2px rgba(0,0,0,.04);
  }
  .page table.table:not(.no-cards) td {
    border: 0; padding: .3rem 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; text-align: right;
  }
  .page table.table:not(.no-cards) td::before {
    content: attr(data-label); font-weight: 600; color: #6c757d; text-align: left; flex: 0 0 42%; font-size: .85rem;
  }
  .page table.table:not(.no-cards) td[data-label=""]::before { display: none; }
  .page table.table:not(.no-cards) td:first-child { font-weight: 600; font-size: 1.02rem; }
  /* Action cell: full-width row of large buttons */
  .page table.table:not(.no-cards) td.cell-actions { display: block; text-align: left; border-top: 1px solid #f0ece5; margin-top: .35rem; padding-top: .6rem; }
  .page table.table:not(.no-cards) td.cell-actions::before { display: none; }
  .page table.table:not(.no-cards) td.cell-actions .btn,
  .page table.table:not(.no-cards) td.cell-actions a.btn { min-height: 44px; margin: 0 .35rem .35rem 0; }
  .crud-row-actions { flex-wrap: wrap; gap: .4rem; }
  .crud-row-actions .crud-delete { margin-left: 0 !important; }
  .table-responsive { overflow-x: visible; }
  .table-responsive.keep-scroll { overflow-x: auto; }
  .page table.table:not(.no-cards) tfoot { display: block; }
  .page table.table:not(.no-cards) tfoot tr { background: #faf7f0; }
  .stat-grid { gap: .6rem; }
}

/* Checkout / Product sale: sticky total + pay bar on phones */
.co-paybar { display: none; }
@media (max-width: 991.98px) {
  .co-paybar {
    display: flex; align-items: center; gap: .75rem; position: fixed; left: 0; right: 0; z-index: 1034;
    bottom: calc(58px + env(safe-area-inset-bottom)); padding: .55rem .9rem; background: #fff;
    border-top: 1px solid #e6e1d8; box-shadow: 0 -4px 14px rgba(0,0,0,.08);
  }
  body:not(.has-bottom-nav) .co-paybar { bottom: env(safe-area-inset-bottom); }
  .co-paybar .co-bar-total { font-size: 1.15rem; font-weight: 700; line-height: 1.1; }
  .co-paybar .co-bar-sub { font-size: .75rem; color: #6c757d; }
  .co-paybar .btn { margin-left: auto; min-width: 42%; }
  body.has-paybar .page { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
  .co-tiles { max-height: none; }
  .co-tile { min-height: 84px; }
}

/* Reports and charts */
@media (max-width: 767.98px) {
  .report-filters .col, .report-filters [class*="col-"] { flex: 0 0 100%; max-width: 100%; }
  .ticket-card .card-body { padding: 1rem .9rem; }
}

/* Login on phones */
@media (max-width: 575.98px) {
  .login-story { min-height: auto; padding: 22px 18px 6px; }
  .login-story h1 { font-size: 1.6rem; }
  .login-panel { padding: 12px; }
  .login-card .btn { width: 100%; min-height: 48px; }
  .login-card .form-control { min-height: 48px; font-size: 16px; }
}
@media print { .bottom-nav, .co-paybar { display: none !important; } }

/* Clock in/out camera (staff portal) */
.camera-panel .camera-frame { position: relative; background: #12202c; border-radius: 8px; overflow: hidden; max-width: 320px; }
.camera-panel video { display: block; width: 100%; max-height: 240px; object-fit: cover; transform: scaleX(-1); }
.camera-countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 4rem; font-weight: 700; color: #e0b44a; background: rgba(0,0,0,.35); }

/* Report heatmap (time-of-day report) */
.report-heatmap .heatmap-cell { background: rgba(224, 180, 74, calc(var(--heat, 0) / 100)); }
.report-totals { color: var(--bs-secondary-color, #5a6b74); }

/* Bookings: week strip + day list */
.booking-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.booking-day { display: flex; flex-direction: column; align-items: center; padding: 6px 0; border-radius: 10px; text-decoration: none; color: inherit; border: 1px solid transparent; min-height: 56px; }
.booking-day:hover { background: rgba(224,180,74,.12); }
.booking-day.today { border-color: #e0b44a; }
.booking-day.active { background: #12202c; color: #fff; }
.booking-count { font-size: .75rem; color: #b07d10; }
.booking-day.active .booking-count { color: #e0b44a; }
.booking-time { min-width: 52px; font-size: 1.05rem; }
.booking-card .btn { min-height: 38px; }
