:root {
  --bg: #0e1116;
  --surface: #171b22;
  --surface-2: #1f242d;
  --line: #2a313b;
  --text: #e6eaf0;
  --muted: #94a0b0;
  --accent: #2f6fed;
  --accent-soft: #1d3a7a;
  --ok: #22a06b;
  --warn: #c77700;
  --danger: #d6001c;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* An explicit display on a class beats the browser's own [hidden] rule, so
   state it once and let it win everywhere. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

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

/* ---------------------------------------------------------------- gate */

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate[hidden] { display: none; }
.gate-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.gate-brand { margin: 0; font-size: 26px; letter-spacing: 3px; }
.gate-sub { margin: 4px 0 20px; color: var(--muted); font-size: 14px; }
.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tabs button {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  cursor: pointer;
}
.tabs button.active { background: var(--accent); border-color: var(--accent); }

/* ---------------------------------------------------------------- layout */

.app { min-height: 100dvh; display: flex; flex-direction: column; }
.app[hidden] { display: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand .kort {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 1px;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.brand .word { font-weight: 600; font-size: 15px; letter-spacing: 0.3px; }
.topbar-right { margin-left: auto; min-width: 0; }
.whoami {
  color: var(--muted);
  font-size: 13px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 4px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 8px;
  white-space: nowrap;
  font-size: 14px;
}
.nav a.active { background: var(--surface-2); color: var(--text); }
.nav a .pill {
  display: inline-block;
  min-width: 18px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  text-align: center;
}

.view { padding: 18px 14px 60px; max-width: 1100px; width: 100%; margin: 0 auto; }

/* ---------------------------------------------------------------- pieces */

h2 { font-size: 19px; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 22px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile .n { font-size: 26px; font-weight: 700; }
.tile .l { color: var(--muted); font-size: 13px; }
.tile.alert { border-color: var(--warn); }
.tile.alert .n { color: var(--warn); }

.stack { display: flex; flex-direction: column; gap: 12px; }
label { display: block; font-size: 13px; color: var(--muted); }
label input, label select, label textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

button.primary, button.ghost, button.danger {
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  border: 1px solid transparent;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: var(--surface-2); border-color: var(--line); }
button.danger { background: transparent; border-color: var(--danger); color: #ff8a97; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.error { color: #ff8a97; min-height: 20px; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------------------------------------------------------------- shifts */

.daygroup { margin-bottom: 22px; }
.dayhead {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}
.dayhead .d { font-weight: 600; }
.dayhead .w { color: var(--muted); font-size: 13px; margin-left: auto; }
.dayhead.today .d { color: var(--accent); }

.shift {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 11px 13px;
  margin-bottom: 8px;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.shift:hover { background: var(--surface-2); }
.shift .time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 96px; }
.shift .time .dt { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.shift .main { flex: 1; min-width: 0; }
.shift .who { font-size: 13px; color: var(--muted); }
.shift .cust { font-weight: 600; }
.shift .meta { font-size: 13px; color: var(--muted); }
.shift .right { text-align: right; font-size: 12px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.5px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  white-space: nowrap;
}
.badge.open { border-color: var(--accent); color: #9dbcff; }
.badge.assigned { border-color: var(--ok); color: #6fd3a6; }
.badge.draft { border-color: var(--muted); color: var(--muted); }
.badge.cancelled { border-color: var(--danger); color: #ff8a97; text-decoration: line-through; }
.badge.completed { border-color: var(--ok); color: var(--muted); }
.badge.warn { border-color: var(--warn); color: #e8ab4f; }

.issue { font-size: 13px; padding: 6px 10px; border-radius: 8px; margin: 4px 0; }
.issue.block { background: rgba(214, 0, 28, 0.12); color: #ff9aa5; }
.issue.warn { background: rgba(199, 119, 0, 0.14); color: #e8ab4f; }

.candidate {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.candidate .name { flex: 1; }
.candidate.blocked .name { color: var(--muted); }

.warn-text { color: var(--warn); }
.offline-banner {
  background: rgba(199, 119, 0, 0.16);
  border: 1px solid var(--warn);
  color: #e8ab4f;
  border-radius: 10px;
  padding: 10px 13px;
  margin-bottom: 14px;
  font-size: 13px;
}
/* The clock is the one button a guard uses in the dark, with gloves on. */
button.big { width: 100%; padding: 16px; font-size: 17px; font-weight: 600; }
.onshift { padding: 13px 16px; }
.onshift .candidate:last-child { border-bottom: 0; padding-bottom: 0; }
.onshift .who-big { font-size: 17px; font-weight: 600; margin-top: 2px; }
.onshift a { color: var(--accent); }

.blocked-list { margin-top: 16px; }
.blocked-list summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  padding: 8px 0;
  list-style: none;
}
.blocked-list summary::before { content: '▸ '; }
.blocked-list[open] summary::before { content: '▾ '; }
.blocked-list summary::-webkit-details-marker { display: none; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.table-wrap { overflow-x: auto; }

/* ---------------------------------------------------------------- modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: 0;
  font-size: 24px;
  color: var(--muted);
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 18px;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: 90vw;
}
.toast[hidden] { display: none; }
.toast.bad { border-color: var(--danger); }

.empty { color: var(--muted); padding: 26px 0; text-align: center; }

.weekbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.weekbar .label { font-weight: 600; white-space: nowrap; }
.weekbar .nav-week { padding: 10px 14px; line-height: 1; }
.weekbar .range { white-space: nowrap; margin-left: auto; }
.weekbar #newShift { white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  cursor: pointer;
  font-size: 13px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

@media (max-width: 640px) {
  .row, .row-3 { grid-template-columns: 1fr; }
  .view { padding: 14px 10px 70px; }

  /* On a phone the status and the person get their own line under the shift,
     so neither the customer name nor the name of the guard gets squeezed. */
  .shift { flex-wrap: wrap; gap: 8px 12px; }
  .shift .time { min-width: 88px; }
  .shift .main { flex: 1 1 60%; }
  .shift .right {
    flex: 1 1 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: left;
  }
  .shift .right .who { color: var(--muted); }

  .weekbar .range { display: none; }
  .weekbar #newShift { flex: 1 1 100%; }
}
