/* Mobile-first styles for the app and the admin page. No inline styles anywhere (CSP). */

:root {
  color-scheme: light dark;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #17202b;
  --muted: #5a6677;
  --border: #d3dae4;
  /* Edge of inputs and buttons: at least 3:1 against the surface (WCAG 1.4.11). */
  --field-border: #7a8696;
  --primary: #0b5cab;
  --on-primary: #ffffff;
  --danger: #b3261e;
  --on-danger: #ffffff;
  --ok-bg: #dff3e4;
  --ok-text: #14532d;
  --warn-bg: #fdf0c8;
  --warn-text: #6b4a00;
  --bad-bg: #fbe0de;
  --bad-text: #7a1712;
  --off-bg: #e6e9ee;
  --off-text: #3f4957;
  --tabs-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #182029;
    --text: #e8edf3;
    --muted: #9aa7b6;
    --border: #2c3744;
    --field-border: #6b7a8c;
    --primary: #5aa2ee;
    --on-primary: #08121e;
    --danger: #ff8a80;
    --on-danger: #2b0b09;
    --ok-bg: #173a24;
    --ok-text: #b6e8c4;
    --warn-bg: #3d3210;
    --warn-text: #f1d98b;
    --bad-bg: #4a1f1c;
    --bad-text: #ffc9c4;
    --off-bg: #2a3340;
    --off-text: #c3ccd8;
  }
}

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overflow-wrap: anywhere;
  overflow-x: hidden;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 0.5rem;
}
h2 {
  font-size: 1.2rem;
  margin-top: 1.2rem;
}
h3 {
  font-size: 1rem;
}
p {
  margin: 0.4rem 0;
}
a {
  color: var(--primary);
}
img {
  max-width: 100%;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
}
.center {
  text-align: center;
}
.empty {
  color: var(--muted);
  text-align: center;
  padding: 1rem 0;
}
.empty .btn {
  margin-top: 8px;
}
.noscript {
  padding: 1rem;
  text-align: center;
}
/* Direct children of #app are the loading line and the start-up error card, shown before the shell exists. */
.app > .card,
.app > .empty {
  margin: 16px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* One visible focus ring for everything that can take keyboard focus. */
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}
/* Programmatic landing spots (a view heading after navigation) are not controls: no ring. */
[tabindex='-1']:focus {
  outline: none;
}

/* ---- shell ---------------------------------------------------------- */

.shell {
  min-height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: calc(56px + env(safe-area-inset-top));
  padding: calc(8px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 8px calc(16px + env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar .title {
  font-size: 1.1rem;
  margin: 0;
  flex: 1;
  min-width: 0;
}
.topbar .who {
  color: var(--muted);
  font-size: 0.85rem;
  min-width: 0;
}
.admin-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  font-size: 0.85rem;
  padding: 0 12px;
  border: 1px solid var(--field-border);
  border-radius: 8px;
  text-decoration: none;
}

.view {
  flex: 1;
  min-width: 0;
  padding: 4px calc(16px + env(safe-area-inset-right)) calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 640px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab {
  position: relative;
  min-height: var(--tabs-h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 2px;
  font-size: 0.72rem;
  text-align: center;
  text-decoration: none;
  color: var(--muted);
  border-top: 3px solid transparent;
  min-width: 0;
}
.tab-label {
  white-space: nowrap; /* never split "Inbox" over two lines on a 320px phone */
}
.tab[aria-current='page'] {
  color: var(--primary);
  border-top-color: var(--primary);
  font-weight: 600;
}
.badge {
  display: inline-block;
  min-width: 1.3em;
  padding: 0 0.35em;
  border-radius: 999px;
  background: var(--danger);
  color: var(--on-danger);
  font-size: 0.7rem;
  line-height: 1.5;
  text-align: center;
}
/* The count floats at the top right of the label so it never squeezes the label in a narrow tab. */
.tab .badge {
  position: absolute;
  top: 6px;
  left: calc(50% + 12px);
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--tabs-h) + 12px + env(safe-area-inset-bottom));
  max-width: 608px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 20;
}
.toast.show {
  opacity: 1;
}
.toast.error {
  background: var(--danger);
  color: var(--on-danger);
}

/* ---- cards and lists ------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 10px 0;
}
.card h2,
.card h3 {
  margin-top: 0;
}
.card h2 {
  font-size: 1rem; /* the admin cards: h2 for the outline, same look as the h3 cards in the app */
}
.error-card {
  text-align: center;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.when {
  font-weight: 600;
  margin-top: 2px;
}
.sub,
.note {
  color: var(--muted);
  font-size: 0.9rem;
}
.note {
  font-style: italic;
}
.reservation.pending {
  border-left: 4px solid var(--warn-text);
}
.reservation.confirmed {
  border-left: 4px solid var(--ok-text);
}
.reservation.declined,
.reservation.expired {
  border-left: 4px solid var(--off-text);
}
/* Finished items are quieter through lighter type, not opacity: faded text drops below 4.5:1. */
.reservation.past .when,
.history.unused .when {
  font-weight: 400;
}

.badge-status {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--off-bg);
  color: var(--off-text);
  white-space: nowrap;
}
.badge-status.confirmed {
  background: var(--ok-bg);
  color: var(--ok-text);
}
.badge-status.pending {
  background: var(--warn-bg);
  color: var(--warn-text);
}
.badge-status.declined {
  background: var(--bad-bg);
  color: var(--bad-text);
}

.day-heading {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}
details.earlier {
  margin-top: 1.2rem;
}
details.earlier summary {
  cursor: pointer;
  color: var(--muted);
  padding: 12px 0;
}
.totals {
  list-style: none;
  margin: 0;
  padding: 0;
}
.totals li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.totals li:last-child {
  border-bottom: 0;
}

/* ---- buttons and forms ---------------------------------------------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--field-border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}
.btn:disabled {
  opacity: 0.6;
  cursor: progress; /* a disabled button means a request is in flight */
}
/* Hover only where there is a real pointer, so a tap does not leave a sticky hover on phones. */
@media (hover: hover) {
  .btn:hover:not(:disabled) {
    background: var(--off-bg);
  }
  .btn.primary:hover:not(:disabled) {
    background: var(--primary);
    filter: brightness(1.12);
  }
  .btn.danger:hover:not(:disabled) {
    background: var(--bad-bg);
  }
  .tab:hover {
    color: var(--text);
  }
}
/* After the hover rules, so pressing always wins over hovering. */
.btn:active:not(:disabled) {
  background: var(--off-bg);
}
.btn.primary:active:not(:disabled) {
  background: var(--primary);
  filter: brightness(0.9);
}
.btn.danger:active:not(:disabled) {
  background: var(--bad-bg);
}
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
}
.btn.danger {
  color: var(--danger);
  border-color: var(--danger);
}
.btn.block {
  display: flex;
  width: 100%;
}
.btn.small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.9rem;
}

.field {
  margin-bottom: 14px;
  min-width: 0;
}
.field label,
.field .label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
  font-weight: 600;
}
input,
select,
textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--field-border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px stops iOS Safari from zooming into the field */
}
input:disabled,
select:disabled {
  background: var(--bg);
  color: var(--muted);
  cursor: not-allowed;
}
.tab:focus-visible {
  outline-offset: -3px; /* keep the ring inside the screen edge and the bar */
}
.pair {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 8px;
}
.field.invalid input,
.field.invalid select {
  border-color: var(--danger);
  box-shadow: inset 0 0 0 1px var(--danger); /* a thicker edge, so the state is not only a colour change */
}
.field-error,
.form-error {
  color: var(--danger);
  font-size: 0.85rem;
}
.field-error:empty {
  display: none;
}
.form-error {
  margin: 8px 0;
}
.notice {
  background: var(--warn-bg);
  color: var(--warn-text);
  padding: 10px 12px;
  border-radius: 10px;
}

.login {
  max-width: 420px;
  margin: 0 auto;
  padding: calc(32px + env(safe-area-inset-top)) 16px 24px;
  text-align: center;
}
.login .logo {
  border-radius: 16px;
}
.login .card {
  text-align: left;
}

/* ---- admin page (desktop friendly, same tokens) ----------------------- */

.admin-wrap {
  max-width: 1000px;
  margin: 0 auto;
  padding: 12px 16px 48px;
}
.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.admin-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 12px 0;
}
/* Same weight as the .btn hover/active rules above and later in the file, so the current tab keeps its colours. */
.admin-tabs .btn[aria-pressed='true'] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.table-wrap {
  /* On a phone the table scrolls inside this box (focusable, so the keyboard can scroll it);
     the page itself never scrolls sideways. */
  overflow-x: auto;
  overflow-wrap: normal;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
table.data {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.data th,
table.data td {
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
table.data tr:last-child td {
  border-bottom: 0;
}
table.data th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
table.data .actions {
  margin-top: 0;
}
.inline-form {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  align-items: end;
}
/* One-line labels with hints underneath (the add-user form): line the inputs up at the top instead. */
.inline-form.top {
  align-items: start;
}
.filters {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin: 10px 0;
}
.kv {
  display: grid;
  grid-template-columns: minmax(0, max-content) minmax(0, 1fr);
  gap: 4px 14px;
  margin: 0;
}
.kv dt {
  color: var(--muted);
}
.kv dd {
  margin: 0;
  min-width: 0;
}
@media (max-width: 560px) {
  .kv {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }
  .kv dt {
    margin-top: 8px;
    font-size: 0.85rem;
  }
}
.secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.05rem;
  background: var(--off-bg);
  padding: 4px 8px;
  border-radius: 6px;
  user-select: all;
}
.secret-card {
  border: 2px solid var(--primary);
}

@media (min-width: 700px) {
  .view {
    padding-bottom: 96px;
  }
}

/* Touch screens: every control gets a full-size target, including the compact admin buttons. */
@media (pointer: coarse) {
  .btn.small {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}
