/* The Family Cloud design language, ported from the design handoff.
   (design bundle: family-cloud-apps/design; token source of truth:
   family-cloud-apps/contract/tokens.json)

   Rules that shape everything here:
   - Dark is the primary theme; light has full parity.
   - Gold = progress/premium, blue (the accent) = action, green = success.
     Flat brand fills are FILL-ONLY on dark; text/icons use the lifted pair.
   - Glass exists only on floating chrome; content panels, toasts and dialogs
     are opaque. Text is never a child of a distorting filter.
   - Plex Sans is content; Plex Mono is every number, size, speed, status word
     and kicker. Max weight 600. One springy easing curve for all motion.
   - Status is shape + word + motion, never colour alone. */

/* ---- Fonts -------------------------------------------------------------- */
@font-face {
  font-family: 'Plex Sans';
  src: url('/fonts/IBMPlexSans-var.woff2') format('woff2');
  font-weight: 100 700;
  font-display: swap;
}
@font-face {
  font-family: 'Plex Mono';
  src: url('/fonts/IBMPlexMono-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Plex Mono';
  src: url('/fonts/IBMPlexMono-600.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}

/* ---- Tokens: dark (primary) --------------------------------------------- */
:root {
  color-scheme: dark;
  --ca: #0F1923;            /* canvas / Ink */
  --pa: #16283A;            /* panel (opaque content surface) */
  --pa2: #1B3448;
  --pop: #14212E;           /* popover: dialogs + toasts */
  --ln: rgba(255, 255, 255, 0.09);
  --ln2: rgba(255, 255, 255, 0.17);
  --tx: #EAF0F6;
  --tx2: #A9BACB;
  --mu: #7E93A6;
  --sel: rgba(50, 90, 129, 0.24);
  --ok: #3FA97A;
  --bad: #E4756A;
  --go: #C9A961;            /* gold text/icon */
  --gof: #B29146;           /* gold fill */
  --te: #5FA98F;            /* teal text/icon */
  --tef: #0E483C;           /* teal fill */
  --bl: var(--accL, #7FA6CC);   /* accent text/icon */
  --blf: var(--acc, #325A81);   /* accent fill */
  --ph: rgba(255, 255, 255, 0.07);
  --scrim: rgba(6, 11, 16, 0.5);

  /* Glass: fills read the tier opacities glass.js sets (--glo/--glo2/--glo3);
     the backdrop-filter stacks (--bfx*) are owned by glass.js entirely. */
  --gl: rgba(13, 22, 31, var(--glo, 0.38));
  --gl2: rgba(16, 27, 38, var(--glo2, 0.6));
  --gl3: rgba(13, 22, 31, var(--glo3, 0.25));
  --hi: rgba(255, 255, 255, 0.45);
  --rim: rgba(255, 255, 255, 0.15);
  --spec: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.05) 34%, rgba(255, 255, 255, 0) 62%);
  --glass-shadow: 0 18px 44px rgba(0, 0, 0, 0.42);

  /* Type */
  --sans: 'Plex Sans', system-ui, sans-serif;
  --mono: 'Plex Mono', ui-monospace, monospace;

  /* Rhythm (Appearance settings override --rp and --ir) */
  --rp: 12px 15px;          /* row padding: comfortable */
  --ir: 12px;               /* icon-tile radius: rounded */
  --ease: cubic-bezier(0.2, 0.9, 0.24, 1);

  /* Chrome geometry */
  --tabbar-h: 62px;
  --appbar-h: 56px;
  --rail-w: 76px;
}

/* ---- Tokens: light parity ----------------------------------------------- */
[data-theme="light"] {
  color-scheme: light;
  --ca: #F2F5FA;
  --pa: #FFFFFF;
  --pa2: #F7F9FC;
  --pop: #FFFFFF;
  --ln: rgba(16, 24, 40, 0.08);
  --ln2: rgba(16, 24, 40, 0.13);
  --tx: #101828;
  --tx2: #344054;
  --mu: #667085;
  --sel: rgba(50, 90, 129, 0.1);
  --ok: #027A48;
  --bad: #B42318;
  --go: #8B6914;
  --te: #0E483C;
  --bl: var(--acc, #325A81);   /* on light, accent text = the fill colour */
  --ph: rgba(16, 24, 40, 0.06);
  --scrim: rgba(16, 24, 40, 0.34);
  --gl: rgba(255, 255, 255, calc(var(--glo, 0.38) + 0.06));
  --gl2: rgba(255, 255, 255, calc(var(--glo2, 0.6) + 0.08));
  --gl3: rgba(255, 255, 255, calc(var(--glo3, 0.25) + 0.09));
  --hi: rgba(255, 255, 255, 0.9);
  --rim: rgba(255, 255, 255, 0.7);
  --spec: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.2) 34%, rgba(255, 255, 255, 0) 62%);
  --glass-shadow: 0 12px 36px rgba(16, 24, 40, 0.14);
}

/* Auto theme: follow the system when no explicit choice is stamped. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]):not([data-theme="light"]) {
    color-scheme: light;
    --ca: #F2F5FA; --pa: #FFFFFF; --pa2: #F7F9FC; --pop: #FFFFFF;
    --ln: rgba(16, 24, 40, 0.08); --ln2: rgba(16, 24, 40, 0.13);
    --tx: #101828; --tx2: #344054; --mu: #667085;
    --sel: rgba(50, 90, 129, 0.1); --ok: #027A48; --bad: #B42318;
    --go: #8B6914; --te: #0E483C; --bl: var(--acc, #325A81);
    --ph: rgba(16, 24, 40, 0.06); --scrim: rgba(16, 24, 40, 0.34);
    --gl: rgba(255, 255, 255, calc(var(--glo, 0.38) + 0.06));
    --gl2: rgba(255, 255, 255, calc(var(--glo2, 0.6) + 0.08));
    --gl3: rgba(255, 255, 255, calc(var(--glo3, 0.25) + 0.09));
    --hi: rgba(255, 255, 255, 0.9); --rim: rgba(255, 255, 255, 0.7);
    --spec: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.2) 34%, rgba(255, 255, 255, 0) 62%);
    --glass-shadow: 0 12px 36px rgba(16, 24, 40, 0.14);
  }
}

/* ---- Accents (fill / on-dark text pairs) -------------------------------- */
[data-accent="0"] { --acc: #325A81; --accL: #7FA6CC; }  /* MorForm Blue */
[data-accent="1"] { --acc: #0288D1; --accL: #7FC4EE; }  /* Sky */
[data-accent="2"] { --acc: #388E3C; --accL: #7FC684; }  /* Green */
[data-accent="3"] { --acc: #B29146; --accL: #E0C57F; }  /* Gold */
[data-accent="4"] { --acc: #C94A0C; --accL: #F0956B; }  /* Orange */
[data-accent="5"] { --acc: #C0392B; --accL: #EE8D82; }  /* Red */
[data-accent="6"] { --acc: #7B2D8B; --accL: #C48BD0; }  /* Purple */
[data-accent="7"] { --acc: #455A64; --accL: #9FB3BD; }  /* Slate */

/* ---- Density & corners (user-selectable) -------------------------------- */
[data-density="compact"] { --rp: 8px 15px; }
[data-corners="square"] { --ir: 6px; }

/* ---- Glass Off: opaque panels, no filters, no specular ------------------ */
[data-gl="off"] {
  --gl: var(--pa);
  --gl2: var(--pa);
  --gl3: var(--pa);
  --hi: transparent;
  --rim: var(--ln2);
  --spec: none;
  --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* ---- Type utilities ------------------------------------------------------ */
.fc-display { font: 600 32px/1.15 var(--sans); letter-spacing: -0.022em; color: var(--tx); }
.fc-title { font: 600 21px/1.25 var(--sans); letter-spacing: -0.014em; color: var(--tx); }
.fc-item { font: 500 16px/1.35 var(--sans); color: var(--tx); }
.fc-body { font: 300 15px/1.6 var(--sans); color: var(--tx2); }
.fc-meta { font: 400 12.5px/1.4 var(--mono); color: var(--mu); }
.fc-label { font: 600 10.5px/1.3 var(--mono); letter-spacing: 0.13em; text-transform: uppercase; color: var(--mu); }

/* ---- Motion -------------------------------------------------------------- */
@keyframes fcSpin { to { transform: rotate(360deg); } }
@keyframes fcPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes fcFade { from { opacity: 0; } }
@keyframes fcRise { from { opacity: 0; transform: translateY(14px); } }
@keyframes fcSheet { from { transform: translateY(100%); } }
@keyframes fcPop { from { opacity: 0; transform: scale(0.92); } }
@keyframes fcShim { from { background-position: -200% 0; } to { background-position: 200% 0; } }

@media (prefers-reduced-motion: reduce) {
  .fc-tabbar, .fc-rail, .fc-pill, .fc-fab, .fc-sheet, .fc-toast { animation: none !important; }
}

/* ---- The glass surface base --------------------------------------------- */
/* One material everywhere; variants only choose the fill tier and which lens
   filter bends the backdrop. Children never sit under the filter (the filter
   applies to the BACKDROP); the specular sheen is its own overlay layer. */
.fc-glass {
  position: relative;
  background: var(--gl);
  border: 1px solid var(--rim);
  box-shadow: inset 0 1px 0 var(--hi), inset 0 -1px 0 rgba(0, 0, 0, 0.24), var(--glass-shadow);
  -webkit-backdrop-filter: var(--bfx, blur(2px) saturate(210%) brightness(1.06));
  backdrop-filter: var(--bfx, blur(2px) saturate(210%) brightness(1.06));
}
.fc-glass::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--spec);
  pointer-events: none;
}
.fc-glass--bar { -webkit-backdrop-filter: var(--bfxBar); backdrop-filter: var(--bfxBar); }
.fc-glass--pill { -webkit-backdrop-filter: var(--bfxPill); backdrop-filter: var(--bfxPill); }
.fc-glass--rail { -webkit-backdrop-filter: var(--bfxRail); backdrop-filter: var(--bfxRail); }
.fc-glass--sheet { background: var(--gl2); }
.fc-glass--transient { background: var(--gl3); }
[data-gl="off"] .fc-glass,
[data-gl="off"] .fc-glass--bar,
[data-gl="off"] .fc-glass--pill,
[data-gl="off"] .fc-glass--rail {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* ---- Bottom tab bar (phone chrome) --------------------------------------- */
.fc-tabbar {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  height: var(--tabbar-h);
  border-radius: 31px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 6px;
  z-index: 100;
  animation: fcRise 0.26s var(--ease);
}
.fc-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 64px;
  min-height: 48px;
  padding: 4px 10px;
  border: none;
  background: transparent;
  /* Owner feedback 08-15: icons over busy content were hard to read. The BAR
     keeps its translucency; the ICONS get the contrast - full secondary-text
     strength plus a soft dark halo that buys legibility on any backdrop. */
  color: var(--tx2);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
  font: 600 9.5px var(--mono);
  letter-spacing: 0.12em;
  cursor: pointer;
  border-radius: 15px;
  text-decoration: none;
}
.fc-tab.active { color: var(--bl); background: color-mix(in srgb, var(--blf) 22%, transparent); }
.fc-tab .fc-tabicon {
  width: 17px; height: 17px; border: 2px solid currentColor; border-radius: 5px; position: relative;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}
.fc-tab .fc-tabicon.round { border-radius: 50%; }
.fc-tab .fc-tabicon.inner::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: inherit;
  background: currentColor;
  opacity: 0.55;
}

/* ---- Desktop rail (the Windows adaptation, at web widths >=900px) -------- */
.fc-rail {
  position: fixed;
  left: 14px;
  top: 14px;
  bottom: 14px;
  width: var(--rail-w);
  border-radius: 24px;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 0;
  z-index: 100;
}
.fc-rail .fc-tab { min-width: 56px; }
.fc-rail .spacer { flex: 1; }

/* ---- Activity pill -------------------------------------------------------- */
.fc-pill {
  position: fixed;
  left: 18px;
  bottom: calc(12px + var(--tabbar-h) + 14px + env(safe-area-inset-bottom));
  height: 44px;
  border-radius: 22px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 0 16px 0 12px;
  border-color: var(--rim);
  color: var(--tx);
  font: 600 10.5px var(--mono);
  letter-spacing: 0.12em;
  cursor: pointer;
  z-index: 100;
  animation: fcRise 0.26s var(--ease);
}

/* ---- FAB ------------------------------------------------------------------ */
.fc-fab {
  position: fixed;
  right: 18px;
  bottom: calc(12px + var(--tabbar-h) + 14px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 20px;
  border: 1px solid color-mix(in srgb, var(--gof) 60%, transparent);
  background: radial-gradient(120% 120% at 30% 20%, color-mix(in srgb, #fff 22%, var(--gof)), var(--gof));
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.5), 0 14px 34px rgba(0, 0, 0, 0.4);
  color: #0F1923;
  font: 300 30px/1 var(--sans);
  cursor: pointer;
  z-index: 100;
  display: grid;
  place-items: center;
}

/* ---- App bar -------------------------------------------------------------- */
.fc-appbar {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--appbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-left: none;
  border-right: none;
  border-top: none;
}

/* ---- Status shapes (colour-independent by design) ------------------------- */
.fc-status { display: inline-flex; align-items: center; gap: 8px; font: 600 10.5px var(--mono); letter-spacing: 0.1em; }
.fc-status .shape { width: 14px; height: 14px; flex: none; position: relative; }
.fc-status.synced { color: var(--ok); }
.fc-status.synced .shape { border-radius: 50%; background: currentColor; }
.fc-status.synced .shape::after { content: ''; position: absolute; left: 4px; top: 3px; width: 5px; height: 8px; border: solid var(--ca); border-width: 0 1.8px 1.8px 0; transform: rotate(42deg); }
.fc-status.syncing { color: var(--go); }
.fc-status.syncing .shape { border-radius: 50%; border: 2px solid currentColor; border-top-color: transparent; animation: fcSpin 1.1s linear infinite; }
.fc-status.waiting { color: var(--mu); }
.fc-status.waiting .shape { border-radius: 50%; border: 2px dashed currentColor; animation: fcPulse 2.4s ease infinite; }
.fc-status.paused { color: var(--mu); }
.fc-status.paused .shape { border-radius: 3px; border: 2px solid currentColor; }
.fc-status.paused .shape::after { content: ''; position: absolute; left: 3px; top: 2.5px; width: 5px; height: 6px; border-left: 1.6px solid currentColor; border-right: 1.6px solid currentColor; }
.fc-status.failed { color: var(--bad); }
.fc-status.failed .shape { width: 0; height: 0; border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 13px solid currentColor; background: none; }

/* ---- Buttons -------------------------------------------------------------- */
.fc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid var(--ln2);
  background: var(--pa2, var(--pa));
  color: var(--tx);
  font: 600 15px var(--sans);
  cursor: pointer;
}
.fc-btn--primary { background: var(--blf); border-color: transparent; color: #fff; }
.fc-btn--danger { background: transparent; border-color: color-mix(in srgb, var(--bad) 45%, transparent); color: var(--bad); }
.fc-btn--big { min-height: 56px; border-radius: 16px; width: 100%; }

/* ---- Toast (opaque by rule) ----------------------------------------------- */
.fc-toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(12px + var(--tabbar-h) + 84px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px 12px 12px;
  border-radius: 16px;
  background: var(--pop);
  border: 1px solid var(--ln2);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.4);
  color: var(--tx);
  font: 500 14px var(--sans);
  z-index: 200;
  animation: fcRise 0.24s var(--ease);
}
.fc-toast .tick {
  width: 18px; height: 18px; border-radius: 6px; background: var(--ok); position: relative; flex: none;
}
.fc-toast .tick::after { content: ''; position: absolute; left: 6px; top: 3px; width: 5px; height: 9px; border: solid #fff; border-width: 0 1.8px 1.8px 0; transform: rotate(42deg); }

/* ---- Responsive shell switch ---------------------------------------------- */
/* Under 900px: phone chrome (tab bar + pill + FAB). At 900px and up: the rail
   takes over, content gets a left gutter, and the phone chrome hides. */
@media (min-width: 900px) {
  .fc-tabbar { display: none; }
  .fc-rail { display: flex; }
  body.fc-shell { padding-left: calc(var(--rail-w) + 28px); }
  .fc-pill { left: auto; right: 18px; bottom: 18px; }
  .fc-fab { display: none; }  /* desktop uploads use the rail button + drag-drop */
}
body.fc-shell { padding-bottom: calc(var(--tabbar-h) + 40px + env(safe-area-inset-bottom)); }
@media (min-width: 900px) { body.fc-shell { padding-bottom: 24px; } }

/* The shell supersedes the old design's mobile bottom nav entirely - with
   both alive, its three buttons sat trapped behind the glass bar (reported
   from the phone). One navigation system at a time. */
body.fc-shell .bottom-nav { display: none !important; }
