:root {
  --nhs-blue: #005eb8;
  --nhs-dark: #003087;
  --nhs-bright: #0072ce;
  --nhs-aqua: #00a9ce;
  --nhs-teal: #00a499;
  --nhs-green: #009639;
  --nhs-warm: #ed8b00;
  --nhs-warm-bg: #fff4e0;
  --nhs-warm-border: #f3c06a;
  --nhs-purple: #330072;
  --ink: #231f20;
  --muted: #425563;
  --line: #d8dde3;
  --paper: #f4f7fb;
  --card: #ffffff;
  --you: #007f3b;
  --danger: #da291c;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(0, 48, 135, 0.08);
  --header-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Source Sans 3", "Frutiger", "Arial", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  min-height: 100dvh;
  line-height: 1.4;
}

button, select, input { font: inherit; }
button { cursor: pointer; }
.app { min-height: 100dvh; display: flex; flex-direction: column; }

/* Header */
.topbar {
  background: linear-gradient(180deg, var(--nhs-dark) 0%, var(--nhs-blue) 100%);
  color: #fff;
  padding: 10px 16px 12px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 4px 16px rgba(0, 48, 135, 0.25);
}
.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.nhs-lozenge {
  background: #fff;
  color: var(--nhs-blue);
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: 15px;
  padding: 4px 10px 5px;
  border-radius: 4px 4px 4px 14px;
  flex-shrink: 0;
}
.brand-text { min-width: 0; }
.brand-text strong {
  display: block;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-text span {
  display: block;
  font-size: 11px;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mode-pills {
  display: flex;
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
  padding: 3px;
  flex-shrink: 0;
}
.mode-pills button {
  border: 0;
  background: transparent;
  color: #fff;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
}
.mode-pills button.active { background: #fff; color: var(--nhs-dark); }

.week-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.week-nav h1 {
  flex: 1;
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: rgba(255,255,255,0.14);
  color: #fff;
  display: grid;
  place-items: center;
}
.icon-btn:active { transform: scale(0.96); }
.icon-btn.ghost { background: rgba(255,255,255,0.08); }

.controls {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.controls select, .controls .field {
  flex: 1;
  min-width: 140px;
  background: #fff;
  color: var(--ink);
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
}
.seg {
  display: flex;
  background: rgba(255,255,255,0.14);
  border-radius: 10px;
  padding: 3px;
}
.seg button {
  border: 0;
  background: transparent;
  color: #fff;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 650;
}
.seg button.active { background: #fff; color: var(--nhs-dark); }
.day-head .seg {
  background: #e4ecf5;
  flex-wrap: wrap;
}
.day-head .seg button { color: var(--muted); }
.day-head .seg button.active { background: var(--nhs-blue); color: #fff; }

/* Body */
.main {
  flex: 1;
  padding: 14px 14px calc(88px + var(--safe-bottom));
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

.notice {
  background: #e6f3fb;
  border: 1px solid #b8d4ea;
  color: var(--nhs-dark);
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

.area-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
  scrollbar-width: none;
}
.area-chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.chip.active { background: var(--nhs-blue); color: #fff; border-color: var(--nhs-blue); }
.chip.late.active { background: var(--nhs-warm); border-color: var(--nhs-warm); color: #231f20; }

/* Day cards */
.day-head {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 4px 0 12px;
}
.day-head h2 { margin: 0; font-size: 22px; }
.day-head p { margin: 0; color: var(--muted); font-size: 13px; }
.day-head .seg {
  width: 100%;
  justify-content: space-between;
}
.day-head .seg button { flex: 1; }

.grid {
  display: grid;
  gap: 12px;
}
@media (min-width: 820px) {
  .grid.day { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1100px) {
  .grid.day { grid-template-columns: repeat(3, 1fr); }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card.long-day {
  border-color: var(--nhs-warm-border);
  box-shadow: 0 8px 24px rgba(237, 139, 0, 0.14);
}
.card-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  color: #fff;
  font-weight: 750;
  letter-spacing: 0.02em;
}
.badge {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  background: rgba(255,255,255,0.2);
  padding: 3px 7px;
  border-radius: 999px;
}
.badge.you { background: #fff; color: var(--you); }
.badge.late { background: #231f20; color: #ffd36a; }

.slot {
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 8px;
  padding: 9px 12px;
  border-top: 1px solid var(--line);
  align-items: center;
}
.slot .role { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.slot .who { font-weight: 650; }
.slot.empty .who { color: #8a97a4; font-weight: 500; }
.slot.you {
  background: #e8f7ee;
}
.slot.you .who::after {
  content: "You";
  margin-left: 8px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--you);
  border: 1px solid #9ad6b2;
  background: #fff;
  border-radius: 999px;
  padding: 1px 6px;
  vertical-align: middle;
}

/* Personal summary */
.my-shifts {
  display: grid;
  gap: 10px;
}
.shift {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  gap: 12px;
  align-items: center;
  box-shadow: var(--shadow);
}
.shift.late {
  background: var(--nhs-warm-bg);
  border-color: var(--nhs-warm-border);
}
.shift .when {
  min-width: 62px;
  text-align: center;
}
.shift .when b { display: block; font-size: 18px; }
.shift .when span { font-size: 11px; color: var(--muted); }
.shift .meta { flex: 1; min-width: 0; }
.shift .meta strong { display: block; font-size: 16px; }
.shift .meta span { color: var(--muted); font-size: 13px; }
.off-day {
  color: var(--muted);
  background: #eef2f6;
  box-shadow: none;
}

/* Week table */
.table-wrap {
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
table.rota {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
  font-size: 13px;
}
table.rota th, table.rota td {
  border-bottom: 1px solid var(--line);
  padding: 8px 9px;
  text-align: left;
  vertical-align: top;
}
table.rota thead th {
  background: var(--nhs-dark);
  color: #fff;
  position: sticky;
  top: 0;
  font-weight: 700;
}
table.rota .area-cell {
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
}
table.rota .role-cell {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
  background: #f7fafc;
}
table.rota td.you { background: #e8f7ee; font-weight: 750; }
table.rota td.late-col { background: #fff8eb; }
table.rota td.late-col.you { background: #ffe8b8; }
table.rota tr.late-row td.area-cell { background: var(--nhs-warm); color: #231f20; }

/* Admin */
.admin-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.btn {
  border: 0;
  border-radius: 10px;
  padding: 9px 12px;
  font-weight: 700;
  font-size: 13px;
  background: var(--nhs-blue);
  color: #fff;
}
.btn.secondary { background: #fff; color: var(--nhs-dark); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.edit-cell {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  padding: 4px 2px;
  border-radius: 6px;
}
.edit-cell:focus {
  outline: 2px solid var(--nhs-aqua);
  background: #fff;
  border-color: var(--nhs-aqua);
}

.staff-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-top: 14px;
}
.staff-panel h3 { margin: 0 0 10px; }
.staff-add { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.staff-add input, .staff-add select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  flex: 1;
  min-width: 120px;
}
.staff-list { display: flex; flex-wrap: wrap; gap: 6px; }
.staff-tag {
  background: #eef4fb;
  border-radius: 999px;
  padding: 5px 8px 5px 10px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.staff-tag button {
  border: 0;
  background: transparent;
  color: var(--danger);
  font-weight: 800;
  padding: 0 4px;
}

/* Auth overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 24, 67, 0.55);
  display: grid;
  place-items: center;
  z-index: 80;
  padding: 20px;
}
.modal {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal h2 { margin: 0 0 6px; }
.modal p { margin: 0 0 14px; color: var(--muted); }
.modal input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  margin-bottom: 12px;
}
.hidden { display: none !important; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 36px 16px;
}
.empty h3 { margin: 0 0 6px; color: var(--ink); }

/* Footer */
.footer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 8px 12px calc(8px + var(--safe-bottom));
  display: flex;
  justify-content: space-around;
  z-index: 30;
}
.footer button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 64px;
}
.footer button.active { color: var(--nhs-blue); }
.footer svg { width: 22px; height: 22px; }

@media print {
  .topbar { position: static; }
  .footer, .mode-pills, .admin-bar, .controls .seg, .icon-btn { display: none !important; }
  .main { padding: 0; }
  body { background: #fff; }
}

@media (max-width: 640px) {
  .brand-text strong { font-size: 12px; }
}

@media (min-width: 900px) {
  .footer { display: none; }
  .main { padding-bottom: 28px; }
  .week-nav { max-width: 560px; margin: 10px auto 0; }
}

.header-actions { display: flex; align-items: center; gap: 8px; }
.header-actions .icon-btn { width: auto; padding: 0 10px; font-size: 12px; font-weight: 700; }
.field-label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.field-label input { width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
table.rota td.weekend-col { background: #f3f0fa; }
table.rota td.weekend-col.you { background: #e8f7ee; }
.day-head .seg button { padding: 7px 6px; font-size: 12px; }
.users-table { min-width: 640px; }
.icon-btn.dark { background: #e8eef6; color: var(--nhs-dark); width: 32px; height: 32px; }

.area-edit {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fbfcfe;
}
.area-edit-h {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.area-edit-h .ae-name { flex: 1; min-width: 140px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.ae-color { width: 42px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 2px; }
.chk { font-size: 13px; font-weight: 700; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.role-edit-list { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.role-edit { display: flex; align-items: center; gap: 4px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 4px 4px 4px 10px; }
.role-edit input { border: 0; width: 120px; }
.ghost-x { border: 0; background: transparent; color: var(--danger); font-weight: 800; }

.login-body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 500px at 10% -10%, #0072ce 0%, transparent 50%),
    linear-gradient(180deg, var(--nhs-dark), #001c54 55%, #e8eef8 55%);
}
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(440px, 100%);
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: 0 24px 60px rgba(0, 20, 70, 0.25);
}
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.login-brand strong, .login-brand span { display: block; }
.login-brand span { color: var(--muted); font-size: 13px; }
.login-card h1 { margin: 0 0 6px; }
.login-lead { color: var(--muted); margin: 0 0 18px; }
.login-form label { display: block; font-weight: 700; font-size: 13px; margin-bottom: 12px; }
.login-form input { width: 100%; margin-top: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; }
.login-form .btn { width: 100%; padding: 12px; }
.login-error { background: #fdecea; color: #8a0413; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }

.notices-board {
  margin-bottom: 12px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #fff;
}
.notices-board.sev-info { border-color: #9dc0e0; }
.notices-board.sev-important { border-color: #f3c06a; }
.notices-board.sev-urgent { border-color: #f5a3a0; }
.notices-board.is-new.sev-info { background: #e6f3fb; }
.notices-board.is-new.sev-important {
  background: #fff4e0;
  box-shadow: 0 0 0 2px #ed8b00;
  animation: noticePulse 1.6s ease-in-out 3;
}
.notices-board.is-new.sev-urgent {
  background: #fdecea;
  box-shadow: 0 0 0 2px #da291c;
  animation: noticePulse 1.2s ease-in-out 4;
}
@keyframes noticePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.01); }
}
.notices-toggle {
  width: 100%;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  text-align: left;
}
.notices-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--nhs-blue);
  flex-shrink: 0;
}
.is-new.sev-important .notices-dot { background: #ed8b00; }
.is-new.sev-urgent .notices-dot { background: #da291c; }
.notices-copy { flex: 1; min-width: 0; }
.notices-copy strong, .notices-copy span { display: block; }
.notices-copy span { color: var(--muted); font-size: 13px; }
.notices-chevron { font-size: 12px; font-weight: 800; color: var(--nhs-dark); }
.notices-list { padding: 0 12px 12px; display: grid; gap: 8px; }
.notice-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.notice-card header { display: flex; justify-content: space-between; gap: 8px; }
.notice-card em { font-style: normal; font-size: 11px; font-weight: 800; text-transform: uppercase; color: var(--muted); }
.notice-card p { margin: 6px 0; }
.notice-card small { color: var(--muted); }
.notice-form { display: grid; gap: 8px; margin-bottom: 14px; }
.notice-form textarea, .notice-form input[name="title"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
}
