/* IMACTA app shell and components. Mobile-first; desktop is the enhancement. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  line-height: var(--leading-tight);
  letter-spacing: -0.015em;
  margin: 0;
}

button { font: inherit; color: inherit; cursor: pointer; }

:where(a, button, input, select, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ═══ Layout ═══════════════════════════════════════════════════════════════ */

.app {
  /* One source for bar heights. Hardcoding them twice drifted and slid the
     sidebar under the topbar. */
  --topbar-h: calc(58px + var(--space-4) + env(safe-area-inset-top));
  --bottomnav-h: calc(66px + var(--space-3));

  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100dvh;
  padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
}

.main {
  width: 100%;
  max-width: 1180px;
  margin-inline: auto;
  padding: var(--space-4) var(--space-4) var(--space-7);
}

@media (min-width: 1024px) {
  .app { grid-template-columns: 250px 1fr; padding-bottom: 0; }
  .topbar { grid-column: 1 / -1; }
  .main { padding: var(--space-5) var(--space-6) var(--space-8); }
}

/* Onboarding screens have no nav yet, so there is no sidebar column to leave room for. */
.app--bare { padding-bottom: env(safe-area-inset-bottom); }
@media (min-width: 1024px) {
  .app--bare { grid-template-columns: 1fr; }
}

/* ═══ Top bar — a floating glass pill, not a bar welded to the edge ════════ */

.topbar { position: sticky; top: 0; z-index: var(--z-sticky); padding-top: env(safe-area-inset-top); }

.topbar__inner {
  display: flex; align-items: center; gap: var(--space-3);
  width: min(100% - var(--space-4) * 2, 1400px);
  min-height: 58px;
  margin: var(--space-3) auto 0;
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
  border-radius: var(--radius-lg);
}

.topbar__mark {
  display: flex; align-items: center; gap: var(--space-2);
  font-family: var(--font-display); font-weight: 700;
  font-size: var(--text-sm); letter-spacing: 0.1em; text-transform: uppercase;
}
.topbar__mark svg { color: var(--blue); flex: none; }

.topbar__day {
  margin-left: auto;
  font-family: var(--font-display); font-weight: 600;
  font-size: var(--text-sm); color: var(--ink-muted); white-space: nowrap;
}

/* Deep Water toggle — Part 3.2. Framed as a promotion, never as a setting. */
.deepwater {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: 44px; padding: 0 var(--space-3);
  border: 1px solid var(--glass-line); border-radius: var(--radius-pill);
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(10px) saturate(150%);
  backdrop-filter: blur(10px) saturate(150%);
  box-shadow: inset 0 1px 0 var(--glass-hl);
  font-size: var(--text-sm); font-weight: 500; color: var(--ink-muted);
  transition: background var(--dur) var(--ease-out), color var(--dur) var(--ease-out),
              transform var(--dur-fast) var(--ease-spring);
}
.deepwater:hover { color: var(--ink); transform: translateY(-1px); }
.deepwater[aria-pressed='true'] {
  background: linear-gradient(150deg, var(--blue), var(--blue-deep));
  border-color: transparent; color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.25), 0 6px 18px rgba(26,107,255,0.32);
}
.deepwater__dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-subtle); transition: background var(--dur) var(--ease-out);
}
.deepwater[aria-pressed='true'] .deepwater__dot {
  background: var(--brass-light); box-shadow: 0 0 8px var(--brass-light);
}
/* The label always shows — a lone dot in a pill is not an identifiable control.
   The wordmark drops its text first; the anchor still carries the brand. */
.deepwater__label { white-space: nowrap; }
@media (max-width: 439px) {
  .topbar__mark { font-size: 0; gap: 0; }
  .topbar__mark svg { font-size: initial; }
}

/* The real metric name, revealed underneath by the toggle. */
.real { display: none; font-size: var(--text-xs); color: var(--ink-subtle); font-weight: 400; }
[data-deepwater='on'] .real { display: block; }

/* ═══ Navigation ═══════════════════════════════════════════════════════════ */
/* Mobile: a floating glass pill, max 5 items. Desktop: a sidebar. */

.nav {
  position: fixed; z-index: var(--z-nav);
  bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
  left: var(--space-3); right: var(--space-3);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: var(--space-1);
  border-radius: var(--radius-lg);
}

.nav__item {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-height: 58px; padding: var(--space-2) 2px;
  border-radius: var(--radius); background: none; border: 0;
  font-size: 10.5px; font-weight: 600; color: var(--ink-subtle);
  text-decoration: none; text-align: center;
  transition: color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.nav__item svg { width: 23px; height: 23px; }
.nav__item[aria-current='page'] {
  color: var(--blue);
  background: linear-gradient(180deg, rgba(26,107,255,0.16), rgba(26,107,255,0.07));
  box-shadow: inset 0 1px 0 var(--glass-hl);
}
.nav__item:active { transform: scale(0.96); }

/* Locked destinations explain themselves rather than vanishing. */
.nav__item[data-locked='true'] { opacity: 0.5; }
.nav__lock { position: absolute; top: 8px; right: 50%; margin-right: -20px; width: 12px; height: 12px; }

@media (min-width: 1024px) {
  .nav {
    position: sticky; top: var(--topbar-h); align-self: start;
    left: auto; right: auto; bottom: auto;
    display: flex; flex-direction: column; gap: var(--space-1);
    grid-template-columns: none;
    height: calc(100dvh - var(--topbar-h));
    padding: var(--space-4) var(--space-3);
    border: 0; border-radius: 0; box-shadow: none;
    background: none; backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .nav__item {
    flex-direction: row; justify-content: flex-start; gap: var(--space-3);
    min-height: 46px; padding: var(--space-2) var(--space-3);
    font-size: var(--text-base); font-weight: 500;
  }
  .nav__item:hover { background: var(--glass-bg); color: var(--ink); }
  .nav__item[aria-current='page'] { font-weight: 600; }
  .nav__lock { position: static; margin: 0 0 0 auto; }
}

/* ═══ Cards ════════════════════════════════════════════════════════════════ */

.card { border-radius: var(--radius-lg); }
.card__head {
  display: flex; align-items: baseline; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-5) var(--space-5) 0;
}
.card__title { font-size: var(--text-lg); font-weight: 600; }
.card__hint { font-size: var(--text-sm); color: var(--ink-subtle); }
.card__body { padding: var(--space-5); }

.grid { display: grid; gap: var(--space-4); }
@media (min-width: 768px) {
  .grid--wheelhouse { grid-template-columns: repeat(2, 1fr); }
  .grid--wheelhouse > .span-2 { grid-column: 1 / -1; }
}

/* ═══ The Licence Card — Part 8.3 component 1 ══════════════════════════════ */
/* Must feel like a physical object. Captains download this and post it, and that is
   free distribution — so it gets a treatment nothing else in the app gets: real depth,
   a brass edge, an embossed anchor, and water moving at its foot. */

.licence {
  position: relative; overflow: hidden; isolation: isolate;
  border-radius: var(--radius-xl);
  padding: var(--space-5) var(--space-5) var(--space-6);
  color: #eaf3fb;
  border: 1px solid transparent;
  background:
    radial-gradient(130% 130% at 86% -18%, rgba(217, 155, 43, 0.28) 0%, transparent 56%),
    linear-gradient(rgba(7, 28, 46, 0.92), rgba(7, 28, 46, 0.92)) padding-box,
    linear-gradient(150deg, rgba(242, 207, 138, 0.55), rgba(255,255,255,0.10) 38%,
                    rgba(26, 107, 255, 0.35)) border-box;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.16), var(--shadow-3);
}
/* Depth soundings raked across the card stock. */
.licence::before {
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: repeating-linear-gradient(-14deg, transparent 0 24px,
              rgba(255,255,255,0.026) 24px 25px);
}

.licence__eyebrow {
  display: flex; align-items: center; gap: var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.16em;
  text-transform: uppercase; color: #f2cf8a; /* 9.1:1 on the card ground */
}
.licence__boat {
  margin-top: var(--space-3);
  font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 700;
}
.licence__captain { font-size: var(--text-sm); color: #a9c9e2; }

.licence__meta { display: flex; gap: var(--space-5); margin: var(--space-4) 0 0; }
.licence__meta dt {
  font-size: var(--text-xs); letter-spacing: 0.1em; text-transform: uppercase; color: #9dc0dc;
}
.licence__meta dd {
  margin: 3px 0 0; font-family: var(--font-display);
  font-size: var(--text-base); font-weight: 600; color: #fff;
}

/* Class stamps. Shape carries the state — solid ring earned, dashed ring not — so it
   never depends on colour alone. Earned stamps sit at a slight angle, like a real one. */
.stamps { display: flex; gap: var(--space-2); margin-top: var(--space-4); }
.stamp {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1.5px dashed rgba(242, 207, 138, 0.40);
  font-family: var(--font-display); font-size: 11px; font-weight: 700;
  color: rgba(242, 207, 138, 0.55);
  transition: transform var(--dur) var(--ease-spring);
}
.stamp[data-earned='true'] {
  border: 2px solid var(--brass-light); border-style: solid;
  background: radial-gradient(circle at 34% 26%, rgba(242,207,138,0.34), rgba(217,155,43,0.14));
  color: #fce8c4;
  transform: rotate(-8deg);
  box-shadow: 0 2px 10px rgba(217, 155, 43, 0.35), inset 0 1px 0 rgba(255,255,255,0.30);
}

/* Never at zero. Endowed progress — buying and naming the boat is already 20%. */
.licence__progress {
  position: relative; z-index: 1;
  margin-top: var(--space-5); height: 7px; border-radius: var(--radius-pill);
  background: rgba(255,255,255,0.14); overflow: hidden;
}
.licence__progress > i {
  display: block; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, var(--brass-deep), var(--brass), var(--brass-light));
  box-shadow: 0 0 14px rgba(217, 155, 43, 0.5);
  transition: width var(--dur-slow) var(--ease-spring);
}

/* ═══ The Water Today — Part 8.3 component 2 ═══════════════════════════════ */
/* Four numbers, each with a SENTENCE underneath. Not a label. A sentence. */

.metrics { display: grid; grid-template-columns: repeat(2, 1fr); }
.metrics > * { padding: var(--space-4); }
.metrics > *:nth-child(odd)  { border-right: 1px solid var(--glass-line); }
.metrics > *:nth-child(-n+2) { border-bottom: 1px solid var(--glass-line); }

@media (min-width: 900px) {
  .metrics { grid-template-columns: repeat(4, 1fr); }
  .metrics > * { border-right: 1px solid var(--glass-line); border-bottom: 0; }
  .metrics > *:last-child { border-right: 0; }
}

.metric__label {
  font-family: var(--font-display);
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-subtle);
}
.metric__value {
  margin-top: var(--space-2);
  font-family: var(--font-display); font-size: var(--text-3xl); font-weight: 700;
  line-height: 1; letter-spacing: -0.03em;
}
.metric__value[data-empty='true'] { color: var(--ink-subtle); font-weight: 500; }
.metric__trend {
  display: inline-flex; align-items: center; gap: 2px;
  margin-left: var(--space-2); font-size: var(--text-sm); font-weight: 700;
  vertical-align: 7px;
}
.metric__trend[data-dir='good'] { color: var(--profit); }
.metric__trend[data-dir='bad']  { color: var(--loss); }
.metric__trend[data-dir='flat'] { color: var(--ink-subtle); }
.metric__sentence {
  margin: var(--space-3) 0 0;
  font-size: var(--text-sm); line-height: var(--leading-snug); color: var(--ink-muted);
  text-wrap: pretty;
}

/* ═══ The Waste Meter — Part 8.3 component 4 ═══════════════════════════════ */

.waste { position: relative; overflow: hidden; }
.waste::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: linear-gradient(180deg, var(--loss), transparent);
}
.waste__value {
  font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 700;
  color: var(--loss);
}
.waste__sub { margin: var(--space-2) 0 0; font-size: var(--text-sm); color: var(--ink-muted); }
/* Without this the Waste Meter causes the exact panic the Lock exists to prevent. */
.waste__reassure {
  display: flex; gap: var(--space-2); margin-top: var(--space-4);
  padding: var(--space-3); border-radius: var(--radius);
  background: var(--glass-bg); border: 1px solid var(--glass-line);
  font-size: var(--text-sm); color: var(--ink-muted);
}

/* ═══ The Three Lights — Part 8.3 component 6 ══════════════════════════════ */

.lights { display: grid; gap: var(--space-4); }
.light { display: grid; grid-template-columns: auto 1fr; gap: var(--space-3); align-items: start; }
.light__pip {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%; margin-top: 2px;
  border: 2px solid currentColor;
  box-shadow: 0 0 12px -2px currentColor, inset 0 1px 0 var(--glass-hl);
}
.light__pip svg { width: 15px; height: 15px; }
.light[data-state='good']  { color: var(--profit); }
.light[data-state='watch'] { color: var(--warn); }
.light[data-state='bad']   { color: var(--loss); }
.light[data-state='none']  { color: var(--ink-subtle); }
.light__name {
  font-family: var(--font-display); font-weight: 600; font-size: var(--text-base); color: var(--ink);
}
.light__note { margin: 3px 0 0; font-size: var(--text-sm); color: var(--ink-muted); }

/* ═══ The Open Card — Part 8.3 component 5 ═════════════════════════════════ */
/* Exactly one, ever. Two open cards is a to-do list, and a to-do list is ignorable.
   So it gets the brass edge — the only card in the app that does. */

.opencard {
  position: relative; overflow: hidden;
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  border: 1px solid transparent;
  background:
    radial-gradient(120% 120% at 88% -10%, rgba(217,155,43,0.14), transparent 58%),
    linear-gradient(var(--glass-bg-strong), var(--glass-bg-strong)) padding-box,
    linear-gradient(150deg, var(--brass-light), rgba(255,255,255,0.05) 42%,
                    rgba(217,155,43,0.45)) border-box;
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  box-shadow: inset 0 1px 0 var(--glass-hl), var(--shadow-2);
}
.opencard__eyebrow {
  font-family: var(--font-display);
  font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.13em;
  text-transform: uppercase; color: var(--brass-deep);
}
.opencard__title { margin-top: var(--space-2); font-size: var(--text-lg); font-weight: 600; }
.opencard__body { margin: var(--space-2) 0 var(--space-4); color: var(--ink-muted); }

/* ═══ Buttons ══════════════════════════════════════════════════════════════ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 50px; padding: 0 var(--space-5);
  border: 1px solid transparent; border-radius: var(--radius);
  font-family: var(--font-display); font-size: var(--text-base); font-weight: 600;
  text-decoration: none;
  transition: transform var(--dur-fast) var(--ease-spring),
              box-shadow var(--dur) var(--ease-out), filter var(--dur) var(--ease-out);
}
.btn:hover  { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(0.985); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn--block { width: 100%; }

.btn--primary {
  background: linear-gradient(150deg, var(--blue-bright), var(--blue) 55%, var(--blue-deep));
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.26), 0 8px 22px rgba(26,107,255,0.30);
}
.btn--primary:hover { box-shadow: inset 0 1px 0 rgba(255,255,255,0.26), 0 14px 32px rgba(26,107,255,0.38); }

.btn--brass {
  background: linear-gradient(150deg, var(--brass-light), var(--brass) 52%, var(--brass-deep));
  color: #2a1c02;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.42), 0 8px 22px rgba(217,155,43,0.32);
}
.btn--brass:hover { box-shadow: inset 0 1px 0 rgba(255,255,255,0.42), 0 14px 32px rgba(217,155,43,0.40); }

.btn--quiet {
  background: var(--glass-bg); color: var(--ink); border-color: var(--glass-line);
  -webkit-backdrop-filter: blur(14px) saturate(150%);
  backdrop-filter: blur(14px) saturate(150%);
  box-shadow: inset 0 1px 0 var(--glass-hl);
}

/* ═══ The Lock — Part 8.4 ══════════════════════════════════════════════════ */
/* A constraint you can see is a feature. A constraint you cannot see is a bug. */

.lockbar {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-4) var(--space-5); margin-bottom: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  background:
    linear-gradient(var(--glass-bg), var(--glass-bg)) padding-box,
    linear-gradient(150deg, var(--glass-edge-a), rgba(26,107,255,0.28)) border-box;
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  box-shadow: inset 0 1px 0 var(--glass-hl), var(--shadow-1);
}
.lockbar svg { flex: none; margin-top: 2px; color: var(--blue); }
.lockbar__title { font-family: var(--font-display); font-weight: 700; }
.lockbar__body { margin: 3px 0 0; font-size: var(--text-sm); color: var(--ink-muted); }

/* ═══ Segmented control ════════════════════════════════════════════════════ */

.seg {
  display: inline-flex; padding: 4px; gap: 2px;
  background: var(--glass-bg); border: 1px solid var(--glass-line);
  border-radius: var(--radius-pill);
  box-shadow: inset 0 1px 2px rgba(18,58,92,0.06);
}
.seg__opt {
  min-height: 38px; padding: 0 var(--space-4);
  background: none; border: 0; border-radius: var(--radius-pill);
  font-size: var(--text-sm); font-weight: 600; color: var(--ink-subtle);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.seg__opt[aria-selected='true'] {
  background: var(--glass-solid); color: var(--ink);
  box-shadow: inset 0 1px 0 var(--glass-hl), var(--shadow-1);
}

/* ═══ Stale data notice ════════════════════════════════════════════════════ */
/* From sync_heartbeats. A client must never read stale numbers as current. */

.stale {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4);
  border-radius: var(--radius); border: 1px solid var(--warn);
  background: var(--glass-bg-strong);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  font-size: var(--text-sm);
}
.stale svg { color: var(--warn); flex: none; }

/* ═══ Entrance ═════════════════════════════════════════════════════════════ */
/* One gentle rise on first paint. Content is readable immediately regardless — the
   animation never gates it, and reduced-motion removes it entirely. */

@media (prefers-reduced-motion: no-preference) {
  .stagger > * { animation: rise var(--dur-slow) var(--ease-out) both; }
  .stagger > *:nth-child(1) { animation-delay: 0ms; }
  .stagger > *:nth-child(2) { animation-delay: 55ms; }
  .stagger > *:nth-child(3) { animation-delay: 110ms; }
  .stagger > *:nth-child(4) { animation-delay: 165ms; }
  .stagger > *:nth-child(5) { animation-delay: 220ms; }
  .stagger > *:nth-child(6) { animation-delay: 275ms; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

/* Explained empty state inside a card. Used where data legitimately does not exist yet
   (manual mode, pre-threshold) — the sentence says why, so blank never reads as bad news. */
.card__empty {
  margin: 0 var(--space-5) var(--space-4);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm); line-height: 1.55; color: var(--ink-muted);
  background: var(--glass-line); border-radius: var(--radius-md);
}
