/* Ordentus iOS — Health tab
   Screen-level styles. The iOS frame paints the bezel; everything inside
   uses these tokens. We define both light and dark in one file via a
   `data-theme="dark"` attribute on the frame root. */

@import url("../colors_and_type.css");

/* Reset within frame */
.io,
.io *,
.io *::before,
.io *::after {
  box-sizing: border-box;
}

/* ── Theme variables, scoped to the frame root ───────────────── */
.io {
  /* ios system grays (light) */
  --io-bg: #F2F2F7;
  --io-bg-elev: #FFFFFF;
  --io-bg-grouped: #F2F2F7;
  --io-bg-tertiary: #FFFFFF;
  --io-fill-thin: rgba(120,120,128,.12);
  --io-fill-quaternary: rgba(116,116,128,.08);
  --io-fill-tertiary: rgba(118,118,128,.12);
  --io-separator: rgba(60,60,67,.12);
  --io-separator-opaque: #C6C6C8;

  --io-label: #1D1D1F;
  --io-label-secondary: rgba(60,60,67,.6);
  --io-label-tertiary: rgba(60,60,67,.3);
  --io-label-quaternary: rgba(60,60,67,.18);

  /* Apple semantic — same hex both modes */
  --io-blue: #007AFF;
  --io-red: #FF3B30;
  --io-orange: #FF9500;
  --io-yellow: #FFCC00;
  --io-green: #34C759;
  --io-teal: #5AC8FA;
  --io-indigo: #5E5CE6;
  --io-purple: #AF52DE;
  --io-pink: #FF2D55;

  /* health domains */
  --io-sleep: #AF52DE;
  --io-heart: #FF3B30;
  --io-activity: #34C759;
  --io-bedtime: #5E5CE6;
  --io-quality: #FF9500;

  /* sleep stage scale */
  --io-stage-deep: #3B3B8B;
  --io-stage-rem: #7C7CE0;
  --io-stage-core: #A8A8F0;
  --io-stage-awake: #E5E5F5;

  /* bedtime gradient — light */
  --io-grad-bedtime: linear-gradient(135deg, #1B1464 0%, #2D1B69 100%);
  --io-grad-bedtime-deep:
    radial-gradient(120% 60% at 80% -20%, rgba(94,92,230,.55), transparent 60%),
    radial-gradient(80% 80% at 10% 120%, rgba(175,82,222,.45), transparent 60%),
    linear-gradient(135deg, #1B1464 0%, #2D1B69 55%, #1B1464 100%);

  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", system-ui, sans-serif;
  color: var(--io-label);
  background: var(--io-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
}

.io[data-theme="dark"] {
  --io-bg: #000000;
  --io-bg-elev: #1C1C1E;
  --io-bg-grouped: #000000;
  --io-bg-tertiary: #2C2C2E;
  --io-fill-thin: rgba(120,120,128,.36);
  --io-fill-quaternary: rgba(118,118,128,.24);
  --io-fill-tertiary: rgba(118,118,128,.32);
  --io-separator: rgba(84,84,88,.65);
  --io-separator-opaque: #38383A;

  --io-label: #FFFFFF;
  --io-label-secondary: rgba(235,235,245,.6);
  --io-label-tertiary: rgba(235,235,245,.3);
  --io-label-quaternary: rgba(235,235,245,.18);

  /* bedtime gradient — dark (deepened per brief) */
  --io-grad-bedtime: linear-gradient(135deg, #0F0A3A 0%, #1B1464 100%);
  --io-grad-bedtime-deep:
    radial-gradient(120% 60% at 80% -20%, rgba(94,92,230,.7), transparent 60%),
    radial-gradient(80% 80% at 10% 120%, rgba(175,82,222,.55), transparent 60%),
    linear-gradient(135deg, #0F0A3A 0%, #1B1464 55%, #0F0A3A 100%);

  background: var(--io-bg);
  color: var(--io-label);
}

/* ── Tabular numerals everywhere a number lives ──────────────── */
.io .num,
.io [data-num] { font-variant-numeric: tabular-nums; }

/* ── Type ramp (iOS dynamic-type anchors, fixed-px shorthand) ── */
.io .lt   { font-size: 34px; font-weight: 700; letter-spacing: 0.4px; line-height: 1.05; }
.io .t1   { font-size: 28px; font-weight: 700; letter-spacing: 0.36px; line-height: 1.15; }
.io .t2   { font-size: 22px; font-weight: 600; letter-spacing: 0.35px; line-height: 1.18; }
.io .t3   { font-size: 20px; font-weight: 600; letter-spacing: 0.38px; line-height: 1.2; }
.io .hd   { font-size: 17px; font-weight: 600; letter-spacing: -0.4px; line-height: 1.3; }
.io .bd   { font-size: 17px; font-weight: 400; letter-spacing: -0.4px; line-height: 1.35; }
.io .ca   { font-size: 16px; font-weight: 400; letter-spacing: -0.32px; line-height: 1.3; }
.io .sh   { font-size: 15px; font-weight: 400; letter-spacing: -0.24px; line-height: 1.3; }
.io .fn   { font-size: 13px; font-weight: 400; letter-spacing: -0.08px; line-height: 1.3; }
.io .cp   { font-size: 12px; font-weight: 400; letter-spacing: 0; line-height: 1.3; }
.io .cp2  { font-size: 11px; font-weight: 400; line-height: 1.3; }

.io .eyebrow {
  font-size: 12px; font-weight: 600; line-height: 1.2;
  text-transform: uppercase; letter-spacing: 0.85px;
  color: var(--io-label-secondary);
}

/* Hero-metric scale — bigger = lighter weight, tighter tracking */
.io .m-hero   { font-size: 64px; font-weight: 200; letter-spacing: -2.4px; line-height: 1; font-variant-numeric: tabular-nums; }
.io .m-xl     { font-size: 54px; font-weight: 200; letter-spacing: -1.8px; line-height: 1; font-variant-numeric: tabular-nums; }
.io .m-lg     { font-size: 44px; font-weight: 300; letter-spacing: -1.2px; line-height: 1; font-variant-numeric: tabular-nums; }
.io .m-md     { font-size: 32px; font-weight: 400; letter-spacing: -0.6px; line-height: 1; font-variant-numeric: tabular-nums; }
.io .m-sm     { font-size: 22px; font-weight: 500; letter-spacing: -0.3px; line-height: 1; font-variant-numeric: tabular-nums; }
.io .m-unit   { font-weight: 300; opacity: .6; letter-spacing: 0; }

/* ── Cards ───────────────────────────────────────────────────── */
.io .card {
  background: var(--io-bg-elev);
  border-radius: 16px;
}
.io .card.padded { padding: 16px; }
.io .card.pill { border-radius: 22px; }

/* iOS continuous corners */
.io .card,
.io .card.pill,
.io .iosqu {
  -webkit-mask-image: -webkit-radial-gradient(white, black); /* clip antialias hack */
}

/* ── Tab bar ─────────────────────────────────────────────────── */
.io .tabbar {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 6px 8px 28px;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255,255,255,.78);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border-top: 0.5px solid var(--io-separator);
  z-index: 30;
}
.io[data-theme="dark"] .tabbar {
  background: rgba(28,28,30,.78);
  border-top-color: var(--io-separator);
}
.io .tabbar .tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0 4px;
  color: var(--io-label-tertiary);
}
.io .tabbar .tab .ic { width: 26px; height: 26px; display: grid; place-items: center; }
.io .tabbar .tab .lb { font-size: 10px; font-weight: 600; letter-spacing: 0.15px; }
.io .tabbar .tab.active { color: var(--io-blue); }

/* ── Section header within a screen ──────────────────────────── */
.io .secthd {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 22px 20px 8px;
}
.io .secthd .lhs { display:flex; align-items: baseline; gap: 10px; }
.io .secthd .lhs .t2 { letter-spacing: -0.45px; }
.io .secthd .ico { width: 22px; height: 22px; display:inline-grid; place-items:center; }
.io .secthd .see { color: var(--io-blue); font-size: 15px; font-weight: 400; letter-spacing: -0.24px; }

/* Bedtime hero — inset (Health root) */
.io .bedtime-inset {
  margin: 6px 16px 0;
  padding: 22px 22px 20px;
  border-radius: 22px;
  background: var(--io-grad-bedtime-deep);
  color: #fff;
  position: relative; overflow: hidden;
  box-shadow: 0 16px 40px -16px rgba(20,18,12,.45);
}
.io .bedtime-inset::after,
.io .bedtime-full::after {
  content:""; position:absolute; inset:0; pointer-events:none; opacity:.7;
  background:
    radial-gradient(1.2px 1.2px at 12% 22%, #fff 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 22% 68%, rgba(255,255,255,.7) 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 42% 18%, rgba(255,255,255,.6) 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 62% 38%, rgba(255,255,255,.5) 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 78% 28%, #fff 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 88% 62%, rgba(255,255,255,.7) 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 35% 82%, rgba(255,255,255,.5) 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 70% 88%, rgba(255,255,255,.4) 50%, transparent 51%);
}
.io .bedtime-inset > *, .io .bedtime-full > * { position: relative; z-index: 1; }

/* Bedtime full-bleed (detail screen) */
.io .bedtime-full {
  position: absolute; inset: 0; padding: 0;
  background: var(--io-grad-bedtime-deep);
  color: #fff;
  z-index: 0;
}

/* Metric tile row */
.io .m-row {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  padding: 0 16px;
}
.io .m-row.three { grid-template-columns: repeat(3, 1fr); }

.io .tile {
  background: var(--io-bg-elev);
  border-radius: 18px;
  padding: 14px 14px 12px;
  display: flex; flex-direction: column; gap: 6px;
  min-height: 110px;
  position: relative;
}
.io .tile .head {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; letter-spacing: -0.08px;
}
.io .tile .head .dot { width: 8px; height: 8px; border-radius: 50%; }
.io .tile .head .lb { color: var(--io-label); }
.io .tile .head .ic { display:inline-grid; place-items:center; margin-left:auto; opacity:.5; }
.io .tile .val { display: flex; align-items: baseline; gap: 4px; margin-top: 2px; }
.io .tile .trend { font-size: 12px; font-weight: 500; display:inline-flex; align-items:center; gap:3px; }
.io .tile .ctx { font-size: 12px; color: var(--io-label-secondary); }

/* Trend chip arrows */
.io .trend.up   { color: var(--io-red); }
.io .trend.down { color: var(--io-green); }
.io .trend.flat { color: var(--io-label-secondary); }

/* Ring chart */
.io .ring { position: relative; }
.io .ring .v { position: absolute; inset: 0; display:grid; place-items: center; text-align:center; }

/* Stage stack (sleep stages) */
.io .stage-row { display: flex; height: 30px; border-radius: 6px; overflow: hidden; }
.io .stage-row span { display: block; height: 100%; }

/* Consistency dots */
.io .dots { display: inline-flex; gap: 5px; }
.io .dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--io-fill-tertiary); }
.io .dots i.on { background: var(--io-purple); }

/* Segmented control (iOS) */
.io .seg {
  background: var(--io-fill-tertiary);
  border-radius: 10px;
  padding: 2px;
  display: inline-flex;
  font-size: 13px; font-weight: 500;
  width: 100%;
}
.io .seg .s {
  flex: 1; padding: 6px 10px; border-radius: 8px; text-align: center;
  color: var(--io-label-secondary); letter-spacing: -0.08px;
}
.io .seg .s.on {
  background: var(--io-bg-elev);
  color: var(--io-label);
  box-shadow: 0 3px 8px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
.io[data-theme="dark"] .seg .s.on { background: #636366; color: #fff; box-shadow:none; }

/* Insight cards */
.io .insight {
  background: var(--io-bg-elev);
  border-radius: 18px;
  padding: 14px 16px;
  display: flex; gap: 12px; align-items: flex-start;
}
.io .insight .ic {
  width: 32px; height: 32px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--io-fill-tertiary);
  flex-shrink: 0;
}
.io .insight .ic.em { background: transparent; font-size: 22px; }

/* List row (Settings-style) */
.io .lrow {
  min-height: 44px;
  padding: 11px 16px;
  display: flex; align-items: center; gap: 12px;
}
.io .lrow + .lrow { border-top: 0.5px solid var(--io-separator); }
.io .lrow .li-ic { width: 28px; height: 28px; border-radius: 7px; display:grid; place-items:center; color:#fff; }
.io .lrow .li-ti { flex: 1; font-size: 17px; letter-spacing: -0.4px; }
.io .lrow .li-de { color: var(--io-label-secondary); font-size: 17px; letter-spacing: -0.4px; }
.io .lrow .li-ch { color: var(--io-label-tertiary); }

/* Banners */
.io .banner {
  margin: 8px 16px 0;
  padding: 10px 12px;
  border-radius: 12px;
  display: flex; gap: 10px; align-items: center;
  font-size: 13px; letter-spacing: -0.08px;
}
.io .banner.warn  { background: rgba(255,149,0,.14);  color: #9F5A00; }
.io .banner.err   { background: rgba(255,59,48,.12);  color: #B5251F; }
.io .banner.off   { background: rgba(118,118,128,.16); color: var(--io-label); }
.io[data-theme="dark"] .banner.warn { color: #FFB85C; }
.io[data-theme="dark"] .banner.err  { color: #FF6961; }

/* Sheet (bottom) */
.io .sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--io-bg-elev);
  border-radius: 22px 22px 0 0;
  padding: 14px 0 36px;
  z-index: 40;
  box-shadow: 0 -10px 40px rgba(0,0,0,.18);
}
.io .sheet .grabber {
  width: 36px; height: 5px; border-radius: 3px;
  background: var(--io-label-tertiary);
  margin: 0 auto 10px;
}
.io[data-theme="dark"] .sheet { background: #1C1C1E; }

/* Modal */
.io .modal-scrim {
  position:absolute; inset:0; background: rgba(0,0,0,.32);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  z-index: 50; display:grid; place-items:center; padding: 0 28px;
}
.io[data-theme="dark"] .modal-scrim { background: rgba(0,0,0,.55); }
.io .modal {
  width: 100%; max-width: 270px; background: var(--io-bg-elev);
  border-radius: 14px; overflow: hidden;
  text-align: center;
}
.io[data-theme="dark"] .modal { background: #2C2C2E; }
.io .modal .body { padding: 18px 16px 16px; }
.io .modal .acts { display:flex; border-top: 0.5px solid var(--io-separator); }
.io .modal .acts > * { flex: 1; padding: 11px 8px; font-size: 17px; letter-spacing: -0.4px; color: var(--io-blue); }
.io .modal .acts > * + * { border-left: 0.5px solid var(--io-separator); }
.io .modal .acts .destr { color: var(--io-red); }
.io .modal .acts .bold { font-weight: 600; }

/* Skeleton */
.io .sk {
  background: var(--io-fill-tertiary);
  border-radius: 6px;
  animation: io-pulse 1.4s ease-in-out infinite;
}
@keyframes io-pulse {
  0%, 100% { opacity: 0.65; }
  50%      { opacity: 1; }
}

/* Bar chart */
.io .bars {
  display: grid; grid-template-columns: repeat(7, 1fr);
  align-items: end; gap: 12px;
  height: 130px;
  padding: 4px 4px 0;
  position: relative;
}
.io .bars .bar {
  background: var(--io-purple);
  border-radius: 4px 4px 2px 2px;
  width: 100%;
  position: relative;
}
.io .bars .bar.today { background: var(--io-purple); }
.io .bars .bar.under { background: var(--io-orange); }
.io .bars .goal-line {
  position: absolute; left: 0; right: 0;
  border-top: 1px dashed var(--io-label-tertiary);
}
.io .bars .goal-lbl { position:absolute; right:0; font-size: 10px; color: var(--io-label-tertiary); }
.io .bar-labels {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 12px;
  padding: 6px 4px 0;
}
.io .bar-labels span { text-align: center; font-size: 11px; color: var(--io-label-secondary); }

/* Horizontal bars (cognitive overview) */
.io .hbar { display: grid; grid-template-columns: 1fr; gap: 10px; }
.io .hbar-row { display: grid; grid-template-columns: 88px 1fr 44px; gap: 8px; align-items: center; }
.io .hbar-row .lb { font-size: 13px; color: var(--io-label); letter-spacing: -0.08px; }
.io .hbar-row .v  { font-size: 13px; color: var(--io-label-secondary); text-align: right; font-variant-numeric: tabular-nums; }
.io .hbar-row .track { height: 10px; border-radius: 5px; background: var(--io-fill-tertiary); position:relative; overflow:hidden; }
.io .hbar-row .fill  { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; }

/* Avatar (large-title trailing) */
.io .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #5E5CE6, #AF52DE);
  font-size: 13px; font-weight: 600;
}

/* Scrubber for chart */
.io .scrub {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: var(--io-label-tertiary);
}
.io .scrub .b { position: absolute; top: -2px; left: -3px; width: 7px; height: 7px; border-radius:50%; background: var(--io-label-secondary); }
.io .scrub-label {
  position: absolute; transform: translateX(-50%);
  padding: 4px 8px; border-radius: 8px;
  background: var(--io-bg-elev);
  font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.1);
}
.io[data-theme="dark"] .scrub-label { background: #2C2C2E; box-shadow: 0 4px 14px rgba(0,0,0,.5); }

/* Misc */
.io .row { display:flex; align-items:center; gap: 8px; }
.io .between { display:flex; align-items:center; justify-content:space-between; }
.io .stack { display:flex; flex-direction: column; }
.io .pill {
  display:inline-flex; align-items:center; gap: 4px;
  padding: 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.io .pill.heavy { background: rgba(255,59,48,.14); color: #B5251F; }
.io .pill.mid   { background: rgba(255,149,0,.16); color: #9F5A00; }
.io .pill.low   { background: rgba(52,199,89,.16); color: #1F8B3D; }
.io .pill.info  { background: rgba(0,122,255,.12); color: var(--io-blue); }
.io[data-theme="dark"] .pill.heavy { color: #FF7B70; }
.io[data-theme="dark"] .pill.mid   { color: #FFB85C; }
.io[data-theme="dark"] .pill.low   { color: #5BD377; }

/* Page-edge breathing room above tab bar */
.io .scroll-pad { height: 96px; }

/* Custom nav title row when not using IOSNavBar */
.io .navrow {
  display: flex; align-items: center; justify-content: space-between;
  padding: 56px 12px 0;
}
.io .navrow .pill-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(120,120,128,.16);
  backdrop-filter: blur(20px);
  color: var(--io-label);
}
.io[data-theme="dark"] .navrow .pill-btn { background: rgba(120,120,128,.36); }

/* Big title row (replaces IOSNavBar large-title for custom content) */
.io .biglt {
  padding: 8px 20px 8px;
  display: flex; align-items: flex-end; justify-content: space-between;
}
.io .biglt h1 { font-size: 34px; font-weight: 700; letter-spacing: 0.4px; line-height: 1.05; margin:0; }

/* Tab-bar safe spacer for sheet contents */
.io .sheet-inner { padding: 0 16px; }

/* Hide scrollbars inside frames */
.io ::-webkit-scrollbar { width: 0; height: 0; }
