/* SuperBrief — SuperPark Glasgow brand palette
   purple #662483 · yellow #f0ff00 · turquoise #77f1b6
   dark purple #390253 · pink #ff008c                                        */

:root {
  --purple: #662483;
  --yellow: #f0ff00;
  --turquoise: #77f1b6;
  --deep: #390253;
  --pink: #ff008c;

  --bg: #24003a;
  --surface: #360a50;
  --surface-2: #45185f;
  --line: #5b2b76;
  --text: #f6eefb;
  --muted: #bda3cf;

  --ok: var(--turquoise);
  --warn: #ffb020;
  --error: var(--pink);

  --radius: 14px;
  --tap: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  overscroll-behavior-y: none;
}

body.is-dragging { user-select: none; touch-action: none; }

button, input, select, textarea { font: inherit; color: inherit; }

/* ------------------------------------------------------------- sign in */

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
  background:
    radial-gradient(120% 80% at 50% 0%, #5c1580 0%, transparent 60%),
    var(--bg);
}

.auth-card {
  width: min(380px, 100%);
  text-align: center;
}

.auth-logo { width: 92px; height: auto; margin-bottom: 12px; }

.auth-card h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: -0.02em;
}
.auth-card h1 span { color: var(--yellow); }

.auth-sub { margin: 4px 0 28px; color: var(--muted); }

.auth-card form { display: grid; gap: 6px; text-align: left; }
.auth-card label { font-size: 13px; color: var(--muted); margin-top: 10px; }

input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--turquoise); }
textarea { min-height: 120px; resize: vertical; }

.auth-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: rgba(255, 0, 140, 0.14);
  border: 1px solid var(--pink);
  border-radius: 10px;
  font-size: 14px;
}

.auth-card button[type="submit"], .primary-btn {
  margin-top: 18px;
  min-height: var(--tap);
  background: var(--yellow);
  color: #1a1a1a;
  border: 0;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
}
.auth-card button[disabled] { opacity: 0.6; }

.ghost-btn, .danger-btn {
  width: 100%;
  min-height: var(--tap);
  margin-top: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  padding: 0 14px;
}
.danger-btn { border-color: var(--pink); color: var(--pink); }

/* -------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--deep);
  border-bottom: 1px solid var(--line);
}

.topbar-logo { width: 30px; height: 30px; object-fit: contain; }

.topbar-title { flex: 1; min-width: 0; line-height: 1.15; }
.topbar-title strong { display: block; font-size: 16px; }
.topbar-title strong span { color: var(--yellow); }
.topbar-title small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#date-picker {
  width: auto;
  min-height: 36px;
  padding: 4px 8px;
  font-size: 13px;
}

.icon-btn {
  flex: none;
  width: 38px;
  height: 38px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 17px;
  cursor: pointer;
}

/* ----------------------------------------------------------- statusbar */

.statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.statusbar::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 13px;
  white-space: nowrap;
}
.chip-btn { cursor: pointer; }
.chip-ok { background: rgba(119, 241, 182, 0.16); border-color: var(--ok); color: var(--ok); }
.chip-warn { background: rgba(255, 176, 32, 0.16); border-color: var(--warn); color: var(--warn); }
.chip-error { background: rgba(255, 0, 140, 0.16); border-color: var(--error); color: var(--error); }

.saved { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px 0;
}
.tab {
  flex: 1;
  min-height: 38px;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--yellow); border-bottom-color: var(--yellow); }

main { padding: 12px 12px 0; padding-bottom: 96px; }

.hint { color: var(--muted); font-size: 13px; }

/* ------------------------------------------------------------ stations */

.station {
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 5px solid var(--zone);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: background 0.12s, box-shadow 0.12s;
}
.station.is-over { background: var(--surface-2); box-shadow: 0 0 0 2px var(--zone) inset; }

.station-head { display: flex; align-items: center; gap: 10px; }
.station-short {
  flex: none;
  min-width: 38px;
  padding: 3px 8px;
  text-align: center;
  background: var(--zone);
  color: var(--ink);
  border-radius: 8px;
  font-weight: 800;
  font-size: 13px;
}
.station-titles { flex: 1; min-width: 0; }
.station-titles strong { display: block; font-size: 14px; line-height: 1.25; }
.station-flag {
  display: inline-block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--warn);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.station-count {
  flex: none;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(119, 241, 182, 0.16);
  color: var(--ok);
  font-size: 13px;
  font-weight: 700;
}
.station-count.is-short { background: rgba(255, 0, 140, 0.16); color: var(--error); }

.station-body {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 40px;
  margin-top: 10px;
  padding: 4px;
  border: 1px dashed var(--line);
  border-radius: 10px;
}
.station-empty { margin: 6px; color: var(--muted); font-size: 13px; }

.duties { margin-top: 8px; }
.duties summary { color: var(--muted); font-size: 13px; cursor: pointer; }
.duties ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.duties li { margin-bottom: 2px; }

/* ------------------------------------------------------------ crew chip */

.crew {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 5px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: grab;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.crew.is-selected {
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px rgba(240, 255, 0, 0.35);
}
.crew-name { font-size: 14px; white-space: nowrap; }
.crew-tag {
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.03em;
}
.tag-sup { background: var(--turquoise); color: #06301f; }
.tag-u18 { background: var(--pink); color: #fff; }
.tag-time { background: var(--line); color: var(--text); font-weight: 600; }

.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  margin: -18px 0 0 -50px;
  padding: 8px 14px;
  background: var(--yellow);
  color: #1a1a1a;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* ----------------------------------------------------------- floorplan */

.plan-wrap { overflow: auto; -webkit-overflow-scrolling: touch; }
.plan {
  position: relative;
  width: 100%;
  min-width: 340px;
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
}
.plan img { display: block; width: 100%; height: auto; }

.plan-area {
  position: absolute;
  border: 2px solid transparent;
  border-radius: 8px;
  transition: background 0.12s, border-color 0.12s;
}
.plan-area.is-over {
  background: color-mix(in srgb, var(--zone) 35%, transparent);
  border-color: var(--zone);
}
.plan-area.is-short { background: rgba(255, 0, 140, 0.1); }

.plan-badge {
  position: absolute;
  top: 3px;
  left: 3px;
  max-width: 92%;
  padding: 3px 5px;
  background: rgba(255, 255, 255, 0.94);
  border: 1.5px solid var(--zone);
  border-radius: 7px;
  color: #1a1a1a;
  font-size: 10px;
  line-height: 1.3;
  pointer-events: none;
}
.plan-badge-head { display: flex; gap: 5px; align-items: center; }
.plan-badge-zone {
  padding: 0 4px;
  background: var(--zone);
  color: var(--ink);
  border-radius: 4px;
  font-weight: 800;
}
.plan-badge-count { font-weight: 700; }
.plan-badge-count.is-short { color: #c8006e; }
.plan-badge-name { display: block; white-space: nowrap; }

/* ---------------------------------------------------------------- pool */

.pool {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: var(--deep);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  max-height: 62dvh;
  display: flex;
  flex-direction: column;
}
.pool-handle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  min-height: 46px;
  padding: 0 16px;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-weight: 600;
}
.pool-caret { transition: transform 0.15s; color: var(--yellow); }
.pool.is-open .pool-caret { transform: rotate(180deg); }

.pool-body {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 14px;
  overflow-y: auto;
}
.pool.is-open .pool-body { display: flex; }

/* -------------------------------------------------------------- sheets */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(10, 0, 20, 0.6);
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 4px 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
}
.sheet-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0 8px;
  background: var(--surface);
}
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-sub { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.sheet-warn {
  margin: 10px 0 0;
  padding: 8px 10px;
  background: rgba(255, 0, 140, 0.14);
  border: 1px solid var(--pink);
  border-radius: 8px;
  font-size: 13px;
}

.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.issue-list { list-style: none; margin: 0; padding: 0; }
.issue {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: var(--surface-2);
  border-left: 4px solid var(--muted);
  font-size: 14px;
}
.issue-error { border-left-color: var(--error); }
.issue-warn { border-left-color: var(--warn); }
.issue strong { flex: none; min-width: 42px; color: var(--muted); }

.rules-block { margin-bottom: 18px; }
.rules-block h3 { margin: 0 0 8px; font-size: 14px; color: var(--yellow); }
.rules-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.rules-zone {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rules-std { flex: none; font-size: 11px; color: var(--muted); }
.rules-row input { width: 68px; min-height: 38px; text-align: center; }

/* --------------------------------------------------------------- print */

.print-only { display: none; }

@media print {
  .no-print, .pool, .sheet, .sheet-backdrop { display: none !important; }
  .print-only { display: block; }

  @page { size: A4 portrait; margin: 10mm; }

  html, body {
    background: #fff;
    color: #111;
    font-size: 9.5pt;
    line-height: 1.3;
  }

  .p-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 8px;
    border-bottom: 3px solid #662483;
  }
  .p-logo { width: 46px; height: auto; }
  .p-head h1 { margin: 0; font-size: 20pt; color: #662483; letter-spacing: -0.01em; }
  .p-date { margin: 2px 0 0; font-size: 10pt; font-weight: 600; }
  .p-count { margin-left: auto; text-align: center; }
  .p-count strong { display: block; font-size: 22pt; line-height: 1; color: #662483; }
  .p-count span { font-size: 8pt; text-transform: uppercase; letter-spacing: 0.06em; }

  .p-focus {
    margin: 8px 0;
    padding: 6px 10px;
    background: #f0ff00;
    border-radius: 4px;
    font-size: 10pt;
  }

  .p-cols { display: flex; gap: 10px; align-items: flex-start; margin-top: 8px; }
  .p-plan { flex: 0 0 40%; }
  .p-plan img { width: 100%; height: auto; border: 1px solid #ddd; }
  .p-key { display: flex; flex-wrap: wrap; gap: 3px 8px; margin-top: 6px; font-size: 7pt; }
  .p-key-item { display: flex; align-items: center; gap: 3px; }
  .p-swatch { width: 8px; height: 8px; border: 0.5px solid #999; border-radius: 2px; }

  .p-stations { flex: 1; min-width: 0; }
  .p-station {
    border-left: 3px solid #ccc;
    padding: 0 0 0 7px;
    margin-bottom: 7px;
    break-inside: avoid;
  }
  .p-station header { display: flex; gap: 8px; align-items: baseline; }
  .p-station header strong { font-size: 9.5pt; }
  .p-num { margin-left: auto; font-weight: 700; font-size: 9pt; }

  .p-people { list-style: none; margin: 2px 0; padding: 0; }
  .p-people li { display: flex; gap: 6px; align-items: baseline; padding: 1px 0; }
  .p-name { font-weight: 600; }
  .p-time { font-size: 8pt; color: #555; }
  .p-u18 {
    padding: 0 4px;
    background: #ff008c;
    color: #fff;
    border-radius: 6px;
    font-size: 6.5pt;
    font-weight: 700;
  }
  .p-note { font-size: 8pt; font-style: italic; color: #444; }
  .p-empty { margin: 2px 0; font-weight: 700; color: #c8006e; font-size: 8.5pt; }

  .p-duties { margin: 2px 0 0; padding-left: 14px; font-size: 7.5pt; color: #555; }

  .p-notes { margin-top: 10px; break-inside: avoid; }
  .p-notes h2 { margin: 0 0 3px; font-size: 10pt; color: #662483; }
  .p-notes p { margin: 0; white-space: pre-wrap; }

  .p-foot {
    margin-top: 10px;
    padding-top: 5px;
    border-top: 1px solid #ddd;
    font-size: 7.5pt;
    color: #666;
  }
}

/* ------------------------------------------------------------- desktop */

@media (min-width: 860px) {
  main {
    display: grid;
    grid-template-columns: 1fr;
    max-width: 1100px;
    margin: 0 auto;
    padding-bottom: 120px;
  }
  .station-body { min-height: 46px; }
  .plan { min-width: 0; }
  .plan-badge { font-size: 11px; }
  .pool-body { max-height: 30dvh; }
}
