/* Colors are plain variables with a dark override. light-dark() is avoided on purpose:
   older phone browsers ignore it, and every color and border then disappears. */
:root {
  color-scheme: light dark;
  --counter: #e3e9e6;
  --panel: #ffffff;
  --ink: #14211d;
  --hint: #51615a;
  --rule: #c4d0cb;
  --edge: #9fb0a9;
  --tonal: #e8efec;
  --pine: #17574a;
  --pine-ink: #ffffff;
  --steel: #8c9b96;
  --marigold: #f0b30a;
  --marigold-ink: #241b00;
  --danger: #b42f2f;
  --danger-tint: #fbe9e9;
  --ticket: #fffefb;
  --ticket-ink: #1a2420;
  --ticket-hint: #5d6b66;
}

@media (prefers-color-scheme: dark) {
  :root {
    --counter: #0f1c18;
    --panel: #182a25;
    --ink: #e9f1ee;
    --hint: #98aca4;
    --rule: #2c433c;
    --edge: #4a665d;
    --tonal: #243c35;
    --pine: #5cc0a8;
    --pine-ink: #06211b;
    --steel: #4f6660;
    --danger: #f28b8b;
    --danger-tint: #3d2626;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh; min-height: 100dvh; background: var(--counter); color: var(--ink);
  font: 16px/1.45 "Schibsted Grotesk", system-ui, sans-serif;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { opacity: 0.5; cursor: default; }
:is(button, input, textarea, a):focus-visible { outline: 3px solid var(--pine); outline-offset: 2px; }
h1 { margin: 0; font-size: 34px; line-height: 1.1; font-weight: 800; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 20px; font-weight: 800; }
.muted { color: var(--hint); }
.error { color: var(--danger); margin: 10px 0 0; }

/* Every button has a filled background and a border, so it never reads as plain text. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border: 1px solid transparent; border-radius: 10px;
  font-weight: 700; text-decoration: none; background: var(--pine); color: var(--pine-ink);
}
.btn:active { transform: translateY(1px); }
.btn.quiet { background: var(--tonal); color: var(--ink); border-color: var(--edge); }
.btn.danger { background: var(--danger-tint); color: var(--danger); border-color: var(--danger); }

/* Login and first-run */
.solo { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 24px 16px; }
.solo-card { width: min(100%, 440px); padding: 28px; background: var(--panel); border-radius: 14px; }
.solo-card p { margin: 12px 0 0; }
.solo-card .btn { width: 100%; margin-top: 20px; }

/* Layout */
header.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding: 12px 20px; background: var(--panel); }
.brand { font-weight: 800; font-size: 18px; overflow-wrap: anywhere; }
nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
nav button { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 10px; font-weight: 700; color: var(--hint); }
nav button[aria-current="page"] { color: var(--ink); background: var(--counter); }
.badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 6px; padding: 0 6px;
  border-radius: 10px; background: var(--marigold); color: var(--marigold-ink); font-size: 12px; font-weight: 800;
}
.banner { margin: 0; padding: 10px 20px; background: var(--marigold); color: var(--marigold-ink); font-weight: 600; }
.banner.expired { background: var(--danger); color: #fff; }
main { padding: 20px; }

/* The order board: tickets hang from a rail, one rail per stage. */
.stage-tabs { display: none; }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(270px, 1fr); gap: 18px; overflow-x: auto; padding-bottom: 12px; }
.rail-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 6px; }
.rail-head h2 { font-size: 16px; }
.rail { height: 8px; border-radius: 4px; background: var(--steel); box-shadow: inset 0 -2px 0 rgb(0 0 0 / 0.18); }
.rail.new { background: var(--marigold); }
.tickets { display: flex; flex-direction: column; gap: 14px; padding: 0 8px; }
.tickets > :first-child { margin-top: -2px; }
.rail-empty { margin: 14px 4px 0; font-size: 14px; color: var(--hint); }

.ticket {
  --tooth: 7px;
  padding: 12px 14px calc(14px + var(--tooth));
  background: var(--ticket); color: var(--ticket-ink);
  -webkit-mask:
    conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) bottom / calc(2 * var(--tooth)) var(--tooth) repeat-x,
    linear-gradient(#000 0 0) top / 100% calc(100% - var(--tooth)) no-repeat;
  mask:
    conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) bottom / calc(2 * var(--tooth)) var(--tooth) repeat-x,
    linear-gradient(#000 0 0) top / 100% calc(100% - var(--tooth)) no-repeat;
}
.ticket-head { display: flex; justify-content: space-between; gap: 8px; font-weight: 800; font-size: 18px; }
.ticket-time { font-weight: 400; font-size: 14px; color: var(--ticket-hint); }
.ticket-who { margin: 4px 0 0; overflow-wrap: anywhere; }
.ticket-who a { color: inherit; }
.ticket ul { list-style: none; margin: 10px 0 0; padding: 8px 0; border-top: 1.5px dashed #b7c2bd; border-bottom: 1.5px dashed #b7c2bd; }
.ticket li { display: flex; justify-content: space-between; gap: 10px; overflow-wrap: anywhere; }
.ticket-total { display: flex; justify-content: space-between; margin-top: 8px; font-weight: 800; }
.ticket-detail { margin: 8px 0 0; font-size: 14px; color: var(--ticket-hint); overflow-wrap: anywhere; white-space: pre-wrap; }
.ticket-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.ticket .btn { background: #17574a; color: #fff; }
.ticket .btn.quiet { background: #e9eeea; border-color: #b9c5bf; color: var(--ticket-ink); }
.ticket .btn.danger { background: #fbe9e9; border-color: #a82a2a; color: #a82a2a; }
.paid { font-weight: 600; color: #17574a; }
.unpaid { font-weight: 600; color: #a35f00; }

.history { margin-top: 24px; }
.history summary { cursor: pointer; font-weight: 700; padding: 10px 0; min-height: 44px; }
.history-tickets { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-top: 10px; }

/* Menu */
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 16px; }
.items { display: grid; gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: 12px; overflow: hidden; }
.item { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px; background: var(--panel); }
.item img, .item .no-photo { flex: none; width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--counter); }
.item .no-photo { border: 1.5px dashed var(--edge); }
.item-body { flex: 1 1 180px; min-width: 0; overflow-wrap: anywhere; }
.item-top { display: flex; justify-content: space-between; gap: 12px; }
.item-name { font-weight: 700; }
.item-price { flex: none; font-weight: 800; }
.item-desc { font-size: 14px; color: var(--hint); }
.item-off { display: inline-block; margin-top: 4px; padding: 2px 8px; border-radius: 6px; background: var(--danger-tint); font-size: 13px; font-weight: 700; color: var(--danger); }
.item-actions { display: flex; gap: 8px; }

/* Forms */
.form { max-width: 560px; padding: 20px; background: var(--panel); border-radius: 12px; }
.items + .form, .form + .items { margin-top: 16px; }
.field { display: block; margin-top: 14px; }
.field:first-child { margin-top: 0; }
.field > span { display: block; margin-bottom: 4px; font-size: 14px; font-weight: 700; }
.field input:not([type="checkbox"]):not([type="file"]), .field textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; font-size: 16px;
  background: var(--counter); border: 1px solid var(--edge); border-radius: 10px;
}
.field input[type="file"] { width: 100%; padding: 8px 0; font-size: 16px; }
.check { display: flex; align-items: center; gap: 12px; margin-top: 8px; min-height: 44px; }
.check input { accent-color: var(--pine); flex: none; width: 22px; height: 22px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.ok { color: var(--pine); font-weight: 600; margin: 10px 0 0; }

.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 16px; align-items: start; }
.settings .form { max-width: none; }
.settings h2 { margin-bottom: 12px; }
.steps { margin: 14px 0 18px; padding-left: 22px; }
.steps li { margin-top: 6px; }
.steps a { color: var(--pine); font-weight: 700; }
.small { font-size: 14px; margin-bottom: 0; }
.settings > * { min-width: 0; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.share { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.share input { flex: 1 1 180px; min-width: 0; min-height: 48px; padding: 8px 12px; font-size: 16px; background: var(--counter); border: 1px solid var(--edge); border-radius: 10px; }

/* Admin */
.table-wrap { overflow-x: auto; background: var(--panel); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--rule); white-space: nowrap; }
th { font-size: 14px; color: var(--hint); }
tr:last-child td { border-bottom: 0; }
td .btn { min-height: 36px; padding: 0 12px; margin-right: 4px; font-size: 14px; }
.state-active { color: var(--pine); font-weight: 700; }
.state-expired { color: var(--danger); font-weight: 700; }

/* Phone: one column, thumb-height controls, navigation at the bottom. */
@media (max-width: 760px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
  main { padding: 16px; }
  h1 { font-size: 28px; }
  .solo-card { padding: 22px; }

  header.top { flex-wrap: nowrap; gap: 10px; padding: 10px 16px; }
  .brand { flex: 1 1 0; min-width: 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  header.top > .btn { flex: none; min-height: 40px; padding: 0 12px; font-size: 14px; }
  .banner { padding: 10px 16px; font-size: 14px; }

  nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--panel); border-top: 1px solid var(--rule);
  }
  nav button { justify-content: center; min-height: 60px; padding: 0 2px; border-radius: 0; font-size: 14px; }
  nav button[aria-current="page"] { background: none; color: var(--pine); box-shadow: inset 0 3px 0 var(--pine); }

  /* The four stages become one rail of big counts. Tapping a segment shows that stage. */
  .stage-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 16px; }
  .stage-tab {
    position: relative; display: flex; flex-direction: column-reverse; align-items: center; justify-content: flex-end;
    min-height: 68px; padding: 4px 0 14px; color: var(--hint); font-size: 13px; font-weight: 700;
  }
  .stage-tab .count { font-size: 28px; font-weight: 800; line-height: 1.1; color: var(--ink); }
  .stage-tab::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 8px; border-radius: 4px;
    background: var(--steel); opacity: 0.4;
  }
  .stage-tab.new::after { background: var(--marigold); opacity: 0.55; }
  .stage-tab[aria-pressed="true"] { color: var(--ink); }
  .stage-tab[aria-pressed="true"]::after { opacity: 1; }

  .board { display: block; overflow: visible; padding: 0; }
  .board > section:not([data-active="true"]) { display: none; }
  .rail-head, .rail { display: none; }
  .tickets { padding: 0; gap: 16px; }
  .tickets > :first-child { margin-top: 0; }
  .rail-empty { margin: 8px 0 0; font-size: 15px; }
  .ticket-actions > .btn { flex: 1 1 calc(50% - 4px); min-height: 48px; }
  .ticket-actions > .btn:not(.quiet):not(.danger) { flex-basis: 100%; }
  .history-tickets { grid-template-columns: 1fr; }

  .section-head .btn { flex: 1 1 100%; }
  .item { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 4px 14px; align-items: start; padding: 14px; }
  .item img, .item .no-photo { width: 64px; height: 64px; }
  .item-actions { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
  .item-actions .btn { width: 100%; }

  .form { padding: 16px; }
  .form-actions > .btn { flex: 1 1 calc(50% - 4px); }
  .share .btn { flex: 1 1 100%; }

  /* The admin table turns into one card per store. */
  .table-wrap { background: none; overflow: visible; }
  table, tbody, tr, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tr { margin-bottom: 12px; padding: 12px 14px; background: var(--panel); border-radius: 12px; }
  td { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border: 0; text-align: right; white-space: normal; }
  td::before { content: attr(data-label); flex: none; font-size: 14px; font-weight: 400; color: var(--hint); text-align: left; }
  td:first-child { font-size: 18px; font-weight: 800; text-align: left; }
  td:first-child::before { content: none; }
  td[data-label="Mag-extend"] { flex-wrap: wrap; justify-content: flex-start; gap: 8px; padding-top: 10px; }
  td[data-label="Mag-extend"]::before { flex-basis: 100%; }
  td .btn { flex: 1 1 calc(33.333% - 6px); min-height: 44px; margin: 0; padding: 0 6px; }
}
