:root {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface-alt: #EDF0F4;
  --border: #E2E6EC;
  --text: #1A1D23;
  --muted: #6B7280;
  --rail-bg: #FFFFFF;
  --both-off-bg: #E5F6EA;
  --both-off-accent: #138A36;
  --today-ring: #D71920;
  --flight-bg: #FFFFFF;
  --flight-text: #C81E25;
  --flight-badge: #C81E25;
  --flight-border: #F2D7D8;
  --off-badge: #128A2E;
  --vac-badge: #0F8A3A;
  --sim-badge: #E8A317;
  --rest-badge: #7685D8;
  --sby-badge: #2563EB;
  --change-border: #F59E0B;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] {
  --bg: #0D1117;
  --surface: #161B22;
  --surface-alt: #21262D;
  --border: #30363D;
  --text: #E6EDF3;
  --muted: #8B949E;
  --rail-bg: #161B22;
  --both-off-bg: #102A1A;
  --both-off-accent: #3FB950;
  --today-ring: #F85149;
  --flight-bg: #1D1719;
  --flight-text: #FF7B72;
  --flight-badge: #D73A49;
  --flight-border: #4A2226;
  --off-badge: #238636;
  --vac-badge: #1F7A38;
  --sim-badge: #D29922;
  --rest-badge: #6E7ED6;
  --sby-badge: #388BFD;
  --change-border: #D29922;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
.hidden { display: none !important; }

/* PIN Gate */
.pin-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.pin-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 28px 22px; width: 100%; max-width: 320px; text-align: center; box-shadow: var(--shadow);
}
.pin-logo {
  width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 50%;
  background: var(--flight-badge); color: #fff; font-size: 28px;
  display: flex; align-items: center; justify-content: center;
}
.pin-card h2 { margin: 0 0 6px; }
.pin-card p { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.pin-card input {
  width: 100%; padding: 12px; text-align: center; font-size: 20px; letter-spacing: 6px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  margin-bottom: 12px;
}
.error-text { color: var(--flight-text); font-size: 13px; margin-top: 8px; }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.topbar-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 6px;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-title { font-weight: 700; font-size: 17px; }
.sync-badge {
  font-size: 11px; padding: 2px 7px; border-radius: 99px;
  background: var(--surface-alt); color: var(--muted); font-weight: 600;
}
.sync-badge.online { color: var(--both-off-accent); background: var(--both-off-bg); }
.sync-badge.offline { color: #B45309; background: #FEF3C7; }
[data-theme="dark"] .sync-badge.offline { color: #FBBF24; background: #3B270C; }

.top-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-alt); color: var(--text); font-size: 16px; cursor: pointer;
}
.btn-upload {
  height: 34px; padding: 0 11px; border-radius: 10px; border: none;
  background: var(--flight-badge); color: #fff; font-weight: 600; font-size: 13px; cursor: pointer;
}

.controls-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 12px 8px; gap: 8px;
}
.month-nav { display: flex; align-items: center; gap: 6px; }
.nav-arrow {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-alt); color: var(--text); font-size: 18px; line-height: 1; cursor: pointer;
}
.month-label { font-weight: 700; font-size: 15px; min-width: 78px; text-align: center; }

.filter-pills { display: flex; gap: 6px; }
.pill-btn {
  padding: 5px 10px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface-alt); color: var(--text); font-size: 12px; font-weight: 600; cursor: pointer;
}
.pill-btn.active {
  background: var(--both-off-accent); color: #fff; border-color: var(--both-off-accent);
}

.col-headers {
  display: grid; grid-template-columns: 50px 1fr 1fr; gap: 6px;
  padding: 6px 8px; background: var(--bg); border-top: 1px solid var(--border);
}
.col-head { display: flex; flex-direction: column; align-items: center; }
.col-name { font-weight: 700; font-size: 13px; }
.col-meta { font-size: 10px; color: var(--muted); }

/* Main Date-Locked Grid */
.roster-grid {
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr) minmax(0, 1fr);
  grid-auto-rows: minmax(64px, auto);
  gap: 6px;
  padding: 8px 8px 80px;
}

.date-cell {
  background: var(--rail-bg); border: 1px solid var(--border); border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 4px 2px; line-height: 1.1; user-select: none;
}
.date-cell .dow { font-size: 10px; color: var(--muted); text-transform: uppercase; font-weight: 600; }
.date-cell .dom { font-size: 18px; font-weight: 800; margin: 1px 0; }
.date-cell .mon { font-size: 9px; color: var(--muted); text-transform: uppercase; }
.date-cell.both-off {
  background: var(--both-off-bg); border-color: var(--both-off-accent);
}
.date-cell.both-off .dom, .date-cell.both-off .dow { color: var(--both-off-accent); }
.date-cell.is-today {
  border: 2px solid var(--today-ring);
}
.date-cell.is-past { opacity: 0.55; }

/* Duty Cards */
.duty-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 13px;
  padding: 7px 8px; box-shadow: var(--shadow); cursor: pointer;
  display: flex; flex-direction: column; justify-content: center;
  min-width: 0; position: relative; overflow: hidden;
}
.duty-card.is-past { opacity: 0.58; }
.duty-card.type-flight {
  background: var(--flight-bg); border-color: var(--flight-border);
}
.duty-card.duty-change {
  border: 2px solid var(--change-border);
}
.duty-card.multi-day {
  justify-content: space-between; padding: 8px;
}
.duty-card.empty-slot {
  background: transparent; border: 1px dashed var(--border); box-shadow: none; opacity: 0.45;
  align-items: center; font-size: 11px; color: var(--muted);
}

.card-main {
  display: flex; align-items: center; gap: 7px; min-width: 0;
}
.badge {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.badge svg { width: 16px; height: 16px; fill: currentColor; }
.badge.flight { background: var(--flight-badge); }
.badge.day_off { background: var(--off-badge); }
.badge.vacation { background: var(--vac-badge); }
.badge.sim { background: var(--sim-badge); }
.badge.rest { background: var(--rest-badge); }
.badge.standby { background: var(--sby-badge); }
.badge.other { background: var(--muted); }

.card-text { min-width: 0; flex: 1; }
.card-code {
  font-size: 12.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.type-flight .card-code { color: var(--flight-text); }
.card-sub {
  font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 1px;
}

.time-bar {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10.5px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--text); opacity: 0.88;
}
.time-bar.est { color: var(--muted); font-weight: 600; }
.carry-tag {
  font-size: 9.5px; color: var(--muted); font-weight: 600;
}
.change-banner {
  margin-top: 4px; font-size: 9.5px; font-weight: 700; text-align: center;
  background: var(--change-border); color: #fff; border-radius: 6px; padding: 1px 4px;
}

/* Modals */
.modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.52);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-sheet {
  background: var(--surface); width: 100%; max-width: 520px; max-height: 90vh;
  border-radius: 20px 20px 0 0; display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; }
.close-btn {
  border: none; background: var(--surface-alt); color: var(--text);
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 14px;
}
.modal-body { padding: 14px 16px 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }

.field-label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
.input, .file-input {
  width: 100%; padding: 9px 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 14px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg-control { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg-btn {
  padding: 9px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-alt); color: var(--text); font-weight: 700; cursor: pointer;
}
.seg-btn.active { background: var(--flight-badge); color: #fff; border-color: var(--flight-badge); }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.btn-primary, .btn-secondary, .btn-danger {
  padding: 11px 14px; border-radius: 11px; border: none; font-weight: 700; font-size: 14px; cursor: pointer;
}
.btn-primary { background: var(--flight-badge); color: #fff; }
.btn-secondary { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: #991B1B; color: #fff; }
.full { width: 100%; }

.hint-text, .status-text { font-size: 12.5px; color: var(--muted); }
.gap-warning {
  padding: 8px 10px; border-radius: 10px; font-size: 12px; font-weight: 600;
  background: #FEF3C7; color: #92400E;
}
[data-theme="dark"] .gap-warning { background: #3B270C; color: #FBBF24; }
.review-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.review-item {
  display: flex; justify-content: space-between; align-items: center; font-size: 12.5px;
  padding: 7px 10px; border-radius: 9px; background: var(--bg); border: 1px solid var(--border);
}
.legs-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; font-size: 12px; display: flex; flex-direction: column; gap: 6px;
}
.leg-row { display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; }
.edit-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.edit-actions button { flex: 1; }
/* LFML Meal Ordering */
.meal-pill { background: #FEF3C7; color: #92400E; border-color: #F59E0B; }
[data-theme="dark"] .meal-pill { background: #3B270C; color: #FBBF24; border-color: #B45309; }
.meal-dot { font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 6px; margin-left: 4px; }
.meal-dot.due { background: #FEF3C7; color: #92400E; }
.meal-dot.done { background: var(--both-off-bg); color: var(--both-off-accent); }
[data-theme="dark"] .meal-dot.due { background: #3B270C; color: #FBBF24; }
.spml-box { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.spml-row { display: flex; justify-content: space-between; align-items: center; }
.spml-label { font-size: 12.5px; font-weight: 700; }
.spml-actions { display: flex; gap: 8px; }
.spml-actions .btn-primary { flex: 1; }
.meal-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.meal-item-info { font-size: 12.5px; line-height: 1.3; }
.meal-item-btns { display: flex; gap: 6px; flex-shrink: 0; }

/* Flightradar24 Single-Line Bar */
.fr24-box {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow-x: auto;
}
.fr24-ico { flex-shrink: 0; display: block; border-radius: 7px; }
.fr24-pills { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.fr24-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 11px;
  border-radius: 999px;
  background: #FFFFFF;
  border: 1px solid var(--border);
  color: #111827;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
[data-theme="dark"] .fr24-link {
  background: #27272A;
  border-color: #3F3F46;
  color: #F4F4F5;
}
.fr24-link:active { opacity: 0.7; }

/* Outlook-Blue Meal Email Button & Status */
.btn-outlook {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 14px;
  border: none;
  border-radius: 11px;
  background: #0F6CBD;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn-outlook:active { background: #0C5A9E; }
.btn-ico { flex-shrink: 0; display: block; }
.spml-label { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 700; }
.svg-tick { flex-shrink: 0; display: inline-block; vertical-align: middle; }

/* Card Meal Pill (under flight code) */
.meal-pill-card {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  width: fit-content;
}
.meal-pill-card.due {
  background: #FEF3C7;
  color: #92400E;
  border: 1px solid #F59E0B55;
}
.meal-pill-card.done {
  background: #DCFCE7;
  color: #166534;
  border: 1px solid #16A34A44;
}
[data-theme="dark"] .meal-pill-card.due {
  background: #3B270C;
  color: #FBBF24;
  border-color: #B4530966;
}
[data-theme="dark"] .meal-pill-card.done {
  background: #0F2E1A;
  color: #4ADE80;
  border-color: #16A34A55;
}
