/* DAS POS — shared theme
   One stylesheet drives every screen. Tweak the variables below to re-theme. */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #4f46e5;
  --primary-ink: #ffffff;
  --primary-dark: #4338ca;
  --sidebar: #111827;
  --sidebar-ink: #e5e7eb;
  --sidebar-active: #4f46e5;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- App shell ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar .brand {
  padding: 18px 20px; font-size: 18px; font-weight: 700; color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, .08); letter-spacing: .3px;
}
.sidebar .brand small { display: block; font-size: 11px; font-weight: 400; color: #9ca3af; }
.nav { padding: 10px 0; flex: 1; overflow-y: auto; }
.nav .group { padding: 14px 20px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: #6b7280; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 20px;
  color: var(--sidebar-ink); font-size: 14px; border-left: 3px solid transparent;
}
.nav a:hover { background: rgba(255, 255, 255, .05); text-decoration: none; }
.nav a.active { background: rgba(79, 70, 229, .18); border-left-color: var(--sidebar-active); color: #fff; }
.nav .ico { width: 18px; text-align: center; opacity: .9; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 22px;
}
.topbar .title { font-size: 16px; font-weight: 600; }
.topbar .user { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 10px; }
.topbar .user b { color: var(--ink); }
.topbar .user form { display: inline-flex; align-items: center; margin: 0; }
.topbar .store-select { font-size: 13px; }
.content { padding: 22px; flex: 1; }

/* ---------- Cards & page header ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card h2 { font-size: 15px; margin: 0 0 12px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 900px) { .grid.cols-3, .grid.cols-4, .grid.cols-5 { grid-template-columns: repeat(2, 1fr); } }

/* Stat tiles */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.stat.accent { border-top: 3px solid var(--primary); }
.stat.warn { border-top: 3px solid var(--warn); }
.stat.success { border-top: 3px solid var(--success); }

/* ---------- Tables ---------- */
table.data { width: 100%; border-collapse: collapse; background: var(--surface); }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafafa; }
table.data tr:hover td { background: #fafbff; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.total td { font-weight: 700; background: #f5f3ff; border-top: 2px solid var(--primary); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); cursor: pointer;
  font-size: 14px; font-weight: 500; }
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
form .field { margin-bottom: 14px; }
form label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
input[type=text], input[type=number], input[type=password], input[type=email],
input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }
.help { color: var(--muted); font-size: 12px; margin-top: 4px; }
.errorlist { color: var(--danger); font-size: 13px; margin: 4px 0; padding-left: 18px; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }

/* ---------- Misc ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.yes { background: #fef3c7; color: #92400e; }
.badge.no { background: #dcfce7; color: #166534; }
.badge.low { background: #fee2e2; color: #991b1b; }
.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 11px 14px; border-radius: 8px; margin-bottom: 8px; font-size: 14px; }
.messages li.success { background: #dcfce7; color: #166534; }
.messages li.error { background: #fee2e2; color: #991b1b; }
.messages li.info { background: #dbeafe; color: #1e40af; }
.muted { color: var(--muted); }
.right { text-align: right; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type=text], .toolbar select { width: auto; min-width: 180px; }
.toolbar input[type=date] { width: auto; min-width: 0; }
.toolbar label { margin-bottom: 0; }

/* ---------- Searchable select (combobox) ---------- */
/* Progressive enhancement of a <select>: without JS the native select shows;
   .js-ready (added by the enhancer) hides it and reveals the search input. */
.combo { position: relative; }
.combo:not(.js-ready) .combo-input,
.combo:not(.js-ready) .combo-list { display: none; }
.combo.js-ready select { display: none; }
.combo-input { width: 100%; }
.combo-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 3px);
  margin: 0; padding: 4px; list-style: none; max-height: 260px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow);
}
.combo-list[hidden] { display: none; }
.combo-list li { padding: 8px 10px; border-radius: 6px; font-size: 14px; cursor: pointer; }
.combo-list li.active, .combo-list li:hover { background: #eef2ff; color: var(--primary-dark); }
.combo-list li.empty, .combo-list li.empty:hover { background: transparent; color: var(--muted); cursor: default; }
.combo-list .code { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--sidebar); }
.login-card { background: var(--surface); padding: 32px; border-radius: 14px; box-shadow: var(--shadow); width: 340px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); margin-bottom: 20px; font-size: 13px; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(17, 24, 39, .5);
  display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--surface); border-radius: 14px; padding: 24px;
  width: 440px; max-width: 92vw; max-height: 90vh; overflow-y: auto; box-shadow: 0 12px 48px rgba(0, 0, 0, .3); }
.modal h2 { margin: 0 0 12px; font-size: 17px; }
.modal h3 { color: var(--muted); }

/* ---------- Responsive (mobile / tablet) ---------- */
/* Hamburger + drawer scaffolding. Hidden on desktop; activated below the breakpoint. */
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.nav-toggle { display: none; background: transparent; border: 0; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--ink); padding: 4px 8px; border-radius: 8px; }
.nav-toggle:hover { background: #f3f4f6; }
.sidebar-backdrop { display: none; }
/* Table scroll wrapper (added by JS around every table.data). No-op on desktop. */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media screen and (max-width: 820px) {
  .nav-toggle { display: inline-flex; }

  /* Sidebar becomes an off-canvas drawer that slides over the content. */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 200; width: 250px;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .45);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; z-index: 150;
    background: rgba(0, 0, 0, .45); }

  .topbar { height: 52px; padding: 0 12px; }
  .topbar .title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .content { padding: 14px; }
  .page-head { flex-wrap: wrap; gap: 10px; }
  .page-head h1 { font-size: 18px; }

  /* Stack multi-column layouts into a single column. !important overrides the
     inline grid-template-columns set on some pages (e.g. the till). */
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .grid.cols-5 { grid-template-columns: 1fr !important; }
  .form-row { grid-template-columns: 1fr; }

  /* Wide tables scroll sideways rather than crushing their columns. */
  .table-scroll table.data th, .table-scroll table.data td { white-space: nowrap; }

  /* Toolbar filters: let text/select inputs shrink and fill the row. */
  .toolbar input[type=text], .toolbar select { min-width: 0; flex: 1 1 140px; }

  .login-card { width: 100%; max-width: 360px; }
}

/* ---------- Print (receipts/reports) ---------- */
@media print {
  /* Thermal printers feed a continuous roll, not discrete sheets. Declaring the
     page as 80mm wide with `auto` height tells the browser the page can be any
     length, so a long receipt prints as ONE continuous page instead of being
     paginated onto a second "sheet" — which the printer then cuts at each page
     boundary (the cause of receipts splitting/cutting at ~12 line items). */
  @page { size: 80mm auto; margin: 0; }

  .sidebar, .topbar, .no-print, .btn-row, .toolbar { display: none !important; }
  .content, .main, .layout { display: block; padding: 0; margin: 0; }
  /* The mobile table-scroll wrapper would clip the right-hand columns (Price/Total)
     off a narrow receipt. Disable its scroll/clipping for print. */
  .table-scroll { overflow: visible !important; width: auto !important; }
  .card { box-shadow: none; border: none; }
  body { background: #fff; }
  .receipt { width: 80mm; margin: 0 auto; font-size: 14px; }

  /* Scale receipt up ~120% so it prints at a good size on thermal paper. */
  .receipt, .receipt table.data { font-size: 14px !important; }
  .receipt h2 { font-size: 19px; }

  /* Force everything black so it stays legible on a POS thermal printer. */
  .receipt, .receipt * { color: #000 !important; }
  .receipt .muted { color: #000 !important; }

  /* Thermal printers are 1-bit (black-or-nothing). Browsers anti-alias glyph
     edges to gray, which a thermal head under-heats -> thin/faded text. Counter
     this with: exact color (no driver "ink saving"), a heavier stroke weight so
     more pixels stay fully black, and a sturdy monospace font with thick,
     uniform strokes that survive the 1-bit conversion. */
  .receipt, .receipt * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
    text-shadow: none !important;
    font-family: "Consolas", "Courier New", monospace !important;
  }
  .receipt table.data,
  .receipt table.data th,
  .receipt table.data td,
  .receipt table.data tr.total td {
    border-color: var(--border) !important;
    background: #fff !important;
  }

  /* Belt-and-suspenders: never break inside a row, and keep each line item's
     name row glued to its qty/price/total row so a pair can't straddle a cut. */
  .receipt tr { page-break-inside: avoid; break-inside: avoid; }
  .receipt .item-row { page-break-after: avoid; break-after: avoid; }
}
