/* Matches the iPhone app: iOS system colours, amber accent, grouped lists. */
:root {
  --bg: #f2f2f7;                       /* systemGroupedBackground */
  --card: #ffffff;                     /* secondarySystemGroupedBackground */
  --card-2: #f2f2f7;                   /* tertiarySystemGroupedBackground (column header) */
  --text: #000000;
  --muted: #6c6c70;                    /* secondary label */
  --faint: #aeaeb2;                    /* tertiary label */
  --line: #c6c6c8;                     /* separator */
  --fill: rgba(118, 118, 128, 0.12);   /* tertiarySystemFill */
  --accent: #d9780e;                   /* AccentColor (light) */
  --accent-soft: rgba(217, 120, 14, 0.14);
  --accent-ink: #ffffff;
  --danger: #ff3b30;
  --danger-soft: rgba(255, 59, 48, 0.12);
  --ok: #34c759;
  --warn: #ff9500;
  --bar: rgba(249, 249, 249, 0.94);
  --seg-on: #ffffff;                   /* selected segment */
  --radius: 10px;
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --text: #ffffff;
    --muted: #8e8e93;
    --faint: #48484a;
    --line: #38383a;
    --fill: rgba(118, 118, 128, 0.24);
    --accent: #fab02e;
    --accent-soft: rgba(250, 176, 46, 0.16);
    --accent-ink: #000000;
    --danger: #ff453a;
    --danger-soft: rgba(255, 69, 58, 0.16);
    --ok: #30d158;
    --warn: #ff9f0a;
    --bar: rgba(28, 28, 30, 0.94);
    --seg-on: #636366;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #000000;
  --card: #1c1c1e;
  --card-2: #2c2c2e;
  --text: #ffffff;
  --muted: #8e8e93;
  --faint: #48484a;
  --line: #38383a;
  --fill: rgba(118, 118, 128, 0.24);
  --accent: #fab02e;
  --accent-soft: rgba(250, 176, 46, 0.16);
  --accent-ink: #000000;
  --danger: #ff453a;
  --danger-soft: rgba(255, 69, 58, 0.16);
  --ok: #30d158;
  --warn: #ff9f0a;
  --bar: rgba(28, 28, 30, 0.94);
  --seg-on: #636366;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  /* Stops the double-tap-to-zoom delay and zoom on quick repeat taps. Pinch-zoom still works. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
body { min-height: 100vh; min-height: 100dvh; }

h1, h2, h3, p { margin: 0; }
h2 { font-size: 17px; font-weight: 600; }
ol, ul { margin: 0; padding-left: 1.3em; }
.app { min-height: 100vh; min-height: 100dvh; }

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 0 calc(env(safe-area-inset-bottom) + 32px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.screen > * { margin-left: 16px; margin-right: 16px; }
.screen > .card, .screen > .count-card, .screen > .list-card { margin-left: 16px; margin-right: 16px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 14px; }
.mono { font-variant-numeric: tabular-nums; }
.big-title { font-size: 22px; font-weight: 700; }
.error { color: var(--danger); font-size: 15px; }
.warning { color: var(--warn); background: var(--card); padding: 12px 14px; border-radius: var(--radius); font-size: 15px; }
.hint { color: var(--muted); font-size: 13px; margin: -6px 16px 0; }

/* MARK: Buttons and links (iOS prominent / bordered / plain) */

.btn {
  appearance: none;
  border: 0;
  background: var(--card);
  color: var(--accent);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  min-height: 50px;
  padding: 0 16px;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.big { width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.danger-fill { background: var(--danger); color: #fff; }

.linkish {
  appearance: none;
  background: none;
  border: 0;
  padding: 6px 2px;
  font: inherit;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.linkish.danger { color: var(--danger); }
.linkish.beer-name { color: var(--text); font-weight: 500; text-align: left; }
.nav-back { font-weight: 400; }

.icon-btn {
  appearance: none;
  background: none;
  border: 0;
  color: var(--accent);
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:disabled { opacity: 0.3; }

.chip {
  appearance: none;
  border: 0;
  background: var(--fill);
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  padding: 0 10px;
  height: 32px;
  cursor: pointer;
}

.icon { flex: none; vertical-align: -3px; }

/* MARK: Navigation and top bar (iOS nav bar with translucent material) */

.navbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 44px;
  margin: 0 !important;
  padding: 0 16px;
}
.nav-title { font-size: 17px; font-weight: 600; text-align: center; grid-column: 2; }
.nav-side { display: flex; }
.nav-side.end { justify-content: flex-end; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  margin: 0 !important;
  padding: calc(env(safe-area-inset-top) + 4px) 12px 4px;
  background: var(--bar);
  backdrop-filter: blur(20px) saturate(1.6);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  border-bottom: 0.5px solid var(--line);
}
.title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 4px;
  white-space: nowrap;
  cursor: pointer;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill.synced { color: var(--ok); }
.pill.syncing { color: var(--accent); }
.pill.offline { color: var(--warn); }
.pill.invalidCode, .pill.error { color: var(--danger); }

.banner {
  display: block;
  margin: 10px 16px 0 !important;
  width: calc(100% - 32px);
  text-align: center;
  padding: 11px 12px;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  border: 0;
  background: var(--card);
  color: var(--warn);
}
.banner.danger { color: var(--danger); cursor: pointer; }

/* MARK: Day and session pickers */

.daybar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  margin-top: 0 !important;
}
.datepick {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 132px;
  height: 36px;
  padding: 0 10px;
  font-size: 17px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
}
.datepick input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 16px;
}

/* iOS segmented control */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--fill);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  min-height: 30px;
  border-radius: 7px;
  padding: 0 6px;
  cursor: pointer;
}
.segmented button.on {
  background: var(--seg-on);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
}
.segmented-wrap { margin-top: 8px; }
.screen > .segmented { margin-left: 16px; margin-right: 16px; }

/* MARK: Cards and the count list (iOS insetGrouped) */

.card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
}
.form-card { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.form-card h2 { font-size: 13px; font-weight: 400; text-transform: uppercase; color: var(--muted); letter-spacing: 0.01em; }
.form-card .small { font-size: 13px; }

.col-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--card-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  border-bottom: 0.5px solid var(--line);
}
.col-head .col-beer { flex: 1; }
.col-head .col-unit, .col-head .col-total { width: 46px; text-align: center; }
.col-head .col-total { text-align: right; width: 46px; }

/* One line per beer: name, three counters, total. */
.row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-top: 0.5px solid var(--line);
}
.col-head + .row { border-top: 0; }
.beer { flex: 1; font-size: 16px; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.tot { width: 46px; text-align: right; font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.row .tot.zero { color: var(--faint); }

.counter {
  width: 46px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
}
.counter .plus, .counter .minus {
  appearance: none;
  border: 0;
  min-height: 26px;
  border-radius: 7px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.counter .plus { background: var(--accent-soft); color: var(--accent); }
.counter .minus { background: var(--fill); color: var(--text); }
.counter .minus:disabled { color: var(--faint); cursor: default; }
.counter input {
  appearance: textfield;
  -moz-appearance: textfield;
  width: 100%;
  height: 18px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  padding: 0;
  font-variant-numeric: tabular-nums;
  border-radius: 4px;
}
.counter input.zero { color: var(--faint); }
.counter input::-webkit-outer-spin-button,
.counter input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.counter input:focus { outline: none; background: var(--fill); }

.count-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  padding: 0 16px;
}
.count-footer .spacer { flex: 1; }

.empty-card { padding: 20px 16px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.empty-card h2 { font-size: 17px; }

/* MARK: Forms and inputs */

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); text-transform: uppercase; }
.row-inline { display: flex; gap: 8px; align-items: stretch; }
.row-inline > input { flex: 1; min-width: 0; }

input[type="text"], input[type="number"], input[type="date"] {
  appearance: none;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 17px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.inline { min-height: 34px !important; }
.form-card input[type="text"] { background: var(--bg); }

.home {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 24px 16px 4px;
  text-align: center;
}
.logo {
  width: 120px;
  height: 120px;
  border-radius: 27px;
  box-shadow: 0 12px 28px rgba(217, 120, 14, 0.30), 0 1px 3px rgba(0, 0, 0, 0.15);
  animation: logo-in 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) both, logo-float 6s ease-in-out 1s infinite;
}
.brand { margin-top: 14px; font-size: 30px; font-weight: 700; letter-spacing: -0.01em; animation: fade-up 0.8s 0.15s both; }
.tagline { color: var(--muted); font-size: 16px; animation: fade-up 0.8s 0.3s both; }
.home-actions { margin-top: 10px; }
.how { padding: 14px 16px 16px; margin-top: 6px; }
.how h2 { font-size: 13px; font-weight: 400; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.how .steps-list { font-size: 16px; }

@keyframes logo-in {
  from { opacity: 0; transform: translateY(18px) scale(0.9); }
  to { opacity: 1; transform: none; }
}
@keyframes logo-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.steps-list { display: flex; flex-direction: column; gap: 14px; padding-left: 1.4em; font-size: 17px; }
.steps-list li { padding-left: 4px; }
.steps-list .icon { color: var(--accent); }
.stack { display: flex; flex-direction: column; gap: 10px; }

.code-big {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-align: center;
  padding: 14px 12px;
  background: var(--card-2);
  border-radius: var(--radius);
  word-break: break-all;
  user-select: all;
}
.code-big.small { font-size: 15px; letter-spacing: 0.02em; padding: 12px 8px; }

/* MARK: Edit beers */

.list-card { display: flex; flex-direction: column; }
.edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 16px;
  border-top: 0.5px solid var(--line);
}
.edit-row:first-child { border-top: 0; }
.edit-row > .linkish, .edit-row > input { flex: 1; min-width: 0; }
.edit-tools { display: flex; gap: 2px; }
.addrow { display: flex; flex-direction: column; gap: 8px; }
.sq {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--accent);
  width: 34px;
  height: 34px;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}
.sq:disabled { opacity: 0.3; }
.sq.danger { color: var(--danger); }

/* MARK: Sheets (iOS action sheets and sheets) */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 8px;
}
.sheet[hidden] { display: none; }
.sheet-card {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 14px;
  padding: 20px 16px calc(env(safe-area-inset-bottom) + 12px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.menu { display: flex; flex-direction: column; gap: 10px; }
.menu h2 { text-align: center; font-size: 17px; }
.menu > p { font-size: 15px; text-align: center; }
.menu-item {
  appearance: none;
  border: 0;
  background: var(--card-2);
  color: var(--accent);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  min-height: 50px;
  border-radius: var(--radius);
  padding: 0 14px;
  text-align: center;
  cursor: pointer;
}
.menu-item.danger { color: var(--danger); }
.import-list h3 { font-size: 13px; font-weight: 400; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.import-list ol, .import-list ul { max-height: 30vh; overflow-y: auto; font-size: 15px; }

@media (max-width: 360px) {
  .counter, .tot, .col-head .col-unit, .col-head .col-total { width: 42px; }
  .counter input { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* MARK: Reports */

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 16px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 12px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.tile-value { font-size: 22px; font-weight: 700; }
.tile-label { font-size: 12px; color: var(--muted); }
.tile.over .tile-value { color: var(--danger); }
.tile.under .tile-value { color: var(--ok); }

.report-card { margin: 0 16px; padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.report-card h2 { font-size: 13px; font-weight: 400; text-transform: uppercase; color: var(--muted); }
.warn-card { border-left: 3px solid var(--warn); }
.missing { margin: 0; padding-left: 1.2em; font-size: 15px; }

.chart { width: 100%; height: auto; display: block; }
.chart-big { font-size: 26px; font-weight: 700; fill: var(--text); }
.chart-small { font-size: 11px; fill: var(--muted); }
.pie-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.pie { max-width: 220px; }
.legend { list-style: none; padding: 0; margin: 0; width: 100%; display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend-name { flex: 1; }
.chip { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }

.var-chart { display: flex; flex-direction: column; gap: 10px; }
.var-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; gap: 8px; }
.var-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.var-value { font-weight: 600; }
.var-value.over { color: var(--danger); }
.var-value.under { color: var(--ok); }
.var-track { position: relative; height: 10px; background: var(--fill); border-radius: 5px; }
.var-center { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--muted); }
.var-bar { position: absolute; top: 0; bottom: 0; border-radius: 5px; }
.var-bar.over { background: var(--danger); }
.var-bar.under { background: var(--ok); }

/* MARK: Sections (beer, wine, liquor) */

.sections { display: flex; flex-direction: column; gap: 12px; }
.section-head {
  appearance: none;
  width: 100%;
  border: 0;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
}
.section-head .chev { color: var(--accent); width: 14px; }
.section-head .section-title { flex: 1; }
.count-card { overflow: hidden; }
.list-head { font-size: 13px; text-transform: uppercase; color: var(--muted); padding: 12px 16px 6px; }

.copy-row { display: block; text-align: center; margin-top: -4px; }
.copy-row .chip { display: inline-block; width: auto; max-width: 100%; height: auto; min-height: 34px; padding: 8px 14px; font-size: 14px; line-height: 1.2; white-space: normal; text-align: center; }
.copy-row .chip:disabled { opacity: 0.4; }

/* MARK: Areas and the sidebar */

.topbar > :first-child { justify-self: start; }
.topbar > :last-child { justify-self: end; min-width: 0; }
.count-screen { gap: 8px; }
.area-title { font-size: 22px; font-weight: 700; text-align: center; margin: 0; }
.scrim { position: fixed !important; inset: 0; margin: 0 !important; background: rgba(0, 0, 0, 0.35); z-index: 40; display: flex; }
.drawer {
  width: 290px;
  max-width: 84%;
  height: 100%;
  background: var(--card);
  overflow-y: auto;
  padding: calc(env(safe-area-inset-top) + 16px) 12px calc(env(safe-area-inset-bottom) + 24px);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.drawer h3 { font-size: 12px; font-weight: 400; text-transform: uppercase; color: var(--muted); margin: 16px 10px 6px; }
.side-item {
  appearance: none;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  padding: 0 12px;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
}
.side-item small { font-size: 12px; font-weight: 500; color: var(--muted); }
.side-item.on { background: var(--accent-soft); color: var(--accent); }
.side-add, .side-link {
  appearance: none;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 16px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
}
.side-link { color: var(--text); }
