/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Theme ─────────────────────────────────────────────────── */
/* HTL scheme (data/HIF.Farbschema.pdf): school red #e30613 as the brand
   (primary buttons, active tabs, header accent line), the grey-blues for
   headings, backgrounds and anything money-positive. The brand color is
   kept separate from the semantic positive/negative colors, so a top-up
   never looks like an error. */
:root {
  color-scheme: light dark;

  --brand: #e30613;
  --brand-hover: #b8050f;
  --brand-contrast: #fff;

  --smoky-blue: #496A81;
  --grey-blue: #738C9B;
  --grey-blue-light: #C9D4DB;

  --header-bg: #fff;
  --header-fg: var(--smoky-blue);
  --header-btn-bg: var(--page-bg);
  --header-btn-fg: var(--smoky-blue);

  --page-bg: #eef2f5;
  --surface: #fff;
  --text: #222;
  --muted: #666;
  --faint: #888;
  --heading: var(--smoky-blue);
  --balance-amount: var(--smoky-blue);

  --border: #ddd;
  --divider: #e0e0e0;
  --row-border: #f0f0f0;
  --accent-border: var(--grey-blue-light);
  --track: #e5e5e5;
  --subtle-bg: #f5f5f5;
  --subtle-fg: #444;
  --row-hover: #fafafa;

  --positive: var(--smoky-blue);
  --positive-bg: #e6edf2;
  --negative: #c0392b;
  --negative-bg: #fdecea;
  --negative-hover-bg: #f9d6d2;
  --negative-border: #f3c6c1;
  --warning: #b9651a;
  --warning-bg: #fff4e5;

  --qr-bar: var(--grey-blue);

  /* Hover/focus are always calm grey-blue, never red: red is reserved for
     primary actions and errors, and a red ring on an input reads as an
     error. An explicit ring also replaces the browser default, which
     follows the OS accent color (e.g. orange on Windows). */
  --hover-bg: #e6edf2;
  --hover-fg: var(--smoky-blue);
  --focus: var(--smoky-blue);
  --focus-ring: 0 0 0 3px rgba(73,106,129,.25);
  accent-color: var(--focus);
}

/* Dark mode follows the device setting. The same roles in a dark
   grey-blue: the school red stays, the smoky blue gets lighter so it
   still reads on the dark surfaces. QR codes are not themed: they
   always stay black on white (see QrCodeSvg). */
@media (prefers-color-scheme: dark) {
  :root {
    --header-bg: #1c242b;
    --header-fg: #a9c1d3;
    --header-btn-fg: #a9c1d3;

    --page-bg: #12181d;
    --surface: #1c242b;
    --text: #e4e9ed;
    --muted: #a3afb8;
    --faint: #85929c;
    --heading: #a9c1d3;
    --balance-amount: #a9c1d3;

    --border: #3a4650;
    --divider: #303b44;
    --row-border: #29333b;
    --accent-border: #3d4f5c;
    --track: #303b44;
    --subtle-bg: #26313a;
    --subtle-fg: #d0d8de;
    --row-hover: #222c34;

    --positive: #a9c1d3;
    --positive-bg: #22333f;
    --negative: #ff8a7d;
    --negative-bg: #3b2123;
    --negative-hover-bg: #4a2629;
    --negative-border: #6b3236;
    --warning: #f0b26b;
    --warning-bg: #3a2c1a;

    --hover-bg: #26323b;
    --hover-fg: #c4d6e3;
    --focus: #8fb0c7;
    --focus-ring: 0 0 0 3px rgba(143,176,199,.35);
  }
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: var(--focus-ring);
}

/* ── Base ──────────────────────────────────────────────────── */
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--page-bg);
  color: var(--text);
}

/* ── Header ────────────────────────────────────────────────── */
header {
  background: var(--header-bg);
  color: var(--header-fg);
  padding: .6rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1rem;
  border-bottom: 4px solid var(--brand);
  box-shadow: 0 1px 4px rgba(73,106,129,.15);
}
/* The logo has a white background, so it sits in a white header bar. */
.header-logo { height: 40px; display: block; }
header h1 {
  font-size: 1rem;
  font-weight: 600;
  padding-left: .75rem;
  border-left: 1px solid var(--accent-border);
}
/* With flex-wrap the buttons drop below the title on narrow phones instead
   of running off-screen; margin-left:auto keeps them right-aligned either
   way. Pages with several buttons wrap them in .header-actions so they
   move as one group. */
header > button,
.header-actions { margin-left: auto; }
.header-actions { display: flex; gap: .5rem; }
@media (max-width: 480px) {
  header { padding: .6rem 1rem; }
  /* The logo identifies the app; the page title would push the buttons
     onto a second row. */
  header h1 { display: none; }
  .header-logo { height: 34px; }
}
header button {
  flex-shrink: 0;
  white-space: nowrap;
  background: var(--header-btn-bg);
  color: var(--header-btn-fg);
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  padding: .4rem .8rem;
  cursor: pointer;
  font-size: .85rem;
}

/* ── Layout ────────────────────────────────────────────────── */
main {
  margin: 0 auto;
  padding: 1.5rem 1rem;
}
.main-wide    { max-width: 900px; }
.main-narrow  { max-width: 480px; }
.main-balance { max-width: 480px; margin-top: 2rem; }

/* ── Card ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  margin-bottom: 1.25rem;
}
.card h2 { font-size: 1rem; margin-bottom: 1rem; color: var(--heading); }

/* ── Forms ─────────────────────────────────────────────────── */
label {
  display: block;
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: .25rem;
  margin-top: .75rem;
}
label:first-of-type { margin-top: 0; }
input, select {
  width: 100%;
  padding: .6rem .8rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  font-size: .95rem;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: block;
  margin-top: 1rem;
  width: 100%;
  padding: .7rem;
  border: none;
  border-radius: 6px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btn:active { opacity: .8; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary   { background: var(--brand); color: var(--brand-contrast); }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-secondary { background: var(--subtle-bg); color: var(--subtle-fg); border: 1px solid var(--border); margin-top: .5rem; }
.btn-secondary:hover:not(:disabled) { background: var(--hover-bg); color: var(--hover-fg); }
header button:hover { background: var(--hover-bg); }
.refresh-btn:hover { background: var(--hover-bg); }

.refresh-btn {
  float: right;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .2rem .5rem;
  cursor: pointer;
  font-size: .8rem;
  font-weight: normal;
}

/* ── Messages ──────────────────────────────────────────────── */
.msg {
  margin-top: .75rem;
  padding: .6rem .8rem;
  border-radius: 6px;
  font-size: .85rem;
}
.msg-ok  { background: var(--positive-bg); color: var(--positive); }
.msg-err { background: var(--negative-bg); color: var(--negative); }

/* ── Login overlay (admin + cashier) ───────────────────────── */
#setup {
  position: fixed;
  inset: 0;
  background: var(--page-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99;
}
#setup .inner {
  background: var(--surface);
  border-radius: 12px;
  padding: 2rem;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 4px 20px rgba(0,0,0,.1);
}
#setup h2   { margin-bottom: 1rem; }
#setup input { margin-bottom: .75rem; }

/* ── Tables ────────────────────────────────────────────────── */
.table-wrap { margin-top: .75rem; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th {
  text-align: left;
  padding: .5rem .75rem;
  background: var(--subtle-bg);
  color: var(--muted);
  font-weight: 600;
}
td { padding: .5rem .75rem; border-bottom: 1px solid var(--row-border); white-space: nowrap; }
tr:hover td { background: var(--row-hover); }
.btn-remove {
  background: var(--negative-bg);
  color: var(--negative);
  border: 1px solid var(--negative-border);
  border-radius: 6px;
  padding: .3rem .6rem;
  font-size: .85rem;
  cursor: pointer;
}
.btn-remove:hover { background: var(--negative-hover-bg); }

/* ── Settings: time-dependent rates ───────────────────────── */
.rate-hint { font-size: .85rem; color: var(--muted); }
.rate-add-row { display: flex; gap: .5rem; align-items: flex-end; margin-top: .75rem; }
.rate-add-row > div { flex: 1; min-width: 0; }
.rate-add-row label { margin-top: 0; }
.rate-add-row .btn-small { padding: .6rem 1rem; font-size: 1rem; }
.rate-current { color: var(--positive); font-weight: 600; }

/* ── Dialog (confirm popup) ────────────────────────────────── */
dialog {
  margin: auto;
  border: none;
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog p { margin-bottom: 1rem; }

/* ── Color helpers ─────────────────────────────────────────── */
.balance-ok  { color: var(--positive); font-weight: 600; }
.balance-low { color: var(--negative); font-weight: 600; }
.topup-type  { color: var(--positive); }
.charge-type { color: var(--negative); }
.status-open { color: var(--negative); font-weight: 600; }
.status-paid { color: var(--positive); font-weight: 600; }
.link-small  { font-size: .75rem; color: var(--faint); word-break: break-all; }
.tx-code     { font-family: monospace; font-size: .75rem; color: var(--faint); }
.text-muted    { color: var(--muted); }
.text-faint    { color: var(--faint); }
.text-negative { color: var(--negative); }
.empty-hint    { color: var(--faint); font-size: .9rem; }

/* ── Admin: tabs ───────────────────────────────────────────── */
/* On narrow screens the tab bar scrolls sideways on its own instead of
   widening the whole page. */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 2px solid var(--divider);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0;
  white-space: nowrap;
  padding: .75rem 1.5rem;
  cursor: pointer;
  font-size: .95rem;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}
.tab:hover { background: var(--hover-bg); color: var(--hover-fg); }
.tab.active { border-bottom-color: var(--brand); color: var(--brand); font-weight: 600; }
.tab.active:hover { color: var(--brand); }
.label-short { display: none; }
@media (max-width: 480px) {
  .tab { padding: .75rem .9rem; }
  .label-long { display: none; }
  .label-short { display: inline; }
}

/* ── Admin: panels + grid ──────────────────────────────────── */
.panel { display: none; }
.panel.active { display: block; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.25rem; }
@media (max-width: 600px) { .grid { grid-template-columns: 1fr; } }

/* ── Cashier: scanner ──────────────────────────────────────── */
#scanner-wrap {
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 1;
  margin-bottom: .75rem;
  position: relative;
}
#video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.scan-frame {
  width: 55%;
  aspect-ratio: 1;
  border: 3px solid var(--brand);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.45);
}
.scan-hint { text-align: center; color: var(--faint); font-size: .85rem; margin-bottom: .25rem; }

.divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  color: var(--faint);
  font-size: .85rem;
  margin: 1rem 0;
}
.divider::before,
.divider::after { content: ''; flex: 1; height: 1px; background: var(--divider); }

/* ── Cashier: confirm panel ────────────────────────────────── */
.student-name { font-size: 1.4rem; font-weight: 700; margin-bottom: .25rem; }
.charge-amount-label { font-size: .85rem; color: var(--muted); }
.charge-amount { font-size: 1.6rem; font-weight: 700; margin-bottom: .5rem; }
.btn-row { display: flex; gap: .75rem; margin-top: 1rem; }
.btn-row .btn { margin-top: 0; flex: 1; }

/* ── Confirm modal ─────────────────────────────────────────── */
#confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.confirm-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 340px;
  width: 90%;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
}
.confirm-card p { font-size: .95rem; color: var(--text); }

/* ── Bills: rows + expandable detail ──────────────────────── */
.btn-small {
  display: inline-block;
  width: auto;
  margin-top: 0;
  padding: .35rem .7rem;
  font-size: .8rem;
}
/* As small as the .tx-code text it sits next to. */
.btn-tiny {
  display: inline-block;
  width: auto;
  margin-top: 0;
  padding: 0 .4rem;
  border-radius: 4px;
  font-size: .75rem;
}
.btn-danger { background: var(--negative-bg); color: var(--negative); border: 1px solid var(--negative-border); }
.btn-danger:hover:not(:disabled) { background: var(--negative-hover-bg); }
.bill-row { border-bottom: 1px solid var(--row-border); padding: .6rem 0; }
.bill-row:last-child { border-bottom: none; }
.bill-row-line1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .95rem;
  gap: .5rem;
}
.tx-code-group { display: flex; align-items: center; gap: .5rem; }
.bill-row-line2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  margin-top: .4rem;
  font-size: .8rem;
  color: var(--faint);
}
.bill-details {
  max-height: 0;
  overflow: hidden;
  transition: max-height .25s ease;
}
.bill-details.expanded {
  max-height: 260px;
  overflow-y: auto;
  margin-top: .6rem;
}

/* ── Accountant: autocomplete ──────────────────────────────── */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  display: none;
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  max-height: 240px;
  overflow-y: auto;
  z-index: 10;
}
.autocomplete-item {
  padding: .5rem .8rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: .1rem;
}
.autocomplete-item:hover,
.autocomplete-item-active { background: var(--hover-bg); }
.autocomplete-item + .autocomplete-item { border-top: 1px solid var(--row-border); }
.autocomplete-name { font-size: .9rem; font-weight: 600; color: var(--text); }
.autocomplete-email { font-size: .8rem; color: var(--faint); }
.autocomplete-empty { padding: .5rem .8rem; font-size: .85rem; color: var(--faint); }

/* ── Parents page ──────────────────────────────────────────── */
/* Used on phones: the status sits under the address, which takes the
   remaining width and wraps, so the remove button stays on screen instead
   of the table scrolling sideways. */
.parents-table td:first-child { width: 100%; white-space: normal; overflow-wrap: anywhere; }
.parent-status { font-size: .8rem; color: var(--muted); }

/* ── Balance page ──────────────────────────────────────────── */
.balance-amount {
  font-size: 3rem;
  font-weight: 700;
  color: var(--balance-amount);
  text-align: center;
  margin: .5rem 0;
}
.balance-label  { text-align: center; color: var(--muted); font-size: .9rem; }
.balance-name   { text-align: center; font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; }
.low-balance .balance-amount { color: var(--negative); }
.balance-hint { text-align: center; color: var(--negative); font-size: .85rem; margin-top: .5rem; }

/* Student's and parents' "Aufladen" tab: bank details for a top-up transfer. */
.topup-details dt { margin-top: .75rem; color: var(--muted); font-size: .85rem; }
.topup-details dd { font-weight: 600; overflow-wrap: anywhere; }
.topup-note { margin-top: 1rem; }
.topup-qr-hint { text-align: center; color: var(--muted); font-size: .85rem; }

.qr-wrap { text-align: center; padding: 1rem 0; }
.qr-wrap img, .qr-wrap svg { width: 200px; height: 200px; }

/* Only shown when the QR can't be used: replaces the QR entirely. */
.qr-notice {
  max-width: 260px;
  margin: 1rem auto;
  padding: 1rem;
  border-radius: 8px;
  background: var(--negative-bg);
  color: var(--negative);
  font-weight: 600;
  line-height: 1.4;
}
/* Shown above a still-usable QR (low balance, offline). */
.qr-warning {
  max-width: 260px;
  margin: 0 auto .5rem;
  padding: .4rem .6rem;
  border-radius: 6px;
  background: var(--warning-bg);
  color: var(--warning);
  font-size: .85rem;
}

/* Subtle, unlabeled lifetime indicator beneath a balance-page QR code.
   Purely presentational -- depletes from full to empty as the displayed
   QR approaches its refresh time. Deliberately one calm color throughout:
   a fresh QR replaces it automatically, so running out isn't a warning.
   Has no bearing on server-side QR validity. */
.menu-link {
  display: block;
  margin-top: .25rem;
  text-align: center;
  font-weight: 600;
  color: var(--brand);
  text-decoration: none;
}
.menu-link:hover { color: var(--brand-hover); text-decoration: underline; }
.qr-lifetime-bar {
  width: 200px;
  height: 4px;
  margin: .6rem auto 0;
  border-radius: 2px;
  background: var(--track);
  overflow: hidden;
}
.qr-lifetime-fill {
  width: 100%;
  height: 100%;
  border-radius: 2px;
  background-color: var(--qr-bar);
}
.qr-lifetime-fill.qr-lifetime-animate {
  animation-name: qr-lifetime-deplete;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}
@keyframes qr-lifetime-deplete {
  from { width: 100%; }
  to   { width: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .qr-lifetime-fill.qr-lifetime-animate {
    animation: none;
    width: 100%;
  }
}

.amount-topup  { color: var(--positive); font-weight: 600; }
.amount-charge { color: var(--negative); font-weight: 600; }

.page-error   { color: var(--negative); text-align: center; padding: 2rem; }
.loading-hint { text-align: center; padding: 2rem; color: var(--faint); }

/* ── Version footer ────────────────────────────────────────── */
.app-version {
  text-align: center;
  font-size: .75rem;
  color: var(--grey-blue);
  padding: 1.5rem 1rem 1rem;
}
