:root {
  color-scheme: light;
  --navy: #07243b;
  --blue: #0868a8;
  --blue-2: #0b83c6;
  --sky: #eaf6fc;
  --ink: #102636;
  --muted: #627583;
  --line: #dbe5eb;
  --surface: #ffffff;
  --canvas: #f4f8fa;
  --green: #168057;
  --green-soft: #e7f5ee;
  --amber: #a85f09;
  --amber-soft: #fff3dc;
  --red: #c84038;
  --red-soft: #fff0ee;
  --yellow: #9d7100;
  --yellow-soft: #fff7d8;
  --shadow: 0 12px 36px rgba(25, 55, 72, .08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); min-height: 100vh; font-size: 16px; line-height: 1.5; }
button, input, select { font: inherit; }
a { color: inherit; }

.shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 24px 0 56px; transform-origin: top center; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; min-width: 0; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; flex: 0 0 42px; border-radius: 13px; color: #fff; background: linear-gradient(145deg, var(--blue-2), var(--navy)); box-shadow: 0 8px 20px rgba(8,104,168,.22); }
.brand-mark svg { width: 24px; height: 24px; }
.brand-copy { min-width: 0; }
.brand-name { display: block; font-size: 1rem; font-weight: 780; letter-spacing: -.02em; white-space: nowrap; }
.brand-sub { display: block; color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; align-items: center; flex-wrap: wrap; max-width: 100%; gap: 6px; padding: 5px; border: 1px solid var(--line); background: rgba(255,255,255,.78); border-radius: 13px; }
.nav a { display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 8px 12px; color: var(--muted); text-decoration: none; font-size: .88rem; font-weight: 650; border-radius: 9px; }
.nav a:hover, .nav a.active { color: var(--blue); background: var(--sky); }
.nav svg { width: 17px; height: 17px; }

.hero { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 24px; margin: 0 0 20px; }
.eyebrow { margin: 0 0 6px; color: var(--blue); font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1 { margin: 0; color: var(--navy); font-size: clamp(1.65rem, 4vw, 2.5rem); line-height: 1.1; letter-spacing: -.04em; }
.lede { max-width: 660px; margin: 10px 0 0; color: var(--muted); font-size: .98rem; }
.updated { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .82rem; white-space: nowrap; }
.updated::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }

.grid { display: grid; grid-template-columns: minmax(250px, .76fr) minmax(0, 1.6fr); gap: 18px; align-items: stretch; }
.stack { display: grid; gap: 18px; }
#details { display: flex; min-width: 0; }
#details > .calendar-card { display: flex; flex: 1; flex-direction: column; min-height: 100%; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; }
.card-title, h2 { margin: 0; color: var(--navy); font-size: 1.02rem; line-height: 1.25; letter-spacing: -.015em; }
.card-kicker { margin: 4px 0 0; color: var(--muted); font-size: .82rem; }
label { display: block; margin: 0 0 7px; color: var(--muted); font-size: .82rem; font-weight: 680; }
select, input[type="password"], input[type="file"] { width: 100%; min-height: 48px; padding: 11px 13px; color: var(--ink); background: #fff; border: 1px solid #cbd9e1; border-radius: 12px; outline: none; }
select:focus, input:focus { border-color: var(--blue-2); box-shadow: 0 0 0 4px rgba(11,131,198,.12); }
.select-help, .hint { margin: 10px 0 0; color: var(--muted); font-size: .79rem; line-height: 1.5; }

.status-card { position: relative; overflow: hidden; background: linear-gradient(135deg, #fff 48%, var(--sky)); }
.status-card::after { content: ""; position: absolute; top: -55px; right: -55px; width: 150px; height: 150px; border-radius: 50%; border: 26px solid rgba(11,131,198,.06); pointer-events: none; }
.status-card .rotations-block { position: relative; z-index: 1; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.status-card .rotations-block .card-head { margin-bottom: 10px; }
.status-badge { display: inline-flex; align-items: center; gap: 8px; padding: 7px 11px; margin-bottom: 14px; border-radius: 999px; font-size: .79rem; font-weight: 800; letter-spacing: .02em; }
.status-badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-badge.onboard { color: var(--green); background: var(--green-soft); }
.status-badge.home { color: var(--amber); background: var(--amber-soft); }
.key-date { margin: 2px 0 16px; color: var(--navy); font-size: clamp(1.18rem, 3vw, 1.65rem); font-weight: 800; letter-spacing: -.035em; }
.rows { display: grid; gap: 0; }
.data-row { display: flex; justify-content: space-between; align-items: baseline; gap: 18px; padding: 11px 0; border-top: 1px solid var(--line); }
.data-row .key { color: var(--muted); font-size: .85rem; }
.data-row .value { color: var(--ink); font-weight: 700; text-align: right; font-size: .9rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 11px 9px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
.empty, .error-state, .loading-state { padding: 28px 18px; color: var(--muted); text-align: center; background: var(--surface); border: 1px dashed #c8d8e1; border-radius: 15px; }
.error-state { color: var(--red); background: var(--red-soft); border-color: #f2c5c1; }

.calendar-card { padding: 22px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 0 0 14px; color: var(--muted); font-size: .75rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.months { display: grid; flex: 1; grid-template-columns: repeat(2, minmax(0,1fr)); grid-template-rows: minmax(0,1fr) minmax(0,1fr); gap: 18px 24px; }
.months > div { display: flex; min-height: 0; flex-direction: column; }
.months > div:first-child { grid-column: 1 / -1; width: calc(50% - 12px); justify-self: center; }
.month-title { margin: 4px 0 9px; color: var(--navy); font-size: .86rem; font-weight: 800; text-align: center; }
.weekdays, .days { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); gap: 3px; }
.months .days { flex: 1; grid-auto-rows: minmax(28px,1fr); }
.weekdays { margin-bottom: 4px; }
.weekdays div { color: var(--muted); text-align: center; font-size: .64rem; font-weight: 760; text-transform: uppercase; }
.day { position: relative; display: grid; place-items: center; min-width: 0; min-height: 28px; overflow: hidden; border-radius: 8px; font-size: .78rem; }
.day.blank { visibility: hidden; }
.day.past { color: #91a0aa; }
.day.onboard { color: var(--green); background: var(--green-soft); font-weight: 800; }
.day.vacation { color: var(--yellow); background: var(--yellow-soft); font-weight: 800; }
.day.today { outline: 2px solid var(--blue-2); outline-offset: -2px; }
.portbar { position: absolute; left: 3px; right: 3px; bottom: 3px; height: 4px; border-radius: 4px; }
.vac-label { display: none; }

.footer { display: flex; justify-content: space-between; gap: 16px; margin-top: 24px; padding: 0 4px; color: var(--muted); font-size: .76rem; }
.footer a { color: var(--blue); text-decoration: none; font-weight: 700; }

.timetable { overflow: hidden; padding: 0; }
.tt-head, .tt-row { display: grid; grid-template-columns: 92px 1fr 1fr; }
.tt-head { position: sticky; top: 0; z-index: 2; color: #fff; background: var(--navy); }
.tt-head > div { padding: 13px 14px; font-size: .72rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.tt-head .port { border-left: 1px solid rgba(255,255,255,.18); }
.scale { display: flex; justify-content: space-between; margin-top: 5px; opacity: .62; font-size: .6rem; font-weight: 500; }
.tt-month { padding: 11px 14px; color: var(--navy); background: var(--sky); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: .82rem; font-weight: 800; }
.tt-row { min-height: 52px; border-bottom: 1px solid var(--line); }
.tt-row:last-child { border-bottom: 0; }
.tt-row.weekend { background: #f9fbfc; }
.tt-row.today { box-shadow: inset 4px 0 var(--blue-2); background: #f1f9fd; }
.tt-date { display: flex; align-items: center; gap: 8px; padding: 8px 14px; font-size: .82rem; font-weight: 700; }
.tt-date small { color: var(--muted); font-size: .65rem; text-transform: uppercase; }
.port-cell { display: flex; flex-direction: column; justify-content: center; gap: 6px; padding: 7px 14px; border-left: 1px solid var(--line); }
.hours { color: var(--navy); font-size: .78rem; font-variant-numeric: tabular-nums; font-weight: 760; }
.track { position: relative; height: 5px; border-radius: 4px; background: #e8eef2; overflow: hidden; }
.bar { position: absolute; top: 0; height: 100%; border-radius: 4px; }
.port-cell.v .bar { background: var(--green); }
.port-cell.n .bar { background: var(--red); }

.admin-layout { display: grid; grid-template-columns: minmax(230px,.72fr) minmax(0,1.55fr); gap: 18px; align-items: start; }
.admin-intro { position: sticky; top: 20px; color: #fff; background: linear-gradient(145deg, var(--navy), #0a557f); border: 0; }
.admin-intro h2 { color: #fff; font-size: 1.28rem; }
.admin-intro p { color: rgba(255,255,255,.72); font-size: .88rem; }
.admin-intro .mini { display: grid; gap: 10px; margin-top: 22px; }
.admin-intro .mini span { display: flex; align-items: center; gap: 9px; font-size: .81rem; }
.admin-intro .mini i { width: 7px; height: 7px; border-radius: 50%; background: #6ee7b7; }
.upload-zone { padding: 16px; margin: 14px 0; background: var(--canvas); border: 1px dashed #b9cdd8; border-radius: 13px; }
.button { display: inline-flex; align-items: center; justify-content: center; width: 100%; min-height: 47px; padding: 11px 16px; color: #fff; background: var(--blue); border: 0; border-radius: 12px; cursor: pointer; font-weight: 760; }
.button:hover { background: var(--blue-2); }
.button:disabled { opacity: .58; cursor: wait; }
.button.secondary { margin-top: 8px; color: var(--muted); background: transparent; border: 1px solid var(--line); }
.message { margin: 0 0 14px; padding: 11px 13px; border-radius: 11px; font-size: .85rem; }
.message.ok { color: var(--green); background: var(--green-soft); }
.message.err { color: var(--red); background: var(--red-soft); }

/* Full-width port indicators and month navigation. */
.calendar-card .portbar {
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 9px;
  border-radius: 0;
  transform: none;
}
.calendar-card .day { padding-bottom: 9px; }
.calendar-navigation {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.calendar-navigation button {
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--navy);
  background: var(--surface);
  font-size: .78rem;
  cursor: pointer;
}
.calendar-navigation button:hover { background: var(--sky); }
.calendar-navigation button:focus-visible { outline: 2px solid var(--blue-2); outline-offset: 2px; }

.calendar-card > .legend { justify-content: center; margin: 14px 0 0; }

/* Desktop: classic grid with one large month above two smaller months. */
@media (min-width: 821px) {
  .months {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: minmax(min-content, 1.7fr) minmax(min-content, 1fr);
    gap: 16px;
  }
  .months > div {
    padding: 0;
    border: 0;
    background: var(--surface);
  }
  .months > div:first-child {
    grid-column: 1 / -1;
    grid-row: 1;
    width: 100%;
    justify-self: stretch;
    align-self: stretch;
  }
  .months > div:nth-child(2) { grid-column: 1; grid-row: 2; }
  .months > div:nth-child(3) { grid-column: 2; grid-row: 2; }
  .months .month-title { margin: 2px 0 8px; text-align: left; }
  .months > div:first-child .month-title { font-size: 1.125rem; }
  .months .weekdays { gap: 1px; margin-bottom: 5px; }
  .months .weekdays div { text-align: left; padding-left: 6px; }
  .months .days {
    gap: 1px;
    grid-template-rows: repeat(var(--week-count, 5), minmax(32px, 1fr));
    grid-auto-rows: minmax(32px, 1fr);
    background: var(--line);
    border: 1px solid var(--line);
  }
  .months .day {
    min-height: 32px;
    padding: 3px 6px 12px;
    place-items: start;
    border: 0;
    border-radius: 0;
    background: var(--surface);
    font-size: .75rem;
  }
  .months .day.onboard { background: var(--green-soft); }
  .months .day.vacation { background: var(--yellow-soft); }
  .months .day.blank { visibility: visible; background: var(--canvas); }
  .months > div:first-child .day {
    aspect-ratio: 1.25;
    min-height: 48px;
    padding: 8px 10px 14px;
    font-size: 1.15rem;
  }
  .months > div:first-child .month-title { font-size: 1.3rem; margin-bottom: 12px; }
}

@media (max-width: 820px) {
  .topbar { align-items: flex-start; }
  .nav span { display: none; }
  .nav a { padding: 9px; }
  .hero { grid-template-columns: 1fr; gap: 10px; }
  .grid, .admin-layout { grid-template-columns: 1fr; }
  #details { display: block; }
  #details > .calendar-card { display: block; height: auto; min-height: 0; }
  .admin-intro { position: static; }
  .months { grid-template-columns: 1fr; grid-template-rows: none; gap: 24px; }
  .months > div { display: block; }
  .months > div:first-child { grid-column: auto; }
  .months > div:first-child { width: auto; justify-self: stretch; }
  .months .days { grid-auto-rows: auto; }
  .day { min-height: 0; aspect-ratio: 1; font-size: .85rem; }
}

@media (max-width: 540px) {
  .shell { width: min(100% - 20px, 1120px); padding-top: 14px; }
  .brand-sub { display: none; }
  .brand-mark { width: 38px; height: 38px; flex-basis: 38px; }
  .card { padding: 18px; border-radius: 15px; }
  .tt-head, .tt-row { grid-template-columns: 64px 1fr 1fr; }
  .tt-head > div, .tt-date, .port-cell { padding-left: 8px; padding-right: 8px; }
  .hours { font-size: .68rem; }
  .footer { flex-direction: column; }
}

@media (prefers-reduced-motion: no-preference) {
  .card { animation: rise .35s ease both; }
  @keyframes rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
}

/* Keep crew identity within a constant-height slot. */
.selected-crew-name {
  color: #c02828;
  text-align: center;
  font-weight: 800;
  line-height: 26px;
  height: 26px;
  margin: 0 0 16px;
  position: relative;
  z-index: 1;
  white-space: nowrap;
}
.selected-crew-name > span { display: inline-block; font-size: 18.4px; }
@media (min-width: 821px) {
  .shell > .grid > .stack { grid-template-rows: 1fr auto; }
  .shell > .grid > .stack > #summary { order: -1; }
  #summary > .card { height: 100%; }
  #summary .table-wrap { overflow: visible; }
  #summary td { white-space: nowrap; }
  #summary .card, #details > .calendar-card { animation: none; }
}

/* A more legible desktop layout without shrinking each person's content. */
@media (min-width: 821px) {
  .crew-page .shell { padding-top: 12px; padding-bottom: 12px; }
  .crew-page .topbar { margin-bottom: 16px; }
  .crew-page .hero { margin-bottom: 14px; }
  .crew-page .footer { margin-top: 14px; font-size: .88rem; }
  .crew-page .card { padding: 18px; }
  .crew-page .card-kicker, .crew-page label { font-size: .94rem; }
  .crew-page .data-row .key, .crew-page .data-row .value { font-size: 1rem; }
  .crew-page #summary table { font-size: .98rem; }
  .crew-page #summary th { font-size: .82rem; letter-spacing: .025em; }
  .crew-page #summary td, .crew-page #summary th { padding: 10px 6px; }
  .crew-page .status-badge { font-size: .95rem; }
  .crew-page .selected-crew-name { height: 30px; line-height: 30px; }
  .crew-page .calendar-navigation button { font-size: .95rem; }
  .crew-page .legend { font-size: .88rem; }
  .crew-page .months { grid-template-rows: minmax(min-content, 1.5fr) minmax(min-content, 1fr); gap: 14px; }
  .crew-page .months .weekdays div { font-size: .77rem; }
  .crew-page .months .month-title { font-size: 1rem; }
  .crew-page .months .day { font-size: .96rem; }
  .crew-page .months > div:first-child .days { min-height: 300px; }
  .crew-page .months > div:first-child .day {
    aspect-ratio: auto;
    min-height: 48px;
    align-self: stretch;
    font-size: 1.3rem;
  }
  .crew-page .months > div:first-child .month-title { font-size: 1.4rem; }
  .crew-page #summary.summary-measuring > .card { height: auto; }
}

/* Preserve the original edge controls when the optional reset is hidden. */
.calendar-navigation { position: relative; display: flex; justify-content: space-between; align-items: center; }
.calendar-navigation button[data-month-step="0"] {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
.calendar-navigation button[hidden] { display: none; }
@media (max-width: 420px) {
  .calendar-navigation button { max-width: 32%; padding-left: 5px; padding-right: 5px; font-size: .72rem; }
}

/* Welcome screen: reveal the dashboard only after a crew member is chosen. */
.crew-page.awaiting-crew .footer,
.crew-page.awaiting-crew #summary,
.crew-page.awaiting-crew #details { display: none; }
.crew-page.awaiting-crew .shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, .15fr) auto minmax(0, .85fr);
  align-items: start;
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 24px 0;
}
/* Keep 30% of the former space above the welcome cards. */
.crew-page.awaiting-crew .hero { margin-bottom: 6px; }
.crew-page.awaiting-crew .grid { display: block; grid-row: 4; width: min(100%, 440px); align-self: start; justify-self: center; margin: 7.2px 0; }
.crew-page.awaiting-crew .stack { display: block; }
.crew-page.awaiting-crew .crew-picker {
  padding: 32px;
  border-radius: 22px;
  box-shadow: 0 18px 54px rgba(25,55,72,.1);
}
.crew-page.awaiting-crew .crew-picker .card-head { justify-content: center; text-align: center; margin-bottom: 24px; }
.crew-page.awaiting-crew .crew-picker h2 { font-size: 1.25rem; letter-spacing: .04em; }
.crew-page.awaiting-crew .crew-picker .card-kicker { display: none; }
.crew-page.awaiting-crew .crew-picker select { min-height: 54px; font-size: 1rem; }
.crew-page.awaiting-crew .crew-picker label { font-size: .9rem; }
#picker-message[hidden] { display: none; }

/* Mobile crew calendar: desktop palette, existing three-month layout. */
@media (max-width: 820px) {
  .crew-page .calendar-card .days { background-color: var(--canvas); }
  .crew-page .calendar-card .day {
    color: var(--ink);
    background-color: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line);
  }
  .crew-page .calendar-card .day.past { color: #91a0aa; }
  .crew-page .calendar-card .day.onboard {
    color: var(--green);
    background-color: var(--green-soft);
  }
  .crew-page .calendar-card .day.vacation {
    color: var(--yellow);
    background-color: var(--yellow-soft);
  }
  .crew-page .calendar-card .day.today { outline-color: var(--blue-2); }
  .crew-page .calendar-navigation button {
    color: var(--navy);
    background-color: var(--surface);
    border-color: var(--line);
    -webkit-tap-highlight-color: rgba(11, 131, 198, .12);
  }
  .crew-page .calendar-navigation button:hover,
  .crew-page .calendar-navigation button:active {
    color: var(--blue);
    background-color: var(--sky);
  }
  .crew-page select {
    color-scheme: light;
    color: var(--ink);
    background-color: var(--surface);
    border-color: var(--line);
  }
}

