:root {
  --color-bg: #f4f1e8;
  --color-paper: #fffdf7;
  --color-ink: #1c1a15;
  --color-muted: #6b6558;
  --color-line: #d8d2c0;
  --color-line-strong: #1c1a15;

  --color-primary: #16513a;
  --color-primary-dark: #0e3a29;
  --color-amber: #9c6b12;
  --color-rose: #8f2f27;
  --color-teal: #0f5c56;

  --radius: 10px;
  --radius-sm: 6px;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Courier New", monospace;

  --bs-primary: var(--color-primary);
  --bs-primary-rgb: 22, 81, 58;
  --bs-link-color: var(--color-primary);
  --bs-link-hover-color: var(--color-primary-dark);
  --bs-border-radius: var(--radius);
  --bs-border-radius-lg: var(--radius);
  --bs-body-font-family: 'Tajawal', sans-serif;
}

body {
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: 'Tajawal', sans-serif;
  min-height: 100vh;
  padding-bottom: 5.5rem;
  display: flex;
  flex-direction: column;
  /* Removes the default grey/blue tap-flash on iOS/Android so our own
     :active states (transform, background swap) show cleanly instead. */
  -webkit-tap-highlight-color: transparent;
}

.amount, .mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  border-radius: var(--radius-sm);
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
  background: var(--color-primary-dark) !important;
  border-color: var(--color-primary-dark) !important;
}
/* Bootstrap's own .btn-primary:disabled has higher specificity than our
   plain .btn-primary rule above (a pseudo-class adds to specificity), so
   without this it silently reverts to Bootstrap's default blue whenever
   the button is disabled - which is exactly the "disabled" state our
   own "disable until form valid" JS relies on the most. */
.btn-primary:disabled, .btn-primary.disabled {
  background: var(--color-primary) !important;
  border-color: var(--color-primary) !important;
  opacity: 0.55;
}
.btn-outline-primary {
  color: var(--color-primary);
  border-color: var(--color-primary);
  border-radius: var(--radius-sm);
}
.btn-outline-primary:hover { background: var(--color-primary); border-color: var(--color-primary); }
.btn-outline-secondary { border-radius: var(--radius-sm); }

/* App bar */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 1020;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--color-paper);
  border-bottom: 2px solid var(--color-line-strong);
}
.app-bar .back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 1.5px solid var(--color-line-strong);
  border-radius: var(--radius-sm);
  color: var(--color-ink);
  -webkit-touch-callout: none;
  user-select: none;
}
.app-bar .back-btn:hover { background: var(--color-ink); color: var(--color-paper); }
/* Without an explicit size, an SVG sized only via viewBox can render at
   0x0 in Safari/iOS inside a flex container (Chrome/Android is lenient
   about this, Safari isn't) - this is why the back arrow was invisible
   on iOS while showing fine on Android. */
.app-bar .back-btn svg { width: 20px; height: 20px; }
.app-bar h1 {
  font-size: 1.05rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: 0.01em;
}

.page-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.85rem 1rem 1rem;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  inset-inline: 0;
  z-index: 1030;
  display: flex;
  background: var(--color-paper);
  border-top: 2px solid var(--color-line-strong);
  padding: 0.4rem 0.5rem calc(0.4rem + env(safe-area-inset-bottom));
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.35rem 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  -webkit-touch-callout: none;
  user-select: none;
}
.bottom-nav a.active { color: var(--color-primary); }
.bottom-nav svg { width: 22px; height: 22px; }

/* ---- Kiosk tiles (entry points) ---- */
.kiosk-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.kiosk-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.9rem 0.5rem;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--color-paper);
  background: var(--color-primary);
  border: 2px solid var(--color-line-strong);
  box-shadow: 3px 3px 0 var(--color-line-strong);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.kiosk-tile:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--color-line-strong);
  color: var(--color-paper);
}
.kiosk-tile svg { width: 22px; height: 22px; }
.kiosk-tile { -webkit-touch-callout: none; user-select: none; }
.kiosk-tile.k-amber { background: var(--color-amber); }
.kiosk-tile.k-rose { background: var(--color-rose); }
.kiosk-tile.k-teal { background: var(--color-teal); }

/* ---- Worker chip picker ---- */
.chip-row {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.2rem 0.1rem 0.6rem;
  -webkit-overflow-scrolling: touch;
}
.chip-row input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.chip {
  flex: 0 0 auto;
  padding: 0.7rem 1.1rem;
  border: 2px solid var(--color-line-strong);
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--color-ink);
  background: var(--color-paper);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  -webkit-touch-callout: none;
}
.chip-row input[type="radio"]:checked + .chip {
  background: var(--color-ink);
  color: var(--color-paper);
  border-color: var(--color-ink);
}
.chip-row input[type="radio"]:focus-visible + .chip {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ---- On-screen keypad ---- */
.amount-display {
  width: 100%;
  border: 2px solid var(--color-line-strong);
  border-radius: var(--radius);
  background: var(--color-paper);
  padding: 0.55rem 1rem;
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.6rem;
}
.amount-display:focus { outline: none; border-color: var(--color-primary); }

/* ---- Date: today by default, collapsed picker ---- */
.date-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  border: 2px dashed var(--color-line);
  border-radius: var(--radius-sm);
  margin-bottom: 0.75rem;
  font-weight: 600;
  color: var(--color-muted);
  background: transparent;
  width: 100%;
}
.dmy-date {
  display: flex;
  gap: 0.5rem;
}
.dmy-date select {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-weight: 600;
}
.dmy-date[hidden] { display: none; }

/* ---- Ledger rows (history/records) ---- */
.ledger-header {
  text-align: center;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  margin: 0.5rem 0 1rem;
}
.ledger-header::before, .ledger-header::after { content: "\2500\2500\2500 "; }
.ledger-header::after { content: " \2500\2500\2500"; }

.activity-details {
  margin-top: 2rem;
}
.activity-details summary.ledger-header {
  cursor: pointer;
  display: block;
}
.activity-details summary.ledger-header::-webkit-details-marker { display: none; }
.activity-details .chevron {
  display: inline-block;
  transition: transform 0.15s ease;
}
.activity-details[open] .chevron { transform: rotate(180deg); }
.scroll-ledger {
  /* ~4 rows of single-line activity items before scrolling kicks in */
  max-height: 200px;
  overflow-y: auto;
}

.ledger {
  background: var(--color-paper);
  border: 2px solid var(--color-line-strong);
  border-radius: var(--radius);
  padding: 0.25rem 1rem;
}
.ledger-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.55rem 0;
  border-bottom: 1px dashed var(--color-line);
  text-decoration: none;
  color: inherit;
}
.ledger-row:last-child { border-bottom: none; }
.ledger-row .label {
  font-weight: 700;
  white-space: nowrap;
}
.ledger-row .leader {
  flex: 1;
  border-bottom: 1px dotted var(--color-muted);
  height: 0;
  margin-bottom: 0.3em;
}
.ledger-row .amount { font-size: 1rem; font-weight: 700; white-space: nowrap; }
.ledger-row .meta { display: block; font-size: 0.78rem; color: var(--color-muted); font-weight: 400; margin-top: 0.15rem; }
.ledger-row.negative .amount { color: var(--color-rose); }
.ledger-row.ended {
  border-top: 2px solid var(--color-rose);
  padding-top: 0.7rem;
  margin-top: 0.1rem;
}

.stamp {
  display: inline-block;
  border: 2px solid currentColor;
  border-radius: var(--radius-sm);
  padding: 0.1rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  transform: rotate(-2deg);
}
.stamp.s-rose { color: var(--color-rose); }
.stamp.s-primary { color: var(--color-primary); }

.balance-slab {
  background: var(--color-ink);
  color: var(--color-paper);
  border-radius: var(--radius);
  padding: 0.8rem;
  text-align: center;
  margin-bottom: 0.75rem;
  text-decoration: none;
  display: block;
}
.balance-slab .value {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 800;
}
.balance-slab.negative .value { color: #e08a83; }
.balance-slab .label { font-size: 0.78rem; opacity: 0.75; margin-top: 0.2rem; }

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0.9rem 0 0.5rem;
}
.section-heading h2 { font-size: 0.95rem; font-weight: 800; margin: 0; }

/* Forms */
.form-shell {
  background: var(--color-paper);
  border: 2px solid var(--color-line-strong);
  border-radius: var(--radius);
  padding: 1rem;
}
.form-control, .form-select {
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--color-line);
  padding: 0.65rem 0.9rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 0.2rem rgba(22, 81, 58, 0.15);
}

/* Login */
.login-shell {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-paper);
  border: 2px solid var(--color-line-strong);
  border-radius: var(--radius);
  box-shadow: 4px 4px 0 var(--color-line-strong);
  padding: 2rem 1.5rem;
}
.login-card .brand {
  text-align: center;
  margin-bottom: 1.5rem;
}
.login-card .brand .icon {
  width: 84px;
  height: 84px;
  object-fit: contain;
  margin: 0 auto 0.75rem;
}

.app-footer {
  text-align: center;
  color: var(--color-muted);
  font-size: 0.65rem;
  /* Pins to the bottom of the viewport when content is short (e.g. the
     activity section collapsed) instead of trailing right behind
     whatever content happens to be above it - .page-content is a flex
     column filling the viewport height, so this auto margin consumes
     all leftover space. When content is tall enough to scroll, this
     just becomes 0 and the footer sits after the content as normal. */
  margin-top: auto;
  padding-top: 1.5rem;
}
