/* Crew Schedule Portal — styles.
   Phone-first, high contrast (crews check this outdoors, in sunlight),
   generous tap targets, automatic dark mode. No external fonts. */

:root {
  color-scheme: light dark; /* native checkboxes, selects and date pickers follow the theme */
  --bg: #f2f5f1;
  --surface: #ffffff;
  --surface-2: #eaefe9;
  --ink: #17241d;
  --muted: #55665c;
  --line: #d8e0d7;
  --accent: #1c714a;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1e8;
  --today: #1c714a;
  --warn-bg: #fdf0cf;
  --warn-ink: #6d5200;
  --error-bg: #fbe2e0;
  --error-ink: #8c1d16;
  --chip-bg: #e7eee7;
  --shadow: 0 1px 2px rgba(23, 36, 29, 0.06), 0 4px 14px rgba(23, 36, 29, 0.06);
  --radius: 14px;
  --radius-sm: 9px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141b17;
    --surface: #1c2620;
    --surface-2: #222e27;
    --ink: #e9f1ea;
    --muted: #a3b5a9;
    --line: #2d3a32;
    --accent: #57c68f;
    --accent-ink: #0c1f16;
    --accent-soft: #1d3a2b;
    --today: #57c68f;
    --warn-bg: #3a3010;
    --warn-ink: #eed48a;
    --error-bg: #43201d;
    --error-ink: #f3b3ac;
    --chip-bg: #263229;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

button:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

a { color: var(--accent); }

/* ---------- Header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo { width: 34px; height: 34px; flex: none; }
.logo-bg { fill: var(--accent); }
.logo-tree { fill: var(--accent-ink); }

.brand h1 {
  font-size: 19px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-badges { display: flex; gap: 6px; flex: none; }

.badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-demo {
  color: var(--warn-ink);
  background: var(--warn-bg);
  border-color: transparent;
}

/* Narrow phones: stack the badges so the title never truncates. */
@media (max-width: 480px) {
  .brand h1 { font-size: 18px; }
  .brand-badges { flex-direction: column; align-items: flex-end; gap: 3px; }
  .badge { font-size: 11px; padding: 2px 8px; }
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.views {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}

.view-btn {
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--muted);
  min-height: 38px;
}

.view-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

.nav { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--ink);
}

.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--surface-2); }

.today-btn {
  padding: 8px 14px;
  min-height: 42px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 14.5px;
  font-weight: 600;
}

.today-btn:hover { background: var(--surface-2); }

.range-label {
  margin: 0;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.banner[hidden] { display: none; }

.banner {
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner.error { background: var(--error-bg); color: var(--error-ink); }

.banner button {
  font-weight: 700;
  text-decoration: underline;
  color: inherit;
  flex: none;
}

/* ---------- Main ---------- */

.main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 14px 28px;
}

/* Full-screen states (loading / not connected / can't reach) */

.screen {
  min-height: 55vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 430px;
  padding: 28px 24px;
  text-align: center;
}

.screen-card .screen-icon { font-size: 40px; line-height: 1; }
.screen-card h3 { margin: 12px 0 6px; font-size: 19px; }
.screen-card p { margin: 0; color: var(--muted); font-size: 15px; }
.screen-card p + p { margin-top: 10px; }

.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto;
  border-radius: 50%;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.5s; }
  * { scroll-behavior: auto !important; }
}

/* ---------- Event cards (week + day views) ---------- */

.event-card {
  width: 100%;
  display: flex;
  align-items: stretch;
  gap: 12px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.event-card:hover { border-color: var(--accent); }

.event-card.all-day {
  border-left-color: transparent;
  background: var(--accent-soft);
  border-color: transparent;
}

.event-when {
  flex: none;
  width: 74px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 13.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.event-when .t2 { color: var(--muted); font-weight: 500; }
.event-when .all-day-label { font-weight: 650; color: var(--accent); }
.event-card.all-day .event-when .all-day-label { color: inherit; }

.event-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }

.event-title {
  font-size: 15.5px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.event-loc {
  font-size: 13.5px;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 5px;
  overflow-wrap: anywhere;
}

.event-loc svg { width: 12px; height: 12px; flex: none; align-self: center; }

.event-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 3px; }

.tag {
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2.5px 9px;
}

.tag-instr {
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tag-instr svg { width: 11px; height: 11px; }
.tag-moved { background: var(--warn-bg); color: var(--warn-ink); }
.tag-cont { background: var(--chip-bg); color: var(--muted); }

/* ---------- Week view ---------- */

.week { display: flex; flex-direction: column; gap: 12px; }

.day-section {
  background: transparent;
  border-radius: var(--radius);
}

.day-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 2px 6px;
}

.day-head .day-name {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.day-head .day-num {
  font-size: 15px;
  font-weight: 700;
  min-width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.is-today .day-head .day-num { background: var(--today); color: var(--accent-ink); }
.is-today .day-head .day-name { color: var(--today); }

.today-pill {
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--today);
}

.day-events { display: flex; flex-direction: column; gap: 8px; }

.no-events {
  margin: 0;
  padding: 9px 12px;
  color: var(--muted);
  font-size: 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

/* Week on wide screens: 7 columns */

@media (min-width: 920px) {
  .week {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 10px;
    align-items: start;
  }
  .week .event-when { width: auto; flex-direction: row; gap: 5px; flex-wrap: wrap; }
  .week .event-card { flex-direction: column; gap: 6px; padding: 9px 10px; border-left-width: 4px; }
  .week .event-title { font-size: 14px; }
  .week .no-events { font-size: 13px; padding: 8px 10px; }
}

/* ---------- Month view ---------- */

.month {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.month-grid-head {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.month-grid-head span {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 7px 0;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.month-cell {
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  min-height: 86px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
  min-width: 0;
}

.month-grid .month-cell:nth-child(-n+7) { border-top: none; }
.month-grid .month-cell:nth-child(7n+1) { border-left: none; }

.month-cell:hover { background: var(--surface-2); }
.month-cell.other-month { background: color-mix(in srgb, var(--surface-2) 45%, var(--surface)); }
.month-cell.other-month .cell-date { color: var(--muted); opacity: 0.6; }

.cell-date {
  font-size: 13px;
  font-weight: 700;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex: none;
}

.month-cell.is-today .cell-date { background: var(--today); color: var(--accent-ink); }

.cell-events { display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--chip-bg);
  border-radius: 6px;
  padding: 2.5px 5px;
  text-align: left;
  min-width: 0;
}

.chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

.chip.all-day { background: var(--accent-soft); }

.chip .chip-time { color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.chip .chip-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.chip-more {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  text-align: left;
  padding: 1px 5px;
}

@media (max-width: 560px) {
  .month-cell { min-height: 72px; padding: 3px; }
  .chip .chip-time { display: none; }
}

/* ---------- Day view ---------- */

.day-view { display: flex; flex-direction: column; gap: 10px; max-width: 640px; margin: 0 auto; }

.day-view .event-card { padding: 13px 14px; }

.event-desc-preview {
  font-size: 13.5px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- Footer status bar ---------- */

.statusbar {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 14px calc(6px + env(safe-area-inset-bottom, 0px));
  font-size: 13px;
  color: var(--muted);
}

.statusbar-actions { display: flex; align-items: center; gap: 4px; }
.statusbar-actions form { margin: 0; }

.status-link {
  font-size: 13.5px;
  font-weight: 650;
  color: var(--accent);
  text-decoration: none;
  padding: 8px 8px;
  border-radius: 8px;
  white-space: nowrap;
}

.status-link[hidden] { display: none; }
.status-link:hover { background: var(--surface-2); }

.statusbar .icon-btn { width: 38px; height: 38px; }
.statusbar .icon-btn svg { width: 19px; height: 19px; }
.statusbar .icon-btn.spinning svg { animation: spin 0.9s linear infinite; }

/* ---------- Event dialog ---------- */

.event-dialog {
  border: none;
  padding: 0;
  background: transparent;
  width: min(560px, calc(100vw - 24px));
  max-height: 86dvh;
}

.event-dialog::backdrop { background: rgba(10, 18, 13, 0.55); }

.dlg-card {
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  overflow: auto;
  max-height: 86dvh;
}

.dlg-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 0;
}

.dlg-head h3 { margin: 0; font-size: 19px; line-height: 1.3; overflow-wrap: anywhere; }

.dlg-body { padding: 10px 16px 18px; display: flex; flex-direction: column; gap: 12px; }

.dlg-row { display: flex; gap: 10px; align-items: baseline; font-size: 15px; }
.dlg-row svg { width: 15px; height: 15px; flex: none; align-self: center; color: var(--muted); }
.dlg-row .dlg-text { min-width: 0; overflow-wrap: anywhere; }
.dlg-row .sub { color: var(--muted); font-size: 13.5px; }

.dlg-desc {
  white-space: pre-wrap;
  font-size: 14.5px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  overflow-wrap: anywhere;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 15px;
  border-radius: 999px;
  padding: 11px 18px;
  text-decoration: none;
}

.btn-primary svg { width: 15px; height: 15px; }

/* Bottom-sheet feel on phones */
@media (max-width: 560px) {
  .event-dialog {
    width: 100vw;
    max-width: 100vw;
    margin: 0;
    position: fixed;
    inset: auto 0 0 0;
    max-height: 88dvh;
  }
  .dlg-card {
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* ---------- Misc ---------- */

.noscript {
  margin: 40px auto;
  max-width: 420px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  font-weight: 600;
}

/* ---------- Sign-in page ---------- */

.login-body {
  align-items: center;
  justify-content: center;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px));
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-brand { justify-content: center; }
.login-brand h1 { white-space: normal; text-align: center; }

.login-form { display: flex; flex-direction: column; gap: 14px; }

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 14px;
  font-weight: 650;
  color: var(--muted);
}

.login-form input {
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  min-height: 46px;
}

.login-form input:focus {
  outline: 3px solid var(--accent-soft);
  border-color: var(--accent);
}

.login-form .primary-btn {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 16px;
  border-radius: 999px;
  min-height: 48px;
  margin-top: 4px;
}

.login-form :disabled { opacity: 0.55; cursor: not-allowed; }

.login-msg {
  margin: 0;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14.5px;
  font-weight: 500;
}

.login-msg.error, .login-msg.setup { background: var(--error-bg); color: var(--error-ink); }
.login-msg.info { background: var(--accent-soft); color: var(--ink); }

.login-foot { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }
