/* Colour modes: dark by default, light with data-mode="light" on <html>.
   theme.js sets data-mode before the first paint, from the visitor's choice
   (Auto / Light / Dark; Auto follows the browser/system setting).
   An event theme (lanparty/themes/<id>/theme.css, see THEMES.md) is loaded
   after this file and overrides these tokens in the same two blocks. */
:root {
  --bg: #0f1220;
  --card: #181c2f;
  --border: #2a3050;
  --text: #e7e9f3;
  --muted: #9aa0bd;
  --accent: #5b8cff;
  --on-accent: #0f1220;       /* 5.9:1 */
  --accent-hover: #7aa2ff;    /* hovered primary button: 7.5:1 with --on-accent */
  --free: #2b3354;
  --free-hover: #3c4a80;
  --reserved: #c48a1a;
  --on-reserved: #1b1300;
  --paid: #2f9e5b;
  --on-paid: #0f1220;         /* 5.5:1 */
  --mine: #6d3fe0;
  --on-mine: #ffffff;         /* 6.1:1 (4.7:1 on hover) */
  --mine-ring: #e0d4ff;
  --danger: #d9485f;
  --danger-text: #ff8b9c;
  --success-text: #6ee7a0;
  --warning-text: #f3c15b;
  --banner-border: #8a6d1f;
  --hero-from: #1d2450;
  --hero-to: #3a1f5c;
  --hero-text: #d4d8f0;
  --input-bg: #0f1324;
  --button-bg: #2a3152;
  --map-bg: #121628;
  --area-bg: rgba(255, 255, 255, .02);
  --grid-line: rgba(255, 255, 255, .05);
  --table-bg: #3a4170;
  --table-border: #4b5490;
  --backdrop: rgba(0, 0, 0, .6);
  color-scheme: dark;

  /* not colours, but themes may change them too */
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, Menlo, Consolas, monospace;
  --radius-scale: 1;          /* 0 = square corners everywhere */
}
:root[data-mode="light"] {
  --bg: #f3f4f9;
  --card: #ffffff;
  --border: #d3d8e8;
  --text: #1a1d2e;
  --muted: #555c78;
  --accent: #2f5fd6;
  --on-accent: #ffffff;
  --accent-hover: #2a56c6;    /* 6.5:1 with --on-accent */
  --free: #f5f7ff;
  --free-hover: #dfe5ff;
  --reserved: #e3a63a;
  --on-reserved: #1b1300;
  --paid: #3aa865;
  --on-paid: #0f1220;
  --mine: #6d3fe0;
  --on-mine: #ffffff;
  --mine-ring: #c9b6ff;
  --danger: #c8283f;
  --danger-text: #b01f35;
  --success-text: #157a3a;
  --warning-text: #7a5000;
  --banner-border: #d9a73a;
  --hero-from: #dfe6ff;
  --hero-to: #ecdfff;
  --hero-text: #2c3150;
  --input-bg: #ffffff;
  --button-bg: #e6e9f4;
  --map-bg: #f8f9fd;
  --area-bg: rgba(20, 30, 80, .02);
  --grid-line: rgba(20, 30, 80, .08);
  --table-bg: #b4bee6;
  --table-border: #8f9bd0;
  --backdrop: rgba(20, 24, 40, .45);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  font-family: var(--font-body);
}

a { color: var(--accent); }
/* --accent on the header gradient stays just under 4.5:1; --hero-text is made for it */
.hero a { color: var(--hero-text); text-decoration: underline; }
h1, h2 { line-height: 1.2; }
h2 { margin-top: 0; font-size: 1.25rem; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

.hero {
  background: linear-gradient(135deg, var(--hero-from), var(--hero-to));
  padding: 1.5rem 0 1rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.hero h1 { margin: 0 0 .5rem; font-size: 2rem; }
.header-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }

.facts { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; color: var(--hero-text); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(12px * var(--radius-scale));
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.upcoming { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; }
.upcoming li {
  display: flex; flex-direction: column; gap: .15rem;
  padding: .6rem .8rem; border: 1px solid var(--border); border-radius: calc(8px * var(--radius-scale));
}

/* admin: event picker */
.event-bar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.event-bar label { flex: 1 1 260px; min-width: 0; }
.event-bar select { width: 100%; }  /* long event names must not widen the page */
.badge.status-active { background: var(--paid); color: var(--on-paid); }
.badge.status-upcoming { background: var(--accent); color: var(--on-accent); }
.badge.status-archived, .badge.status-draft { background: var(--free); color: var(--text); }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.prewrap { white-space: pre-wrap; }
.mono { font-family: var(--font-mono); word-break: break-all; }
.big { font-size: 1.4rem; font-weight: 700; margin: .25rem 0 .75rem; }

footer { padding: 1rem 16px 2rem; }

/* forms */
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--muted); }
input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: calc(8px * var(--radius-scale));
  padding: .5rem .6rem;
  min-width: 0;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.form-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.form-row label { flex: 1 1 200px; }

button {
  font: inherit;
  cursor: pointer;
  color: var(--text);
  background: var(--button-bg);
  border: 1px solid var(--border);
  border-radius: calc(8px * var(--radius-scale));
  padding: .5rem .9rem;
}
/* Primary buttons get their own hover colour: brightening the light-mode accent
   would drop white text below 4.5:1. */
button:hover:not(:disabled):not(.primary) { filter: brightness(1.2); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger-text); }
button.link { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; }

.settings { display: grid; gap: 1rem; }
.settings fieldset {
  border: 1px solid var(--border);
  border-radius: calc(10px * var(--radius-scale));
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: .75rem;
}
.settings legend { padding: 0 .4rem; color: var(--text); }
.settings .full { grid-column: 1 / -1; }
.theme-preview-row { align-self: end; margin: 0 0 .6rem; }
label.checkbox { flex-direction: row; align-items: center; gap: .5rem; flex-wrap: wrap; color: var(--text); }
label.checkbox small { flex-basis: 100%; }
label.checkbox.inline { display: inline-flex; margin: 0 .5rem; }
label small { line-height: 1.35; }
.access-actions p { margin: .6rem 0; }
.access-actions .muted { display: block; margin-top: .2rem; }
.confirm-password { max-width: 26rem; }

/* admin areas: navigation, overview tiles, check lists */
.admin-nav { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; padding-bottom: .6rem; }
.hero .admin-nav a { text-decoration: none; padding: .15rem 0; border-bottom: 2px solid transparent; }
.hero .admin-nav a:hover { border-bottom-color: var(--hero-text); }
.hero .admin-nav a[aria-current="page"] { border-bottom-color: var(--hero-text); font-weight: 600; }
.overview-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.overview-grid .card { margin: 0; }
a.overview-card { display: block; color: var(--text); text-decoration: none; }
a.overview-card:hover, a.overview-card:focus-visible { border-color: var(--accent); }
.checks { list-style: none; padding: 0; margin: 0; display: grid; gap: .45rem; }
.check { padding-left: 1.6rem; position: relative; }
.check::before { position: absolute; left: 0; font-weight: 700; }
.check.ok::before { content: "✓"; color: var(--success-text); }
.check.warn { color: var(--warning-text); }
.check.warn::before { content: "!"; color: var(--warning-text); }
.check.info::before { content: "i"; color: var(--muted); }

.actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }

.message { min-height: 1.2em; margin: .75rem 0 0; }
.message.error { color: var(--danger-text); }
.message.success { color: var(--success-text); }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: calc(999px * var(--radius-scale)); font-size: .8rem; background: var(--free); }
.badge.paid { background: var(--paid); color: var(--on-paid); }
.badge.reserved { background: var(--reserved); color: var(--on-reserved); }

/* seat map */
.legend { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; font-size: .875rem; color: var(--muted); margin-bottom: 1rem; }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.seat-dot { width: 14px; height: 14px; border-radius: calc(4px * var(--radius-scale)); display: inline-block; }
.seat-dot.free { background: var(--free); box-shadow: inset 0 0 0 1px var(--table-border); }
.seat-dot.reserved { background: var(--reserved); }
.seat-dot.paid { background: var(--paid); }
.seat-dot.mine { background: var(--mine); }

.seat-map {
  --u: 36px;
  overflow: auto;
  padding: 1.5rem .75rem .75rem;
  border: 1px solid var(--border);
  border-radius: calc(10px * var(--radius-scale));
  background: var(--map-bg);
}
.area {
  position: relative;
  margin: 0 auto;
  border-radius: calc(4px * var(--radius-scale));
  background-color: var(--area-bg);
  outline: 1px dashed var(--border);
}
.area.cropped { outline: none; background-color: transparent; }
.group { position: absolute; }
.group-label {
  position: absolute;
  bottom: 100%;
  left: 0;
  font-size: .75rem;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
  color: var(--text);
  pointer-events: none;
  z-index: 3;
  text-shadow: 0 0 3px var(--bg), 0 0 3px var(--bg);
}
.group-name { font-weight: 400; color: var(--muted); }
.table {
  position: absolute;
  background: var(--table-bg);
  border: 1px solid var(--table-border);
  border-radius: calc(5px * var(--radius-scale));
}
.seat {
  position: absolute;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  border: 4px solid transparent;
  background-clip: padding-box;
  border-radius: calc(8px * var(--radius-scale));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: max(9px, calc(var(--u) * .27));
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  overflow: hidden;
}
.seat.free { background-color: var(--free); }
.seat.reserved { background-color: var(--reserved); color: var(--on-reserved); }
.seat.paid { background-color: var(--paid); color: var(--on-paid); }
.seat.mine { background-color: var(--mine); color: var(--on-mine); box-shadow: inset 0 0 0 2px var(--mine-ring); }
button.seat.free:hover:not(:disabled) { background-color: var(--free-hover); box-shadow: inset 0 0 0 2px var(--accent); filter: none; }
button.seat:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.seat:disabled { cursor: default; }
.seat.free:disabled { opacity: .6; }

/* area elements (doors, windows, sleeping area, food & drinks, other) */
.item {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .25em;
  padding: 0 .2em;
  overflow: hidden;
  border: 1px dashed var(--item-border);
  border-radius: calc(6px * var(--radius-scale));
  background: var(--item-bg);
  color: var(--text);
  font-size: calc(var(--u) * .32);
  line-height: 1.1;
  text-align: center;
}
.item.tall { flex-direction: column; }
.item-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.tall .item-label { writing-mode: vertical-rl; max-height: 100%; }
.item-door     { --item-bg: rgba(176, 116, 58, .35);  --item-border: #c98a4b; border-style: solid; }
.item-window   { --item-bg: rgba(92, 179, 222, .25);  --item-border: #6cc3ea; border-style: solid; }
.item-sleeping { --item-bg: rgba(110, 96, 220, .16);  --item-border: #8a7cf0; }
.item-food     { --item-bg: rgba(226, 132, 54, .18);  --item-border: #e68a3c; }
.item-other    { --item-bg: rgba(160, 166, 190, .12); --item-border: #8d93ad; }

.header-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
#session-controls:not([hidden]) { display: inline-flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.nowrap { white-space: nowrap; }

#code-form label { flex: 0 1 14rem; }
.code-input { text-transform: uppercase; letter-spacing: .25em; font-family: var(--font-mono); }

.warning { color: var(--warning-text); }
.banner { border-color: var(--banner-border); }
/* a step the participant still has to take (e.g. confirm the email address) */
.notice { border: 1px solid var(--banner-border); border-radius: calc(8px * var(--radius-scale)); padding: .25rem .9rem; margin: .5rem 0 .75rem; }
.copy-row > input { min-width: 0; }

/* login links */
.login-link-box { border-top: 1px solid var(--border); margin-top: 1rem; padding-top: .75rem; }
.logout-box { border-top: 1px solid var(--border); margin-top: 1rem; padding-top: .75rem;
  display: flex; flex-wrap: wrap; gap: .5rem; }
.copy-row { display: flex; gap: .5rem; margin-top: .75rem; }
.copy-row input { flex: 1; font-family: var(--font-mono); font-size: .8rem; }

/* audit log */
.audit-table td { font-size: .8rem; vertical-align: top; }
.audit-table .details { font-family: var(--font-mono); word-break: break-word; color: var(--muted); }
.audit-table .action-security { color: var(--danger-text); }

/* layout editor */
.editor-toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: .75rem; }
.editor-toolbar label { width: 7.5rem; }
.editor-toolbar .spacer { flex: 1; }
/* layout templates (top of the layout card) */
.template-panel { border: 1px solid var(--border); border-radius: calc(8px * var(--radius-scale)); padding: .75rem 1rem; margin-bottom: 1rem; }
.template-panel h3 { margin: 0 0 .25rem; }
.template-panel .editor-toolbar { margin-bottom: .5rem; }
.editor-toolbar label.template-choice { width: auto; flex: 0 1 20rem; min-width: 0; }
.template-choice select { width: 100%; }
.template-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) auto; gap: .75rem; align-items: end; margin-bottom: .5rem; }
.template-form .actions { grid-column: 3; grid-row: 1; }
.template-form label.checkbox { grid-column: 1 / 3; flex-wrap: nowrap; align-items: flex-start; }
.template-form label.checkbox input { margin-top: .2rem; flex-shrink: 0; }
.template-preview { --u: 12px; padding: .75rem; max-width: 100%; }
.template-preview .seat, .template-preview .item-label, .template-preview .group-name { font-size: 0; }
.template-preview .group-label { font-size: .65rem; }
.template-preview .item-icon { font-size: calc(var(--u) * .8); }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 1rem; align-items: start; }
.editor-canvas { --u: 28px; }
.editor-canvas .area {
  background-color: var(--input-bg);
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: var(--u) var(--u);
  outline: 1px dashed var(--border);
}
.editor-canvas .editable {
  cursor: grab;
  touch-action: none;
  user-select: none;
  border-radius: calc(6px * var(--radius-scale));
  outline: 1px dashed transparent;
  outline-offset: 2px;
}
.editor-canvas .editable:hover { outline-color: var(--muted); }
.editor-canvas .editable:focus { outline: none; }
.editor-canvas .editable.selected { outline: 2px solid var(--accent); z-index: 1; }
.editor-canvas .editable.invalid { outline: 2px solid var(--danger); }
/* keyboard focus is always visible, whether or not the element is selected */
.editor-canvas .editable:focus-visible {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  z-index: 2;
}
.editor-canvas .editable.dragging { cursor: grabbing; opacity: .85; z-index: 2; }
.resize-handle {
  display: none;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--accent) 50%);
  border-bottom-right-radius: calc(5px * var(--radius-scale));
}
.editor-canvas .item.selected .resize-handle { display: block; }
.add-items { align-items: center; }
.add-items button { padding: .35rem .7rem; font-size: .875rem; }
.editor-canvas .seat { border-width: 3px; }
.canvas-empty { margin: .5rem 0 0; text-align: center; }
.group-panel {
  border: 1px solid var(--border);
  border-radius: calc(10px * var(--radius-scale));
  padding: .9rem;
}
.group-panel h3 { margin: 0 0 .5rem; font-size: 1rem; }
.group-panel form { display: grid; gap: .6rem; }
/* long (translated) option texts must not widen the panel on phones */
.group-panel select, .group-panel input { width: 100%; min-width: 0; }
.group-panel .pair { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.group-panel .actions { justify-content: space-between; }
.problems { margin: .75rem 0 0; padding-left: 1.2rem; color: var(--danger-text); font-size: .875rem; }
.problems:empty { display: none; }
.message.info { color: var(--text); }
button:disabled { opacity: .5; cursor: default; }

/* table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; }
.actions-cell { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.actions-cell .move { display: inline-flex; gap: .25rem; }
.actions-cell button, .actions-cell select { padding: .3rem .6rem; font-size: .85rem; }

/* dialog */
dialog {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: calc(14px * var(--radius-scale));
  max-width: min(480px, calc(100vw - 32px));
  padding: 1.5rem;
}
dialog::backdrop { background: var(--backdrop); }
dialog p { margin: .25rem 0; }
dialog .actions { margin-top: 1rem; }

/* theme switch */
.header-switches { display: flex; flex-wrap: wrap; gap: .4rem; }
.header-switches select { padding: .3rem .5rem; font-size: .875rem; background: var(--input-bg); }
.hero .header-row h1 { margin-bottom: .5rem; }

#map-hint { margin: 0 0 .5rem; }

@media (max-width: 800px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .hero h1 { font-size: 1.5rem; }
  .card { padding: 1rem; }
  .seat-map { --u: 30px; padding: 1.5rem .5rem .5rem; }
  .editor-canvas { --u: 24px; }
  .template-form { grid-template-columns: minmax(0, 1fr); }
  .template-form .actions, .template-form label.checkbox { grid-column: auto; grid-row: auto; }
  dialog { padding: 1.1rem; }
  .big { font-size: 1.2rem; }
  /* long PayPal addresses wrap instead of widening the dialog */
  .big.mono { overflow-wrap: anywhere; }
}

/* Narrow screens: data tables become one card per row; each cell shows its
   column name from data-label (set by admin.js). */
@media (max-width: 700px) {
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr {
    border: 1px solid var(--border);
    border-radius: calc(10px * var(--radius-scale));
    padding: .5rem .75rem;
    margin-bottom: .75rem;
  }
  table.stack td {
    border: none;
    padding: .2rem 0;
    display: grid;
    grid-template-columns: 6.5rem minmax(0, 1fr);
    gap: .5rem;
    overflow-wrap: anywhere;
    white-space: normal;   /* also for .nowrap cells (audit timestamps): a card has no room for it */
  }
  table.stack td::before { content: attr(data-label); color: var(--muted); font: .8rem/1.5 var(--font-body); }
  table.stack td.actions-cell { display: flex; padding-top: .5rem; }
  table.stack td.actions-cell::before { content: none; }
  table.stack td[colspan] { display: block; }
  table.stack td[colspan]::before { content: none; }
  .actions-cell button, .actions-cell select { padding: .45rem .7rem; }
}
