:root {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #17201d;
  --muted: #5b6a65;
  --border: #d8e0dc;
  --brand: #1d6b57;
  --brand-strong: #145444;
  --brand-soft: #dcefe8;
  --on-brand: #ffffff;
  --danger: #b3261e;
  --danger-soft: #fbe3e1;
  --warn: #8a5a00;
  --warn-soft: #fff1d6;
  --ok: #1b6e3a;
  --ok-soft: #dff3e5;
  --info-soft: #e3ecfb;
  --radius: 14px;
  --tabbar-h: 64px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 2px 8px rgb(0 0 0 / 0.04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101614;
    --surface: #18201d;
    --surface-2: #212b27;
    --text: #e7eeeb;
    --muted: #9aaba5;
    --border: #2e3a35;
    --brand: #4fb594;
    --brand-strong: #6cc9aa;
    --brand-soft: #1d3a31;
    --on-brand: #06231a;
    --danger: #ff8a80;
    --danger-soft: #3d1a17;
    --warn: #ffc65c;
    --warn-soft: #3a2c10;
    --ok: #7dd89a;
    --ok-soft: #173322;
    --info-soft: #1b2638;
    --shadow: none;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

a {
  color: var(--brand);
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 0.5rem;
}

h1 {
  font-size: 1.6rem;
}

h2 {
  font-size: 1.2rem;
}

h3 {
  font-size: 1.02rem;
}

p {
  margin: 0 0 0.75rem;
}

/* ---------- layout ---------- */

.app {
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
}

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.page.wide {
  max-width: 1000px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 16px;
  flex-wrap: wrap;
}

.page-head h1 {
  margin: 0;
}

.back {
  display: inline-block;
  margin-bottom: 8px;
  text-decoration: none;
  font-weight: 500;
}

.center-screen {
  min-height: 80vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

.auth-card .logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  display: block;
  margin: 0 auto 12px;
}

.auth-card h1 {
  text-align: center;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 600px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

/* Two fields side by side even on phones (e.g. a date range). */
.pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.row.end {
  justify-content: flex-end;
}

.row.between {
  justify-content: space-between;
}

.stack > * + * {
  margin-top: 12px;
}

.spacer {
  flex: 1;
}

/* ---------- cards & lists ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  min-width: 0;
}

.card.flush {
  padding: 0;
  overflow: hidden;
}

.card h2:first-child,
.card h3:first-child {
  margin-top: 0;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list > li {
  border-top: 1px solid var(--border);
}

.list > li:first-child {
  border-top: 0;
}

.list-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  color: inherit;
  text-decoration: none;
  width: 100%;
  background: none;
  border: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.list-item:active {
  background: var(--surface-2);
}

.list-item .main {
  flex: 1;
  min-width: 0;
}

.list-item .title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.list-item .sub {
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.list-item .aside {
  text-align: right;
  white-space: nowrap;
}

.date-group {
  margin: 20px 4px 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.notes {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 0.92rem;
  margin-top: 4px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.num {
  font-variant-numeric: tabular-nums;
}

.big-num {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 8px;
}

/* ---------- chips, badges, banners ---------- */

.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.chip.brand {
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.chip.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.chip.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.chip.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.banner {
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 0.95rem;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.banner.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.banner.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.banner.info {
  background: var(--info-soft);
}

.banner.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-wrap: anywhere;
}

.success {
  background: var(--ok-soft);
  color: var(--ok);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px 0;
}

.offline-pill {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: var(--text);
  color: var(--bg);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* ---------- forms ---------- */

label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.field {
  margin-bottom: 14px;
  min-width: 0;
}

.field .hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 4px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="search"],
select,
textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  appearance: none;
  -webkit-appearance: none;
}

input[type="date"],
input[type="datetime-local"] {
  display: block;
  min-width: 0;
}

select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

textarea {
  min-height: 80px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.6;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  min-height: 44px;
  cursor: pointer;
}

.check input {
  width: 22px;
  height: 22px;
  accent-color: var(--brand);
  margin: 0;
}

.segmented {
  display: flex;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
  overflow-x: auto;
  scrollbar-width: none;
  margin-bottom: 16px;
}

.segmented::-webkit-scrollbar {
  display: none;
}

.segmented button {
  flex: 1 0 auto;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 10px;
  border-radius: 9px;
  min-height: 38px;
  cursor: pointer;
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
}

.btn.danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--brand);
}

.btn.small {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 0.9rem;
  border-radius: 10px;
}

.btn.block {
  width: 100%;
}

.timer-button {
  width: 100%;
  min-height: 72px;
  font-size: 1.35rem;
  border-radius: 18px;
}

.timer-button.stop {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* ---------- timer ---------- */

.timer-card {
  text-align: center;
}

.stopwatch {
  font-size: clamp(2.8rem, 14vw, 4.2rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 8px 0 4px;
}

.timer-card .context {
  font-size: 1.05rem;
  font-weight: 600;
}

.timer-card .field {
  text-align: left;
}

/* ---------- balances ---------- */

.meter {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin: 6px 0;
}

.meter > span {
  display: block;
  height: 100%;
  background: var(--brand);
  border-radius: 999px;
}

.meter.low > span {
  background: var(--warn);
}

.meter.over > span {
  background: var(--danger);
}

.pool {
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.pool:first-of-type {
  border-top: 0;
  padding-top: 4px;
}

.kv {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  font-size: 0.93rem;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.kv dd.total {
  border-top: 1px solid var(--border);
  padding-top: 4px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}

.stat {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 12px;
}

.stat .label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.stat .value {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- statement ---------- */

.line {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.line:first-child {
  border-top: 0;
}

.line .head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.line .entries {
  margin: 8px 0 0;
  padding: 0 0 0 12px;
  border-left: 3px solid var(--surface-2);
  list-style: none;
  font-size: 0.9rem;
}

.line .entries li + li {
  margin-top: 6px;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.history {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.93rem;
}

table.history th,
table.history td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.history th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
}

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.tabbar nav {
  display: flex;
  width: 100%;
  max-width: 640px;
}

.tabbar a {
  flex: 1;
  min-height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 600;
  position: relative;
}

.tabbar a .icon {
  width: 24px;
  height: 24px;
}

.tabbar a[aria-current="page"] {
  color: var(--brand);
}

.tabbar .badge {
  position: absolute;
  top: 8px;
  left: calc(50% + 6px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  line-height: 18px;
  text-align: center;
}

/* ---------- misc ---------- */

.lock {
  font-size: 0.85rem;
}

.copy-box {
  display: flex;
  gap: 8px;
}

.copy-box input {
  flex: 1;
  min-width: 0;
}

details.disclosure > summary {
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  display: flex;
  align-items: center;
  list-style: none;
}

details.disclosure > summary::-webkit-details-marker {
  display: none;
}

details.disclosure > summary::before {
  content: "▸";
  margin-right: 8px;
  color: var(--muted);
  transition: transform 0.15s;
}

details.disclosure[open] > summary::before {
  transform: rotate(90deg);
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

@media (min-width: 900px) {
  .page {
    padding-top: 28px;
  }
}

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

.banners {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}

.banners .banner:first-child {
  margin-top: 12px;
}

/* ---------- reports ---------- */

.presets {
  flex-wrap: wrap;
  margin-bottom: 12px;
}

table.report {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.93rem;
}

table.report th,
table.report td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  vertical-align: top;
}

table.report th:first-child,
table.report td:first-child {
  text-align: left;
  white-space: normal;
  min-width: 140px;
}

table.report th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
}

table.report tfoot td {
  font-weight: 700;
  border-bottom: 0;
}

/* ---------- print (and Save as PDF) ---------- */

.print-only {
  display: none;
}

@media print {
  /* Always print light, whatever the screen theme. */
  :root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f2f4f3;
    --text: #000000;
    --muted: #4a5753;
    --border: #cfd8d4;
    --brand: #1d6b57;
    --brand-strong: #145444;
    --brand-soft: #dcefe8;
    --danger: #b3261e;
    --danger-soft: #fbe3e1;
    --warn: #8a5a00;
    --warn-soft: #fff1d6;
    --ok: #1b6e3a;
    --ok-soft: #dff3e5;
    --info-soft: #e3ecfb;
    --shadow: none;
    color-scheme: light;
  }

  body {
    background: #ffffff;
  }

  .app {
    min-height: 0;
    padding-top: 0;
  }

  .tabbar,
  .banners,
  .offline-pill,
  .back,
  .segmented,
  .btn,
  .no-print,
  .staff-name {
    display: none !important;
  }

  .print-only {
    display: block;
  }

  .page,
  .page.wide {
    max-width: none;
    padding: 0;
  }

  .card {
    box-shadow: none;
    border: 1px solid var(--border);
  }

  .line,
  .stat,
  table.report tr {
    break-inside: avoid;
  }

  .table-scroll {
    overflow: visible;
  }

  a {
    color: inherit;
    text-decoration: none;
  }
}
