* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --brand-red: #b3261e;
  --brand-red-dark: #8f1d18;
  --brand-ink: #24272c;
  --brand-amber: #f0a202;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f1f3f5;
  --line: #d9dde3;
  --text: #2f3136;
  --muted: #6f7782;
  --success-bg: #e7f3ed;
  --success: #146c43;
  --danger-bg: #fde8e6;
  --danger: #b3261e;
  --warning-bg: #fff4d6;
  --warning: #9a5b00;
  --shadow-sm: 0 1px 3px rgba(20, 24, 31, 0.08);
  --shadow-md: 0 2px 8px rgba(20, 24, 31, 0.16);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 2rem;
}

header {
  background: linear-gradient(180deg, #3a3f45 0%, #2c3034 100%);
  color: var(--surface);
  padding: 0.85rem 1rem;
  border-bottom: 4px solid var(--brand-red);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 600px;
  margin: 0 auto;
}

.brand-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  flex-shrink: 0;
  /* logo.png is black/white line-art with no background; on the dark ink
     header the white linework reads as an etched emblem. A soft red glow
     ties it to the brand red. */
  filter: drop-shadow(0 0 4px rgba(179, 38, 30, 0.55));
}

header h1 {
  font-size: 1.4rem;
  margin-bottom: 0.2rem;
}

.subtitle {
  font-size: 0.85rem;
  opacity: 0.85;
}

.hidden {
  display: none !important;
}

.offline-banner {
  background: var(--warning-bg);
  color: var(--warning);
  border-bottom: 1px solid var(--brand-amber);
  text-align: center;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
}

.user-chip {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.user-chip span {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
}

.profile-photo {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-muted);
  flex-shrink: 0;
}

.profile-photo.large {
  width: 72px;
  height: 72px;
  margin: 0 auto 0.8rem;
}

.auth-gate {
  max-width: 600px;
  margin: 0 auto;
  padding: 1rem;
}

.auth-panel {
  background: var(--surface);
  border-radius: 8px;
  padding: 1.2rem;
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.auth-panel h2 {
  font-size: 1.1rem;
  margin-bottom: 0.45rem;
}

.auth-panel p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.auth-button {
  display: inline-block;
  text-decoration: none;
}

.auth-fineprint {
  margin-top: 1rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.auth-fineprint a {
  color: var(--brand-red);
}

.legal-links {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
}

.legal-links a {
  color: var(--muted);
  text-decoration: none;
}

.legal-links a:hover {
  color: var(--brand-red);
  text-decoration: underline;
}

.legal-links span {
  margin: 0 0.4rem;
  opacity: 0.6;
}

.auth-error {
  margin-top: 1rem;
  color: var(--danger) !important;
  margin-bottom: 0 !important;
}

nav {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.tab {
  flex: 1;
  padding: 0.75rem 0.5rem;
  border: none;
  background: none;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}

.tab.active {
  color: var(--brand-red);
  border-bottom-color: var(--brand-red);
}

main {
  max-width: 600px;
  margin: 0 auto;
  padding: 1rem;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* View toggle */
.view-toggle {
  display: flex;
  background: #eceff3;
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 0.8rem;
}

.view-btn {
  flex: 1;
  padding: 0.5rem;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
}

.view-btn.active {
  background: var(--surface);
  color: var(--brand-red);
  box-shadow: var(--shadow-sm);
}

/* Date navigation */
.date-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 1rem;
}

.date-nav button {
  background: var(--brand-red);
  color: var(--surface);
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1.2rem;
  cursor: pointer;
}

#period-label {
  font-size: 0.95rem;
  font-weight: 500;
  min-width: 160px;
  text-align: center;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

/* Week view */
.week-grid {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.week-day {
  background: var(--surface);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  box-shadow: var(--shadow-sm);
}

.week-day.today {
  border-left: 3px solid var(--brand-red);
}

.week-day.weekend {
  background: var(--surface-muted);
}

.week-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
}

.week-day-name {
  font-weight: 600;
  font-size: 0.85rem;
}

.week-day-date {
  font-size: 0.75rem;
  color: var(--muted);
}

.week-day-count {
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--surface-muted);
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
}

/* Month view */
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.month-header-cell {
  text-align: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0.3rem 0;
}

.month-cell {
  background: var(--surface);
  border-radius: 4px;
  min-height: 60px;
  padding: 0.25rem;
  box-shadow: 0 1px 2px rgba(20, 24, 31, 0.06);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
}

.month-cell .badges-short {
  display: flex;
}

.month-cell .badges-full {
  display: none;
}

.month-cell.expanded {
  grid-column: 1 / -1;
  min-height: auto;
  padding: 0.5rem;
  box-shadow: var(--shadow-md);
  z-index: 5;
  position: relative;
}

.month-cell.expanded .badges-short {
  display: none;
}

.month-cell.expanded .badges-full {
  display: flex;
}

.month-cell.expanded .badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.45rem;
}

.month-cell.today {
  box-shadow: inset 0 0 0 2px var(--brand-red);
}

.month-cell.outside {
  background: var(--surface-muted);
  opacity: 0.5;
}

.month-cell.weekend {
  background: var(--surface-muted);
}

.month-day-num {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.2rem;
}

/* Badges */
.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.badge {
  display: inline-block;
  font-size: 0.6rem;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-weight: 500;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge.away {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge.available {
  background: var(--success-bg);
  color: var(--success);
}

/* Week badges are slightly larger */
.week-day .badges {
  gap: 4px;
}

.week-day .badge {
  font-size: 0.72rem;
  padding: 0.2rem 0.45rem;
}

/* Forms */
.form-group {
  margin-bottom: 0.8rem;
}

.form-group.inline {
  display: flex;
  gap: 0.5rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

input[type="text"],
input[type="date"],
select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.95rem;
  background: var(--surface);
}

.form-group.inline input {
  flex: 1;
}

.btn-primary {
  background: var(--brand-red);
  color: var(--surface);
  border: none;
  padding: 0.65rem 1.2rem;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--brand-red-dark);
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface-muted);
  color: var(--brand-ink);
  border: 1px solid var(--line);
  padding: 0.55rem 0.9rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-danger {
  background: var(--brand-ink);
  color: var(--surface);
  border: none;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
}

/* Cards */
h3 {
  margin: 1.5rem 0 0.8rem;
  font-size: 1rem;
  color: var(--text);
}

.card {
  background: var(--surface);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  margin-bottom: 0.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.card-main {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.card .name {
  font-weight: 500;
}

.card .detail {
  font-size: 0.8rem;
  color: var(--muted);
}

.role-pill {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--brand-red);
  background: #f7d9d6;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  margin-left: 0.35rem;
}

.admin-panel {
  margin-top: 1rem;
}

/* Availability */
.person-status {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  box-shadow: var(--shadow-sm);
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.available {
  background: var(--success);
}

.status-dot.away {
  background: var(--danger);
}

.person-info {
  flex: 1;
}

.person-info .name {
  font-weight: 500;
  font-size: 0.95rem;
}

.person-info .note {
  font-size: 0.75rem;
  color: var(--muted);
}

.summary-bar {
  background: var(--surface);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  text-align: center;
  font-size: 0.9rem;
}

.summary-bar strong {
  color: var(--brand-red);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
  font-size: 0.9rem;
}

/* Range Picker */
.picker-instruction {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--brand-red);
  margin-bottom: 0.5rem;
  min-height: 1.2em;
}

.range-picker {
  background: var(--surface);
  border-radius: 10px;
  padding: 0.8rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
}

.picker-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.picker-nav button {
  background: var(--brand-red);
  color: var(--surface);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1rem;
  cursor: pointer;
}

#picker-month-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  text-align: center;
}

.picker-header-cell {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0.3rem 0;
}

.picker-cell {
  position: relative;
  padding: 0.55rem 0.2rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}

.picker-cell:active {
  transform: scale(0.92);
}

.picker-cell.outside {
  color: #aeb4bc;
}

.picker-cell.today {
  font-weight: 700;
}

.picker-cell.self-booked {
  background: var(--danger-bg);
  color: var(--danger);
  text-decoration: line-through;
}

.picker-cell.range-start,
.picker-cell.range-end {
  background: var(--brand-red);
  color: var(--surface);
  font-weight: 600;
}

.picker-cell.range-mid {
  background: #f7d9d6;
  color: var(--brand-red);
}

.picker-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--brand-amber);
  color: var(--brand-ink);
  font-size: 0.55rem;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

/* Warning styles */
.warning-bar {
  background: var(--warning-bg);
  border: 1px solid var(--brand-amber);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  margin-bottom: 0.6rem;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--warning);
}

.week-day.warning {
  border-left: 3px solid var(--brand-amber);
  background: var(--warning-bg);
}

.month-cell.warning {
  background: var(--warning-bg);
  box-shadow: inset 0 0 0 2px var(--brand-amber);
}

.count-warning {
  background: var(--warning-bg) !important;
  color: var(--warning) !important;
  font-weight: 600;
}

/* ============================================================
   First-landing CRT / matrix splash
   ============================================================ */
.splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  /* default state: tube is on. .powering-off collapses it. */
}

/* CRT cathode power-off: collapse vertically to a line, then to a dot. */
.splash.powering-off {
  animation: crt-power-off 0.55s steps(1, end) forwards;
}

@keyframes crt-power-off {
  0% {
    transform: scaleY(1) scaleX(1);
    filter: brightness(1);
  }
  55% {
    transform: scaleY(0.006) scaleX(1.06);
    filter: brightness(3);
  }
  80% {
    transform: scaleY(0.006) scaleX(0.0008);
    filter: brightness(5);
  }
  100% {
    transform: scaleY(0.006) scaleX(0);
    filter: brightness(8);
    opacity: 0;
  }
}

/* CRT cathode power-on: a scanline opens up vertically. */
.splash.powering-on {
  animation: crt-power-on 0.5s ease-out;
}

/* Power-on is a brightness flash only — the overlay must stay full-screen so
   the app behind is never revealed before the splash. (Collapsing the whole
   overlay with scaleY here showed the page for a beat.) */
@keyframes crt-power-on {
  0% {
    filter: brightness(8) contrast(1.6);
  }
  12% {
    filter: brightness(1.3) contrast(1.1);
  }
  100% {
    filter: brightness(1) contrast(1);
  }
}

.splash-matrix {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.splash-stage {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.splash-logo {
  width: min(62vw, 320px);
  height: auto;
  opacity: 0;
  /* reveal: flicker in like a tube warming up, with chromatic aberration */
  animation: logo-reveal 1.6s ease-out 1s forwards;
  filter: drop-shadow(0 0 18px rgba(240, 80, 20, 0.55));
  will-change: opacity, filter, transform;
}

@keyframes logo-reveal {
  0%   { opacity: 0; filter: brightness(4) blur(3px); transform: scale(1.04); }
  8%   { opacity: 1; }
  10%  { opacity: 0.2; }
  14%  { opacity: 1; }
  18%  { opacity: 0.4; }
  22%  { opacity: 1; filter: brightness(1.4) blur(0); transform: scale(1); }
  100% { opacity: 1; filter: brightness(1) drop-shadow(0 0 18px rgba(240, 80, 20, 0.55)); transform: scale(1); }
}

/* Static CRT scanline overlay */
.splash-scanlines {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.28) 3px,
    rgba(0, 0, 0, 0.28) 4px
  );
  mix-blend-mode: multiply;
  opacity: 0.7;
}

/* Rolling brightness flicker + moving scan band */
.splash-flicker {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.04) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  animation: scan-roll 5s linear infinite, tube-flicker 0.12s steps(2, end) infinite;
}

@keyframes scan-roll {
  0%   { transform: translateY(-100%); }
  100% { transform: translateY(100%); }
}

@keyframes tube-flicker {
  0%   { opacity: 0.9; }
  100% { opacity: 1; }
}

.splash-skip {
  position: absolute;
  z-index: 5;
  bottom: 1.4rem;
  right: 1.4rem;
  background: rgba(0, 0, 0, 0.4);
  color: #ff7a5a;
  border: 1px solid rgba(227, 39, 28, 0.6);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  text-shadow: 0 0 6px rgba(255, 80, 60, 0.7);
}

@media (prefers-reduced-motion: reduce) {
  .splash-logo { animation: none; opacity: 1; }
  .splash.powering-on,
  .splash.powering-off { animation-duration: 0.25s; }
  .splash-flicker { animation: none; }
}

@media (max-width: 480px) {
  .brand-lockup {
    flex-wrap: wrap;
  }

  .user-chip {
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
  }

  .user-chip span {
    max-width: calc(100vw - 150px);
  }

  .card {
    align-items: flex-start;
    flex-direction: column;
  }

  .card-actions {
    width: 100%;
    justify-content: flex-start;
  }
}
