/* ─── Cafe POS — stylesheet ─────────────────────────────────────────────── */
:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #faf9f5;
  --border: #e6e1d6;
  --border-strong: #d3ccba;
  --text: #2a241c;
  --muted: #7a7062;
  --accent: #6f4e37;          /* coffee brown */
  --accent-hover: #5a3f2c;
  --accent-soft: #f0e6dc;
  --good: #2f8f5e;
  --warn: #c98a14;
  --bad:  #c0392b;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --r: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  /* Respect iPhone notch & home-bar when installed as a PWA */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  /* Disable double-tap-to-zoom on POS screen — annoying for cashiers */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.center { text-align: center; }
.right { text-align: right; }
.row { display: flex; gap: 12px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.gap-sm { gap: 6px; }
.gap-lg { gap: 18px; }
.full { width: 100%; }
.spacer { flex: 1; }
.error { color: var(--bad); margin-top: 8px; min-height: 18px; }
.ok    { color: var(--good); }
.warn  { color: var(--warn); }
code { background: #f0ebe0; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ─── LOGIN ───────────────────────────────────────────────── */
.login-wrap {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #f5e9d8 0%, #ddc8a6 100%);
}
.login-card {
  background: var(--surface);
  padding: 32px 32px 24px;
  border-radius: 14px;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
  text-align: center;
}
.login-card .logo {
  font-size: 44px; line-height: 1;
}
.login-card h1 { margin: 8px 0 4px; font-size: 20px; letter-spacing: 0.5px; }

/* ─── Brand initials badge (GI logo) ──────────────────────── */
.brand-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.5px;
  border-radius: 50%;
  user-select: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.brand-initials.big {
  width: 72px; height: 72px;
  font-size: 26px;
  margin: 4px auto 8px;
  box-shadow: 0 4px 18px rgba(111,78,55,0.35);
}
.brand-initials.small {
  width: 38px; height: 38px;
  font-size: 14px;
}

.login-card form { text-align: left; margin-top: 20px; }
.login-card label {
  display: block; font-size: 12px; color: var(--muted);
  margin: 14px 0 4px;
}
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: 8px; font-size: 14px; background: #fff;
}
.login-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.login-card .hint { margin-top: 18px; }
.login-card .big { margin-top: 18px; }

/* ─── APP SHELL ─────────────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 230px;
  background: #2a241c;
  color: #ddd2bf;
  display: flex; flex-direction: column;
  flex-shrink: 0;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 18px; border-bottom: 1px solid #3a3225; }
.logo.small { font-size: 26px; }
.brand-title { font-weight: 700; color: #fff; font-size: 16px; }
.brand-sub { font-size: 12px; color: #a89c87; }

#nav { padding: 8px 6px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; gap: 10px; align-items: center;
  padding: 9px 12px; margin: 2px 0;
  border-radius: 8px; cursor: pointer; user-select: none;
  font-size: 13.5px; color: #d4c8b3;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 500; }
.nav-icon { width: 18px; text-align: center; opacity: 0.85; }
.nav-section { padding: 12px 14px 4px; font-size: 11px; color: #7a6e58; text-transform: uppercase; letter-spacing: 0.5px; }

.sidebar-bottom { border-top: 1px solid #3a3225; padding: 12px; }
.user-chip { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
}

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.page-title { font-size: 19px; font-weight: 600; }
.topbar-right { display: flex; gap: 12px; align-items: center; }
.shift-pill {
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.shift-pill.open { background: #e3f4ea; color: var(--good); }
.shift-pill.closed { background: #fbe8e6; color: var(--bad); }

#view {
  flex: 1; overflow-y: auto;
  padding: 20px 22px;
}

/* ─── COMMON UI ─────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card-h { font-size: 14px; font-weight: 600; margin: 0 0 12px; }
.grid { display: grid; gap: 14px; }
.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); }
@media (max-width: 1100px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

.btn {
  background: var(--surface); border: 1px solid var(--border-strong);
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font-size: 13.5px; color: var(--text); font-weight: 500;
  transition: all .12s ease;
}
.btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: inherit; }
.btn.ghost:hover { background: rgba(0,0,0,0.05); }
.btn.danger { background: #fff; border-color: var(--bad); color: var(--bad); }
.btn.danger:hover { background: var(--bad); color: #fff; }
.btn.success { background: var(--good); border: 1px solid var(--good); color: #fff; }
.btn.big { padding: 12px 16px; font-size: 15px; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

input[type="text"], input[type="number"], input[type="password"],
input[type="date"], input[type="email"], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong);
  border-radius: 7px; font-size: 13.5px; background: #fff;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 3px; font-weight: 500; }

table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
tr:hover td { background: var(--surface-2); }
.badge {
  display: inline-block; font-size: 11px; padding: 2px 8px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-weight: 500;
}
.badge.good { background: #e3f4ea; color: var(--good); }
.badge.bad  { background: #fbe8e6; color: var(--bad); }
.badge.warn { background: #fef3d6; color: var(--warn); }

/* ─── KPI ───────────────────────────────────────────── */
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 2px; }
.kpi .delta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.accent .value { color: var(--accent); }
.kpi.good .value { color: var(--good); }
.kpi.bad .value { color: var(--bad); }

/* ─── POS SCREEN ───────────────────────────────────────── */
.pos-layout { display: grid; grid-template-columns: 1fr 380px; gap: 16px; height: calc(100vh - 110px); }
@media (max-width: 1000px) { .pos-layout { grid-template-columns: 1fr; height: auto; } }

.menu-side { display: flex; flex-direction: column; min-height: 0; }
.cat-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.cat-tab {
  padding: 6px 12px; background: #fff; border: 1px solid var(--border-strong);
  border-radius: 999px; cursor: pointer; font-size: 13px;
}
.cat-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  overflow-y: auto;
  padding-right: 4px;
}
.product-tile {
  background: #fff; border: 1px solid var(--border);
  border-radius: 10px; padding: 12px;
  cursor: pointer; user-select: none;
  transition: transform .06s, box-shadow .12s, border-color .12s;
  display: flex; flex-direction: column; justify-content: space-between;
  min-height: 88px;
}
.product-tile:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.product-tile:active { transform: scale(0.98); }
.product-tile.disabled { opacity: 0.45; cursor: not-allowed; }
.product-tile .name { font-weight: 600; font-size: 13.5px; line-height: 1.3; }
.product-tile .price { color: var(--accent); font-weight: 700; margin-top: 8px; font-size: 14px; }
.product-tile .stock { font-size: 11px; color: var(--muted); margin-top: 2px; }
.product-tile .stock.low { color: var(--warn); }

.cart-side {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--r);
  display: flex; flex-direction: column;
  min-height: 0;
}
.cart-header { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.cart-items { flex: 1; overflow-y: auto; padding: 4px; }
.cart-item {
  display: grid; grid-template-columns: 1fr auto;
  gap: 4px 10px; padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.cart-item .name { font-weight: 500; font-size: 13px; }
.cart-item .controls { display: flex; gap: 4px; align-items: center; }
.qty-btn {
  width: 26px; height: 26px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: #fff; cursor: pointer; font-weight: 600;
}
.qty-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.qty-val { width: 32px; text-align: center; font-weight: 600; }
.line-total { font-weight: 600; color: var(--accent); }
.cart-empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.cart-totals { padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }
.tot-row { display: flex; justify-content: space-between; padding: 3px 0; }
.tot-row.grand { font-size: 18px; font-weight: 700; padding-top: 6px; border-top: 1px solid var(--border); margin-top: 4px; }

.cart-actions { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }

/* ─── MODAL ───────────────────────────────────────────── */
#modal-root { position: fixed; inset: 0; pointer-events: none; z-index: 100; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); pointer-events: auto;
  display: flex; align-items: center; justify-content: center;
  animation: fade .12s ease;
}
.modal {
  background: #fff; border-radius: 12px; max-width: 90vw; width: 460px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: pop .14s ease;
}
.modal.large { width: 720px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ─── RECEIPT ─────────────────────────────────────────── */
.receipt {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  width: 280px;
  margin: 0 auto;
  background: #fff;
  padding: 16px;
  color: #000;
}
.receipt .center { text-align: center; }
.receipt .right { text-align: right; }
.receipt h3 { margin: 4px 0; }
.receipt .line { border-top: 1px dashed #555; margin: 6px 0; }
.receipt table { font-size: 11px; }
.receipt th, .receipt td { padding: 2px 4px; border: none; text-transform: none; letter-spacing: 0; color: #000; font-weight: normal;}

@media print {
  body { background: #fff; }
  body * { visibility: hidden; }
  .receipt, .receipt * { visibility: visible; }
  .receipt { position: fixed; left: 0; top: 0; width: 80mm; padding: 4mm; }
  .modal-header, .modal-footer { display: none !important; }
  .modal-backdrop { background: #fff !important; }
  .modal { box-shadow: none !important; max-width: none; width: auto; }
}

/* ─── BANNER ─────────────────────────────────────────── */
.banner {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 14px;
  background: #fef7e3; border: 1px solid #f3e2a4; color: #6e5500;
  font-size: 13px;
}
.banner.danger { background: #fbe8e6; border-color: #ecc7c2; color: #6e1410; }
.banner.success { background: #e3f4ea; border-color: #b9deca; color: #1a5d3a; }

.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }
.list-row { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }

/* ─── Mobile menu / drawer / cart sheet (default: hidden on desktop) ─── */
.mobile-only { display: none; }

.icon-btn {
  width: 40px; height: 40px; border: none; background: transparent;
  border-radius: 8px; cursor: pointer;
  display: inline-flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  padding: 0;
}
.icon-btn span {
  display: block; width: 22px; height: 2px;
  background: var(--text); border-radius: 2px;
}
.icon-btn:hover { background: rgba(0,0,0,0.05); }

#overlay-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 40;
  display: none;
  animation: fade .15s ease;
}
body.sidebar-open #overlay-backdrop,
body.cart-open #overlay-backdrop { display: block; }

#mobile-cart-pill {
  position: fixed; left: 12px; right: 12px; bottom: 12px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 14px;
  padding: 14px 18px;
  font-size: 15px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(111,78,55,0.45);
  z-index: 30; cursor: pointer;
  display: none;
  align-items: center; justify-content: space-between;
  /* Respect iPhone home-bar */
  margin-bottom: env(safe-area-inset-bottom);
}
#mobile-cart-pill .cart-pill-count {
  background: rgba(255,255,255,0.25); padding: 3px 10px; border-radius: 999px;
  margin-right: 8px; font-size: 13px;
}

/* ─────────────────────────────────────────────────────────────────────
 * MOBILE / TABLET breakpoint — applies up to 768px wide
 * ───────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body { font-size: 15px; }

  /* ── Sidebar becomes a slide-in drawer ── */
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: 78%; max-width: 300px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.25);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }

  /* Show hamburger button on mobile */
  .mobile-only { display: inline-flex; }

  /* ── Topbar ── */
  .topbar { padding: 10px 12px; gap: 10px; }
  .page-title { font-size: 17px; flex: 1; }
  .topbar-right { gap: 8px; }
  .shift-pill { font-size: 11px; padding: 4px 9px; }

  /* ── Main content gets full width ── */
  .content { width: 100%; }
  #view { padding: 14px 12px; padding-bottom: 100px; /* room for cart pill */ }

  /* ── Cards ── */
  .card { padding: 14px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }

  /* ── POS layout: products fill the screen, cart becomes bottom sheet ── */
  .pos-layout { grid-template-columns: 1fr; height: auto; gap: 0; }
  .menu-side { padding-bottom: 80px; }
  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 8px;
  }

  /* Cart slides up from the bottom */
  .cart-side {
    position: fixed; left: 0; right: 0; bottom: 0;
    max-height: 85vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 0.25s ease;
    z-index: 60;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.25);
  }
  body.cart-open .cart-side { transform: translateY(0); }

  .cart-header {
    /* visible drag handle line */
    padding-top: 8px;
    position: relative;
  }
  .cart-header::before {
    content: ''; position: absolute; top: 6px; left: 50%;
    transform: translateX(-50%);
    width: 36px; height: 4px; background: var(--border-strong); border-radius: 2px;
  }

  /* Show the floating cart pill on mobile when in POS view */
  body.pos-view #mobile-cart-pill { display: flex; }
  /* But hide it while the cart sheet is open */
  body.cart-open #mobile-cart-pill { display: none; }

  /* ── Touch-friendly tap targets ── */
  .qty-btn { width: 38px; height: 38px; font-size: 18px; }
  .btn { padding: 10px 14px; min-height: 42px; font-size: 14px; }
  .btn.small { padding: 7px 11px; min-height: 34px; font-size: 13px; }
  .btn.big { padding: 14px 18px; min-height: 50px; font-size: 16px; }

  input, select, textarea { font-size: 16px; padding: 10px 12px; min-height: 42px; } /* 16px prevents iOS zoom */
  label { font-size: 13px; }

  .nav-item { padding: 12px 14px; font-size: 15px; }

  /* ── Tables overflow to horizontal scroll ── */
  .card > table,
  .card > div > table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  th, td { padding: 10px 12px; }

  /* ── Modals: full-screen on phone for room ── */
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    display: flex; flex-direction: column;
  }
  .modal-body { flex: 1; overflow-y: auto; }
  .modal.large { width: 100% !important; }

  /* ── Login card slightly smaller ── */
  .login-card { width: 92%; max-width: 360px; padding: 28px 22px 22px; }

  /* ── Hide branch switcher select label crowding ── */
  #branch-switcher { max-width: 140px; }
}

/* ─── Phones only (<= 480px) — tighter still ─── */
@media (max-width: 480px) {
  .product-tile { min-height: 76px; padding: 10px; }
  .product-tile .name { font-size: 12.5px; }
  .product-tile .price { font-size: 13px; }

  /* Single-column KPIs even on the dashboard */
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 20px; }
}

/* ─── PWA standalone mode tweaks (when launched from home screen) ─── */
@media (display-mode: standalone) {
  /* Slightly tighter top padding since there's no browser chrome */
  .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
}

