/* CrewLog -- dark, mobile-first. Phone is the primary target; desktop just gets
   more columns. Everything is CSS custom properties so themes stay in one place. */

:root {
  --bg:        #0b1020;
  --bg-2:      #121a30;
  --surface:   #16203a;
  --surface-2: #1d2947;
  --border:    #26324f;
  --border-hi: #35456b;

  --text:      #e8edf9;
  --text-dim:  #9aa8c7;
  --text-mute: #6b7998;

  --accent:      #4fd1c5;
  --accent-dim:  #2c8d86;
  --accent-soft: rgba(79, 209, 197, 0.12);
  --gold:        #f0b429;
  --violet:      #a78bfa;
  --rose:        #fb7185;
  --sky:         #60a5fa;
  --green:       #34d399;

  --radius:    14px;
  --radius-sm: 9px;
  --shadow:    0 6px 24px rgba(0, 0, 0, 0.35);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 58px;

  /* Data-visualisation tokens. Validated against the --surface #16203a dark
     surface with the dataviz palette validator: viz-primary + viz-secondary
     pass all six checks as a categorical pair (CVD dE 12.3, normal 19.7);
     viz-primary + viz-warn pass as meter states; viz-track clears the 2:1
     near-surface floor at 2.42:1. Do not hand-tune these without re-running it. */
  --viz-primary:   #2aa79b;
  --viz-secondary: #9085e9;
  --viz-warn:      #c98500;
  --viz-track:     #26665f;
  --viz-land:      #222e4d;
  --viz-grid:      #26324f;
  --viz-dim:       #4a5878;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(180deg, var(--bg-2), rgba(18, 26, 48, 0.6));
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--text-mute); letter-spacing: 0.04em; }
.topbar-spacer { flex: 1; }
.topbar .who { font-size: 13px; color: var(--text-dim); text-align: right; }
.topbar .who b { display: block; color: var(--text); font-size: 14px; }
.topbar .logout { display: flex; flex: none; }
.topbar .logout .btn { display: inline-flex; align-items: center; gap: 7px; }
.topbar .logout svg { width: 16px; height: 16px; flex: none; }
/* Narrow screens keep the topbar but lose the room for a word, so the icon
   carries it alone; the button keeps its title attribute for accessibility. */
@media (max-width: 560px) {
  .topbar .logout .btn span { display: none; }
  .topbar .logout .btn { padding: 6px 9px; }
}

/* ---------- desktop nav ---------- */
.navlinks { display: none; gap: 4px; }
.navlinks a {
  padding: 7px 13px; border-radius: 999px; font-size: 14px; font-weight: 500;
  color: var(--text-dim);
}
.navlinks a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.navlinks a.on { background: var(--accent-soft); color: var(--accent); }

/* ---------- bottom tab bar (mobile) ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex; height: var(--nav-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(13, 19, 36, 0.94);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 10px; font-weight: 600; letter-spacing: 0.02em;
  color: var(--text-mute); text-decoration: none;
}
.tabbar a.on { color: var(--accent); }
.tabbar svg { width: 21px; height: 21px; }

@media (min-width: 820px) {
  .navlinks { display: flex; }
  .tabbar { display: none; }
  body { padding-bottom: 0; }
  .wrap { padding: 24px 20px 60px; }
}

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card.flush { padding: 0; overflow: hidden; }
.card h2, .card h3 { margin: 0 0 12px; letter-spacing: -0.01em; }
.card h2 { font-size: 17px; }
.card h3 { font-size: 14px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }

.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 12px;
}
.card-head h2, .card-head h3 { margin: 0; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 25px; letter-spacing: -0.03em; }
.page-head p { margin: 3px 0 0; color: var(--text-dim); font-size: 14px; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 620px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tiles.three { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 620px) { .tiles.three { grid-template-columns: repeat(3, 1fr); } }

.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 13px 14px;
}
.tile .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-mute); font-weight: 700; }
.tile .v { font-size: 23px; font-weight: 700; letter-spacing: -0.03em; margin-top: 3px; }
.tile .s { font-size: 12px; color: var(--text-dim); margin-top: 1px; }
.tile.accent .v { color: var(--accent); }
.tile.gold .v   { color: var(--gold); }
.tile.violet .v { color: var(--violet); }
.tile.sky .v    { color: var(--sky); }
.tile.green .v  { color: var(--green); }

/* ---------- flight / trip rows ---------- */
.rows { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  color: var(--text); text-decoration: none;
}
.row:last-child { border-bottom: none; }
.row:hover { background: var(--surface-2); text-decoration: none; }
.row .grow { flex: 1; min-width: 0; }
.row .when { font-size: 11.5px; color: var(--text-mute); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.row .main { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.row .sub { font-size: 12.5px; color: var(--text-dim); }
.row .right { text-align: right; flex-shrink: 0; }
.row .right .big { font-family: var(--mono); font-size: 14px; font-variant-numeric: tabular-nums; }
.row .right .small { font-size: 11.5px; color: var(--text-mute); }

.route { display: flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: 15px; font-weight: 600; }
.route .arrow { color: var(--text-mute); font-size: 12px; }
.route .code { letter-spacing: 0.02em; }

/* ---------- date bucket header ---------- */
.bucket {
  padding: 9px 16px; font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-mute);
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  position: sticky; top: var(--nav-h); z-index: 5;
}
@media (min-width: 820px) { .bucket { top: 0; } }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border-hi);
  white-space: nowrap;
}
.badge.dh    { background: rgba(167, 139, 250, 0.14); color: var(--violet); border-color: rgba(167, 139, 250, 0.3); }
.badge.intl  { background: rgba(96, 165, 250, 0.14); color: var(--sky); border-color: rgba(96, 165, 250, 0.3); }
.badge.pays  { background: var(--accent-soft); color: var(--accent); border-color: rgba(79, 209, 197, 0.32); }
.badge.warn  { background: rgba(240, 180, 41, 0.14); color: var(--gold); border-color: rgba(240, 180, 41, 0.32); }
.badge.live  { background: rgba(52, 211, 153, 0.16); color: var(--green); border-color: rgba(52, 211, 153, 0.34); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-hi); cursor: pointer;
  font-size: 14px; font-weight: 600; font-family: inherit;
  text-decoration: none; transition: background 0.13s, border-color 0.13s;
}
.btn:hover { background: var(--border); text-decoration: none; }
.btn.primary { background: var(--accent); color: #06231f; border-color: var(--accent); }
.btn.primary:hover { background: #6fded3; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--rose); border-color: rgba(251, 113, 133, 0.4); }
.btn.danger:hover { background: rgba(251, 113, 133, 0.12); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btnrow { display: flex; gap: 9px; flex-wrap: wrap; }

/* ---------- forms ---------- */
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--text-dim); margin-bottom: 5px; letter-spacing: 0.02em; }
.field .hint { font-size: 11.5px; color: var(--text-mute); margin-top: 4px; line-height: 1.45; }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=time], input[type=email], input[type=file], select, textarea {
  width: 100%; padding: 10px 12px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border-hi); border-radius: var(--radius-sm);
  font-size: 15px; font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); vertical-align: -3px; }
textarea { min-height: 120px; font-family: var(--mono); font-size: 13px; line-height: 1.55; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 620px) {
  .grid2 { grid-template-columns: 1fr 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr 1fr; }
}
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; margin: 0 0 16px; }
legend { padding: 0 7px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--accent); }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-mute); font-weight: 700; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- flash + alerts ---------- */
.flash {
  padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 14px;
  font-size: 14px; border: 1px solid;
  background: var(--accent-soft); border-color: rgba(79, 209, 197, 0.3); color: var(--accent);
}
.flash.err  { background: rgba(251, 113, 133, 0.12); border-color: rgba(251, 113, 133, 0.34); color: var(--rose); }
.flash.warn { background: rgba(240, 180, 41, 0.12); border-color: rgba(240, 180, 41, 0.34); color: var(--gold); }

.empty { text-align: center; padding: 34px 18px; color: var(--text-mute); }
.empty svg { width: 38px; height: 38px; opacity: 0.4; margin-bottom: 10px; }
.empty p { margin: 0 0 14px; font-size: 14px; }

/* ---------- misc ---------- */
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dim { color: var(--text-dim); }
.mute { color: var(--text-mute); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 5px 11px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border-hi); font-size: 12.5px; color: var(--text-dim);
}
.chip b { color: var(--text); font-family: var(--mono); }
.chip.on { background: var(--accent-soft); border-color: var(--accent-dim); color: var(--accent); }

.filters { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type=text] { flex: 1; min-width: 160px; }
.filters select { width: auto; min-width: 110px; }

.divider { height: 1px; background: var(--border); margin: 16px 0; border: 0; }

/* segmented control */
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--border-hi); border-radius: 999px; padding: 3px; }
.seg a { padding: 5px 13px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: var(--text-dim); }
.seg a.on { background: var(--accent); color: #06231f; }
.seg a:hover { text-decoration: none; }

/* auth screens */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 22px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .brand { justify-content: center; font-size: 22px; margin-bottom: 6px; }
.auth-card .brand svg { width: 27px; height: 27px; }
.auth-sub { text-align: center; color: var(--text-dim); font-size: 14px; margin: 0 0 20px; }

/* timeline for trip detail */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--border-hi); }
.tl-item { position: relative; padding: 0 0 16px; }
.tl-item::before {
  content: ""; position: absolute; left: -23px; top: 5px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
}
.tl-item.rest::before { background: var(--gold); }
.tl-item.dh::before { background: var(--violet); }
.tl-item .tl-head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-mute); font-weight: 700; }
.tl-item .tl-body { margin-top: 2px; }


/* ---------- charts ---------- */
.viz { position: relative; }
.viz svg { display: block; width: 100%; height: auto; overflow: visible; }
/* The map is the one viz that must clip. Its projection frames +83/-58
   latitude, but world.json carries geometry down to -90, so Antarctica
   projects about 104px below a 460px viewBox and, with overflow visible,
   paints over the card beneath it. Every other chart genuinely needs
   overflow visible for labels that sit outside the plot area, so scope the
   clip to the map rather than changing the shared rule. */
.viz[data-viz="map"] svg { overflow: hidden; }
.viz-axis { fill: var(--text-mute); font-size: 10px; font-weight: 600; letter-spacing: 0.03em; font-variant-numeric: tabular-nums; }
.viz-label { fill: var(--text); font-size: 10.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.viz-grid-line { stroke: var(--viz-grid); stroke-width: 1; }
.viz-bar { fill: var(--viz-primary); transition: opacity 0.12s; }
.viz-bar.empty { fill: var(--viz-dim); opacity: 0.35; }
.viz-hit { fill: transparent; cursor: pointer; }
.viz-hit:hover + .viz-bar, .viz-bar:hover { opacity: 0.78; }

.viz-tip {
  position: absolute; z-index: 30; pointer-events: none; opacity: 0;
  transform: translate(-50%, -100%);
  background: var(--bg); border: 1px solid var(--border-hi); border-radius: 8px;
  padding: 7px 10px; font-size: 12px; line-height: 1.4; white-space: nowrap;
  box-shadow: var(--shadow); transition: opacity 0.1s;
}
.viz-tip.on { opacity: 1; }
.viz-tip b { display: block; font-size: 12.5px; }
.viz-tip .t-sub { color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* map */
.map-land { fill: var(--viz-land); stroke: var(--border); stroke-width: 0.4; }
.map-route { stroke: var(--viz-primary); fill: none; stroke-linecap: round; opacity: 0.72; }
.map-dot { fill: var(--viz-primary); stroke: var(--surface); stroke-width: 2; }
.map-hit { fill: transparent; cursor: pointer; }

/* meter -- fill carries severity, track is a near-surface step of the same ramp */
.meter { margin: 4px 0 0; }
.meter-track { height: 10px; border-radius: 999px; background: var(--viz-track); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; background: var(--viz-primary); transition: width 0.3s; }
.meter-fill.warn { background: var(--viz-warn); }
.meter-legend { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; font-size: 12px; }
.meter-state { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; }
.meter-state svg { width: 13px; height: 13px; }
.meter-state.ok   { color: var(--viz-primary); }
.meter-state.warn { color: var(--viz-warn); }
.hidden { display: none !important; }

/* ---- month calendar ---------------------------------------------------- */
.cal-nav { display:flex; align-items:center; gap:6px; }
.cal-nav .btn { padding:6px 10px; }
.cal-month { font-variant-numeric:tabular-nums; min-width:10.5ch; text-align:center;
             font-weight:650; font-size:15px; }

.cal { display:grid; grid-template-columns:repeat(7,1fr); gap:1px;
       background:var(--border); border:1px solid var(--border);
       border-radius:var(--radius); overflow:hidden; }
.cal-dow { background:var(--surface-2); color:var(--text-mute); font-size:11px;
           text-transform:uppercase; letter-spacing:.07em; font-weight:650;
           text-align:center; padding:7px 2px; }
.cal-day { background:var(--surface); min-height:104px; padding:6px 6px 7px;
           display:flex; flex-direction:column; gap:4px; position:relative; }
.cal-day.out { background:var(--bg-2); }
.cal-day.out .cal-num { color:var(--text-mute); opacity:.55; }
.cal-day.today { box-shadow:inset 0 0 0 2px var(--accent); }
.cal-day.holiday { background:linear-gradient(160deg,var(--surface),rgba(240,180,41,.09)); }

.cal-top { display:flex; align-items:baseline; justify-content:space-between; gap:4px; }
.cal-num { font-family:var(--mono); font-size:13px; font-weight:650; color:var(--text-dim); }
.cal-day.today .cal-num { color:var(--accent); }
.cal-tfp { font-family:var(--mono); font-size:11px; color:var(--accent); font-weight:650; }
.cal-hol { font-size:9.5px; text-transform:uppercase; letter-spacing:.05em;
           color:var(--gold); font-weight:700; line-height:1.1; }

.cal-trip { display:block; text-decoration:none; border-radius:var(--radius-sm);
            padding:3px 6px; font-size:11.5px; line-height:1.3; font-weight:600;
            background:var(--accent-soft); color:var(--accent);
            border:1px solid var(--accent-dim); white-space:nowrap;
            overflow:hidden; text-overflow:ellipsis; }
.cal-trip:hover { background:rgba(79,209,197,.2); }
.cal-trip.rsv { background:rgba(167,139,250,.12); color:var(--violet);
                border-color:rgba(167,139,250,.35); }
.cal-trip.personal { background:rgba(96,165,250,.12); color:var(--sky);
                     border-color:rgba(96,165,250,.35); }
.cal-trip small { display:block; font-weight:500; opacity:.8; font-size:10px; }
.cal-more { font-size:10.5px; color:var(--text-mute); padding-left:2px; }

@media (max-width: 760px) {
  .cal-day { min-height:74px; padding:4px 3px 5px; gap:3px; }
  .cal-num { font-size:11.5px; }
  .cal-tfp, .cal-hol { font-size:9.5px; }
  .cal-trip { font-size:10px; padding:2px 4px; }
  .cal-trip small, .cal-more { display:none; }
}

/* ---- stacked composition bar ------------------------------------------- */
.viz-stack { position:relative; }
.viz-stack svg { width:100%; height:34px; display:block; }
.viz-stack-label { fill:#0b1020; font-size:11px; font-weight:750;
                   font-family:var(--mono); paint-order:stroke; }
.viz-legend { display:flex; flex-wrap:wrap; gap:6px 18px; margin-top:11px; }
.viz-legend-item { display:inline-flex; align-items:center; gap:7px;
                   font-size:12px; color:var(--text-dim); }
.viz-legend-item i { width:10px; height:10px; border-radius:3px; flex:none; }
.viz-legend-item b { color:var(--text); font-family:var(--mono); font-weight:650; }
