:root {
  --bg: #f6f7f9; --card: #fff; --ink: #1c2430; --muted: #6b7684;
  --line: #e3e7ec; --brand: #2f6f4f; --brand-dark: #245c40;
  --danger: #c0392b; --warn: #b9770e; --good: #2f6f4f;
  --radius: 12px; --shadow: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html {
  /* Stop iOS inflating text when the phone is rotated to landscape. */
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
header {
  position: sticky; top: 0; z-index: 10; background: var(--card);
  border-bottom: 1px solid var(--line); padding: 12px 20px;
  box-shadow: var(--shadow);
}
header h1 { margin: 0 0 8px; font-size: 20px; }
nav { display: flex; flex-wrap: wrap; gap: 6px; }
nav button {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 7px 13px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500;
}
nav button:hover { background: var(--bg); }
nav button.active { background: var(--brand); color: #fff; }
main { max-width: 1000px; margin: 22px auto; padding: 0 20px; }
.tab { display: none; }
.tab.active { display: block; }

h2 { font-size: 18px; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }

label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .02em; }
input, select {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink);
  /* 16px is not a style choice: iOS Safari zooms the whole page in on focus for any
     field below 16px, and never zooms back out. Do not lower this. */
  font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
/* Selects still need their chevron back after appearance:none. */
select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7684' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  background-size: 11px; padding-right: 30px;
}
input:focus, select:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.field { flex: 1; min-width: 120px; }
.field.narrow { flex: 0 0 110px; }

button.btn {
  border: 0; background: var(--brand); color: #fff; padding: 9px 16px;
  border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 14px;
}
button.btn:hover { background: var(--brand-dark); }
button.btn.ghost { background: #eef1f4; color: var(--ink); }
button.btn.ghost:hover { background: #e2e7ec; }
button.btn.danger { background: #fbeae8; color: var(--danger); }
button.link { border: 0; background: none; color: var(--brand); cursor: pointer; padding: 0; font-size: 13px; }
button.link.danger { color: var(--danger); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.low td { background: #fdf6ec; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.pill.low { background: #fbeee0; color: var(--warn); }
.pill.ok { background: #e7f3ec; color: var(--good); }
.pill.drink { background: #e8eefb; color: #3355aa; }
.pill.dish { background: #f0ece0; color: #806020; }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.pos .big { color: var(--good); } .stat.neg .big { color: var(--danger); }

.line-item { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.line-item select { flex: 2; } .line-item input { flex: 1; }
.pos { color: var(--good); } .neg { color: var(--danger); }
.right { margin-left: auto; }

#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 8px;
  opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 50; font-weight: 500;
}
#toast.show { opacity: 1; }
.empty { color: var(--muted); padding: 20px; text-align: center; }

/* header user bar + login */
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#userbar { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); }
#userbar .who { font-weight: 700; color: var(--ink); }
.role-badge { background: var(--brand); color: #fff; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.role-badge.staff { background: #8a94a2; }
.role-badge.manager { background: #3355aa; }
.role-badge.cashier { background: #7d5ba6; }
.role-badge.kitchen { background: #b9770e; }
.role-badge.barista { background: #0e7c86; }

/* Language picker — compact in the header, full width on the login card. */
.lang-select {
  width: auto; padding: 5px 24px 5px 8px; font-size: 12px;
  border-radius: 7px; background-color: #eef1f4; border-color: transparent;
  background-position: right 6px center; background-size: 9px;
}
.lang-row { margin-top: 16px; text-align: center; }
.lang-row .lang-select { width: 100%; padding: 9px 30px 9px 10px; font-size: 14px; }

/* Activity + Manage staff: admin only. */
.admin-only { display: none !important; }
body.is-admin .admin-only { display: inline-block !important; }

/* Wages & Bills: the manager runs the money too, so admin OR manager. */
.payroll-only { display: none !important; }
body.is-admin .payroll-only,
body.is-manager .payroll-only { display: inline-block !important; }

/* ---- permanent monthly statements ---- */
.seal-ok, .seal-bad {
  margin-top: 12px; padding: 10px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 600;
}
.seal-ok  { background: #e7f3ec; color: var(--good); border: 1px solid #bfe0cd; }
.seal-bad { background: #fbeae8; color: var(--danger); border: 1px solid #eeb9b2; }
.seal-warn {
  padding: 10px 12px; border-radius: 8px; font-size: 13px; line-height: 1.6;
  background: #fdf6ec; color: var(--warn); border: 1px solid #f0ddbe;
}

/* Dashboard nudge: days with no sales entered. */
.card.nudge {
  background: #fdf6ec; border-color: #f0ddbe; color: var(--warn); font-size: 14px;
}

.statement-sheet { max-width: 760px; }
.stmt-line {
  display: flex; justify-content: space-between; gap: 20px;
  padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px;
}
.stmt-total {
  display: flex; justify-content: space-between; gap: 20px;
  margin-top: 14px; padding: 12px 0; border-top: 2px solid var(--ink);
  font-size: 18px; font-weight: 700;
}
.stmt-seal {
  margin-top: 22px; padding: 12px; border: 1px dashed var(--line);
  border-radius: 8px; background: var(--bg); font-size: 12px; line-height: 1.7;
}
.stmt-seal code { font-size: 11px; word-break: break-all; color: var(--muted); }

/* A printed statement should be the statement — not the app around it. */
@media print {
  header, #toast, .no-print, .login-overlay { display: none !important; }
  main { max-width: none; margin: 0; padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; margin: 0; }
  .statement-sheet { max-width: none; }
  body { background: #fff; }
  table { page-break-inside: auto; }
  tr { page-break-inside: avoid; }
}

.login-overlay { position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-overlay.hidden { display: none; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,.12); padding: 30px; width: 340px; max-width: 100%; }
.login-card h2 { margin: 0 0 4px; font-size: 22px; }
.login-card > p.muted { margin: 0 0 8px; }
.login-card label { margin-top: 14px; }
.login-card .btn { margin-top: 20px; width: 100%; padding: 11px; font-size: 15px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 10px 0 0; text-align: center; }
small.hint { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }

/* ==========================================================================
   PHONE (Echa enters the day's sales from an iPhone every night)
   ========================================================================== */
@media (max-width: 720px) {

  /* Keep content clear of the notch and the home indicator. */
  header { padding: 10px 12px; padding-left: max(12px, env(safe-area-inset-left)); }
  main {
    margin: 14px auto;
    padding: 0 12px calc(28px + env(safe-area-inset-bottom, 0px));
  }

  /* The top bar has to fit the brand, the user, their role, the language and Log out
     across ~366px. Nothing may wrap; if anything has to give, it is the username. */
  header h1 { font-size: 16px; margin-bottom: 8px; white-space: nowrap; flex: 0 0 auto; }
  .head-row { gap: 8px; }
  #userbar { min-width: 0; }
  #userbar .role-badge { white-space: nowrap; flex: 0 0 auto; }
  #userbar .who {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 72px;
  }
  /* The logout button must not pick up the big-touch-target sizing below —
     it has its own inline padding and would stretch into a two-line block. */
  #userbar button.btn {
    min-height: 34px; padding: 8px 12px; font-size: 13px; white-space: nowrap; width: auto;
  }

  /* Twelve tabs would wrap into four rows and swallow the screen. Make them one
     swipeable strip instead. */
  nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin: 0 -12px;            /* bleed to the screen edges so it reads as scrollable */
    padding: 0 12px 2px;
    gap: 4px;
  }
  nav::-webkit-scrollbar { display: none; }
  nav button {
    flex: 0 0 auto;             /* never squash a tab to fit */
    padding: 9px 14px;
    font-size: 14px;
  }

  /* Tables are the one thing that genuinely cannot fit. Let them scroll sideways
     rather than be cut off or crushed to unreadable. */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    min-width: 100%;
  }
  th, td { padding: 11px 8px; }

  /* Thumb-sized targets. 'edit' / 'delete' were 13px text with no padding — a
     coin-flip to hit on a phone. */
  button.link {
    padding: 8px 6px;
    font-size: 14px;
    display: inline-block;
    min-height: 34px;
  }
  button.btn { padding: 12px 18px; font-size: 15px; min-height: 46px; }

  /* Actions go full width and stack. Side by side, "Save sales & deduct stock"
     wrapped onto two lines inside a half-width button; stacked, the main action is
     unmissable and impossible to mis-tap. */
  .card > button.btn { width: 100%; }
  .row > button.btn { flex: 1 1 100%; width: 100%; }

  /* A sale line (dish + qty + remove) is far too cramped across a phone: give the
     dish its own row. */
  .line-item { flex-wrap: wrap; gap: 8px 6px; }
  .line-item select { flex: 1 0 100%; }
  .line-item input { flex: 2; }

  /* Form fields stack; figures pair up two-across so a month fits on one screen
     instead of four scrolls of enormous cards. */
  .grid { grid-template-columns: 1fr; gap: 10px; }
  .grid.stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .grid.stats .card { padding: 11px; }
  .grid.stats .stat .big { font-size: 19px; }
  .grid.stats .stat .muted { font-size: 12px; line-height: 1.35; }

  .card { padding: 14px; margin-bottom: 14px; }
  .stat .big { font-size: 22px; }

  #userbar { gap: 6px; font-size: 12px; }
  .stmt-line, .stmt-total { gap: 12px; }
  .stmt-seal code { font-size: 10px; }

  /* Sit the toast above the home indicator. */
  #toast { bottom: calc(18px + env(safe-area-inset-bottom, 0px)); left: 12px; right: 12px;
    transform: none; text-align: center; }
}

/* Very narrow phones (iPhone SE / mini): buy back a little more room. */
@media (max-width: 380px) {
  header h1 { font-size: 16px; }
  nav button { padding: 8px 11px; font-size: 13px; }
  main { padding: 0 10px calc(28px + env(safe-area-inset-bottom, 0px)); }
}
