:root {
  --bg: #f1f5f9; --card: #fff; --fg: #0f172a; --muted: #64748b;
  --accent: #2563eb; --accent-fg: #fff; --danger: #dc2626; --border: #cbd5e1;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 16px/1.5 system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--fg); }

/* Start page: a single centered card, mobile-first vertical with minimal scrolling */
.center { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; width: 100%; max-width: 380px; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
h1 { font-size: 1.25rem; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 16px; font-size: .9rem; }
.hint { color: var(--muted); font-size: .85rem; }

label { display: block; font-size: .85rem; margin: 10px 0 4px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=datetime-local], input[type=number], input[type=time], select {
  width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 1rem; background: #fff; color: var(--fg); }
button { width: 100%; padding: 11px; margin-top: 16px; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-fg); font-size: 1rem; font-weight: 600; cursor: pointer;
  transition: background-color .25s ease, color .25s ease; }
button.secondary { background: #e2e8f0; color: var(--fg); }
button.danger { background: var(--danger); color: #fff; }
button:disabled { opacity: .6; cursor: not-allowed; }
/* In-button action feedback (e.g. door buttons): fade to the status colour + show the message,
   then revert. Keeps full opacity while disabled so the message stays readable. */
button.feedback-ok  { background: #16a34a; color: #fff; opacity: 1; cursor: default; }
button.feedback-err { background: var(--danger); color: #fff; opacity: 1; cursor: default; }

.msg { margin-top: 12px; padding: 10px; border-radius: 8px; font-size: .9rem; display: none; }
.msg.err { display: block; background: #fee2e2; color: #991b1b; }
.msg.ok  { display: block; background: #dcfce7; color: #166534; }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.check input { width: auto; }
.check label { margin: 0; }
.balance { font-size: 2rem; font-weight: 700; margin: 8px 0; }
/* "Guthaben:" left, value right on one line; parts keep their own font size, baseline-aligned. */
.balance-line { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; margin: 8px 0; }
.balance-line .balance { margin: 0; }
.balance-line .hint { margin: 0; }

/* CAPTCHA (local image) on the password-recovery form */
.captcha-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.captcha-img { border: 1px solid var(--border); border-radius: 8px; background: #fff; flex: 0 0 auto; }
.captcha-row .btn-auto { margin: 0; }

/* Public station / fill status banners. Colour transitions so transient diver messages
   (statusFlash) fade in/out in place instead of a separate flash that scrolls the page. */
.status { padding: 10px 12px; border-radius: 8px; font-size: .95rem; font-weight: 600; margin: 12px 0; text-align: center;
  transition: background-color .25s ease, color .25s ease; }
.status.avail { background: #dcfce7; color: #166534; }
.status.busy  { background: #fef9c3; color: #854d0e; }
.status.closed { background: #fee2e2; color: #991b1b; }

/* Opening hours + closures on the login/setup screen */
.hours-title { font-size: .95rem; margin: 16px 0 6px; }
.hours-table { width: 100%; border: 0; }
.hours-table td { border: 0; padding: 2px 0; font-size: .9rem; }
.hours-table td.day { width: 3em; color: var(--muted); font-weight: 600; }
.hours-table .muted { color: var(--muted); }
.closures { margin: 0; padding-left: 18px; font-size: .9rem; }
.closures li { margin: 2px 0; }

/* Diver fill rows */
/* Stations block: symmetric 16px gap above (after the door buttons, via this margin-top) and
   below (the following button's own margin-top provides the 16px — buttons are inline-block and
   don't margin-collapse, so we add NO bottom margin here). Rows space 10px between each other. */
#fillArea { margin: 16px 0 0; }
.fill-row { display: flex; align-items: center; gap: 10px; padding: 10px; margin: 10px 0;
  border: 1px solid var(--border); border-radius: 8px; }
.fill-row:first-child { margin-top: 0; }
.fill-row:last-child { margin-bottom: 0; }
.fill-row > div:first-child { flex: 1; }
.fill-row.run { background: #f0fdf4; border-color: #86efac; }
.fill-row button { width: auto; margin: 0; padding: 8px 14px; }
.fill-meta { text-align: right; font-size: .85rem; display: flex; flex-direction: column; }
.fill-meta .elapsed { font-weight: 700; }

.pw-field { display: flex; gap: 8px; }
.pw-field input { flex: 1; }
.pw-field button { margin-top: 0; width: auto; }

/* Admin layout */
header.bar { display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5; flex-wrap: wrap; gap: 8px; }
.bar-right { display: flex; align-items: center; gap: 10px; }
.btn-auto { width: auto; margin: 0; padding: 8px 12px; }
main { max-width: 960px; margin: 0 auto; padding: 16px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar h1 { margin: 0; }

table { width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: .9rem; }
th { background: #f8fafc; color: var(--muted); }
tr.inactive { opacity: .5; }
.tag { display: inline-block; padding: 1px 6px; border-radius: 999px; font-size: .75rem; background: #e2e8f0; }
.tag.admin { background: #dbeafe; color: #1e40af; }
.actions { display: flex; gap: 6px; }
.actions button { width: auto; margin: 0; padding: 6px 10px; font-size: .8rem; }

/* Collapsible panels (stations, config, mail, users) */
.panel { background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; margin-bottom: 12px; }
.panel summary { cursor: pointer; font-weight: 600; }
.panel[open] summary { margin-bottom: 8px; }
.panel h2 { font-size: .95rem; margin: 16px 0 6px; }
/* Space the holiday add-row from the table directly above it */
#holidayPanel > .pw-field { margin-top: 12px; }
#hoursTable input[type=time] { padding: 4px 6px; }

/* Pagination: page-size selector + page controls above the list, controls again below it */
.pager-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.pager-bar label { margin: 0; }
.pager-bar select { width: auto; }
.pager { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pager:not(:empty) { margin-top: 12px; }           /* spacing only when it actually shows (below the table) */
.pager-bar .pager { margin-top: 0; }               /* the top pager sits inline with the select */
.pager:empty { display: none; }
.pager .pager-info { color: var(--muted); font-size: .85rem; }
.pager button { width: auto; margin: 0; padding: 6px 12px; }
.pager button:disabled { opacity: .5; cursor: not-allowed; }

/* Paginated tables: every cell stays on ONE line. Text cells that exceed their width fade out
   at the right edge (mask gradient) instead of wrapping to a second line. The actions column
   (interactive buttons) keeps its natural width and is never clipped/faded. */
.paged-table td, .paged-table th { white-space: nowrap; }
.paged-table td:not(.actions) {
  max-width: 220px; overflow: hidden; text-overflow: clip;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent 100%);
          mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent 100%);
}

/* User list filter bar */
.filters { display: flex; gap: 8px; align-items: center; flex: 1; flex-wrap: wrap; }
.filters input[type=text] { width: auto; flex: 1; min-width: 180px; }
.filters select { width: auto; }
button.active { background: var(--accent); color: var(--accent-fg); }
/* A filter bar that sits directly above content needs breathing room below it */
.filter-bar { margin-bottom: 12px; }
/* Standalone block inputs in the lock panel get spacing from the control above */
#lockPanel > input[type=datetime-local], #lockPanel > input[type=text] { margin-top: 6px; }
/* Standalone save buttons directly under a panel get spacing from the control above */
.panel > .btn-auto { margin-top: 12px; }

/* Tab navigation + sections */
nav.tabs { display: flex; gap: 6px; max-width: 960px; margin: 12px auto 0; padding: 0 16px; flex-wrap: wrap; }
nav.tabs .btn-auto { background: #e2e8f0; color: var(--fg); }
nav.tabs .btn-auto.active { background: var(--accent); color: var(--accent-fg); }

/* Bar charts (built via DOM API; bar heights set through CSSOM for CSP safety) */
.chart { display: flex; align-items: stretch; gap: 3px; height: 180px; position: relative; }
.bar-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.bar-area { flex: 1; display: flex; align-items: flex-end; }
.bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px;
  transition: background .08s ease; }
.bar-col:hover .bar { background: #1d4ed8; }
.bar-label { font-size: .65rem; text-align: center; color: var(--muted); padding-top: 3px; }

/* Custom chart tooltip: appears instantly, anchored above the hovered bar with a pointer arrow.
   Positioned via CSSOM (left/top + --arrow-x) so it stays CSP-safe (no inline styles in HTML). */
.chart-tip {
  position: absolute; left: 0; top: 0; transform: translate(-50%, calc(-100% - 9px));
  background: var(--fg); color: #fff; padding: 5px 9px; border-radius: 7px;
  font-size: .72rem; line-height: 1.25; white-space: nowrap; text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.25); pointer-events: none; z-index: 20;
  opacity: 0; transition: opacity .07s ease; }
.chart-tip.show { opacity: 1; }
.chart-tip .chart-tip-v { display: block; font-weight: 700; }
.chart-tip .chart-tip-d { display: block; color: #cbd5e1; font-size: .66rem; }
.chart-tip::after {
  content: ''; position: absolute; top: 100%; left: calc(50% + var(--arrow-x, 0px));
  transform: translateX(-50%); border: 5px solid transparent; border-top-color: var(--fg); }

/* Log table: keep the details column from blowing up the layout */
td.details { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; color: var(--muted); }

/* Live monitor: diver info as label/value rows; the elapsed clock uses tabular figures so it
   doesn't jitter as it ticks each second. */
.live-info { margin: 12px 0; display: grid; gap: 0; }
.live-info > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 7px 0; border-bottom: 1px solid var(--border); }
.live-info dt { color: var(--muted); font-size: .9rem; margin: 0; }
.live-info dd { margin: 0; font-weight: 600; }
.live-elapsed { font-variant-numeric: tabular-nums; font-weight: 700; }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: none; align-items: center; justify-content: center; padding: 16px; }
.modal.open { display: flex; }
.modal .card { max-width: 420px; max-height: 90dvh; overflow: auto; }
.modal h2 { font-size: 1rem; margin: 16px 0 8px; }
.amount-pos { color: #166534; }
.amount-neg { color: var(--danger); }

/* PDF export: print-only container. Hidden on screen; on print it's the only thing shown. */
#printArea { display: none; }
#printArea h1 { font-size: 1.1rem; }
#printArea td { font-size: .75rem; word-break: break-word; }
@media print {
  header.bar, nav.tabs, main, .modal { display: none !important; }
  #printArea { display: block; }
}
