/* ============================================================================
   UFUQ · أفق — app shell
   The phone surface: status bar, app bar, scrolling screen, tab bar.
   Screens are standalone HTML files, so the shell is CSS plus a little
   injection from shell.js rather than a framework.
   ========================================================================== */

body.app {
  display: flex; flex-direction: column;
  block-size: 100dvh; overflow: hidden;
  background: var(--surface-2);
  position: relative;
  overscroll-behavior: none;
}

/* On a desktop the standalone screen is centred at phone width with the page
   behind it darkened, so it reads as a device rather than as a broken site. */
@media (min-width: 480px) {
  body.app {
    inline-size: var(--phone-w); block-size: min(var(--phone-h), 100dvh);
    margin: max(0px, calc((100dvh - var(--phone-h)) / 2)) auto;
    border-radius: 28px; overflow: hidden;
    box-shadow: var(--e-3), 0 0 0 1px var(--line);
  }
  html:has(body.app) { background: var(--surface-sunk); min-block-size: 100dvh; }
}

/* ───────────────────────────────────────────────────────── status bar ───── */
.statusbar {
  flex: none; block-size: var(--statusbar);
  display: flex; align-items: center; justify-content: space-between;
  padding-inline: var(--s-6); padding-block-start: 6px;
  background: var(--bg);
  font-size: var(--t-dense); font-weight: 600; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.statusbar .sb-right { display: flex; align-items: center; gap: 5px; }
.statusbar svg { display: block; }

/* ────────────────────────────────────────────────────────── app bar ─────── */
.appbar {
  flex: none; min-block-size: var(--appbar);
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  background: var(--bg);
  border-block-end: 1px solid transparent;
  transition: border-color var(--d-hover) var(--ease-out), background-color var(--d-hover) var(--ease-out);
}
.appbar.is-stuck { border-block-end-color: var(--line); }
.appbar h1 { font-size: var(--t-h3); font-weight: 600; flex: 1; min-inline-size: 0; }
.appbar .ab-sub { font-size: var(--t-meta); color: var(--ink-3); font-weight: 400; display: block; margin-block-start: -1px; }
.appbar .ab-btn {
  display: grid; place-items: center; flex: none;
  inline-size: 38px; block-size: 38px; border-radius: var(--r);
  color: var(--ink-2); cursor: pointer;
  transition: background-color var(--d-hover) var(--ease-out), color var(--d-hover) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) { .appbar .ab-btn:hover { background: var(--surface-2); color: var(--ink); } }
.appbar .ab-btn:active { background: var(--surface-sunk); }
.appbar .ab-btn.has-dot { position: relative; }
.appbar .ab-btn.has-dot::after {
  content: ''; position: absolute; inset-block-start: 8px; inset-inline-end: 8px;
  inline-size: 7px; block-size: 7px; border-radius: 50%;
  background: var(--crit); border: 1.5px solid var(--bg);
}

/* ────────────────────────────────────────────────────────── screen ──────── */
.screen {
  flex: 1; min-block-size: 0; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: var(--s-4) var(--s-4) var(--s-9);
  background: var(--surface-2);
}
.screen > * + * { margin-block-start: var(--s-4); }
.screen.flush { padding-inline: 0; }
.screen.flush > * { margin-inline: var(--s-4); }
.screen.flush > .bleed { margin-inline: 0; }
.screen.on-bg { background: var(--bg); }

/* ────────────────────────────────────────────────────────── tab bar ─────── */
.tabbar {
  flex: none;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding-block: 6px calc(6px + var(--safe-bot));
  background: var(--bg); border-block-start: 1px solid var(--line);
}
.tabbar a {
  display: grid; justify-items: center; gap: 3px;
  padding-block: var(--s-1); min-block-size: 44px;
  color: var(--ink-3); font-size: var(--t-micro); font-weight: 500;
  transition: color var(--d-hover) var(--ease-out);
}
.tabbar a .ico { inline-size: 22px; block-size: 22px; }
.tabbar a[aria-current='page'] { color: var(--brand); font-weight: 600; }
@media (hover: hover) and (pointer: fine) { .tabbar a:hover { color: var(--ink-2); } }
.tabbar a:active { opacity: 0.65; }

/* The home indicator, purely so the frame reads as a phone. */
.tabbar::after {
  content: ''; position: absolute; inset-block-end: 8px; inset-inline: 0;
  inline-size: 128px; block-size: 4px; border-radius: 2px;
  background: var(--ink); opacity: 0.22; margin-inline: auto;
}

/* ────────────────────────────────────────────── hero balance block ──────── */
.hero-balance { padding: var(--s-3) var(--s-1) var(--s-5); }
.hero-balance .hb-label { font-size: var(--t-meta); color: var(--ink-3); font-weight: 500; }
.hero-balance .hb-value {
  font-size: var(--t-hero); font-weight: 600; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums; line-height: 1.05; margin-block-start: 2px;
  display: flex; align-items: baseline; gap: var(--s-2);
}
.hero-balance .hb-value .cur { font-size: var(--t-h3); font-weight: 500; color: var(--ink-3); letter-spacing: 0; }
.hero-balance .hb-note { display: flex; align-items: center; gap: var(--s-2); margin-block-start: var(--s-2); font-size: var(--t-dense); color: var(--ink-3); }

/* ───────────────────────────────────────────── forecast chart block ─────── */
.chart-block { padding: var(--s-2) 0 0; }
.chart-block .cb-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: 0 var(--s-4) var(--s-3); }
.chart-block .cb-body { padding-inline: var(--s-2); }
.chart-block .cb-foot { padding: var(--s-3) var(--s-4) var(--s-2); }

/* ─────────────────────────────────────────────────── calendar grid ──────── */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-dow { font-size: var(--t-micro); color: var(--ink-3); text-align: center; padding-block-end: var(--s-1); font-weight: 600; }
.cal-cell {
  aspect-ratio: 1; border-radius: var(--r-sm);
  display: grid; place-content: center start; gap: 1px;
  padding: 4px 5px; background: var(--surface-2);
  font-size: var(--t-micro); position: relative; cursor: pointer;
  transition: transform var(--d-press) var(--ease-out);
}
.cal-cell:active { transform: scale(0.94); }
.cal-cell .d { font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.cal-cell .b { font-size: 9px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.cal-cell.out { opacity: 0.35; }
.cal-cell.today { outline: 2px solid var(--brand); outline-offset: -2px; }
.cal-cell.lvl-ok   { background: var(--in-fill); }
.cal-cell.lvl-warn { background: var(--warn-fill); }
.cal-cell.lvl-crit { background: var(--crit-fill); }
.cal-cell.lvl-crit .d, .cal-cell.lvl-crit .b { color: var(--crit); }
.cal-cell .dots { position: absolute; inset-block-end: 3px; inset-inline-start: 5px; display: flex; gap: 2px; }
.cal-cell .dots i { inline-size: 3px; block-size: 3px; border-radius: 50%; background: var(--ink-4); }

/* ────────────────────────────────────── embedded app surface ────────────────
   The same phone surface as `body.app`, but as a container rather than the
   document — so a screen can be mounted inside the device frame on
   prototype.html with no <iframe>, and therefore no origin to violate when the
   folder is opened straight from disk. */
.app-embed {
  display: flex; flex-direction: column;
  inline-size: 100%; block-size: 100%;
  background: var(--surface-2);
  position: relative; overflow: hidden;
  border-radius: 36px;
  container-type: inline-size;
}
.app-embed .screen { overscroll-behavior: contain; }
@media (max-width: 460px) { .app-embed { border-radius: 28px; } }

/* ────────────────────────────────────────────────── device frame ────────── */
/* Used by index.html and prototype.html to host a screen in an iframe. */
.device {
  inline-size: calc(var(--phone-w) + 20px);
  block-size: calc(var(--phone-h) + 20px);
  padding: 10px; flex: none;
  background: linear-gradient(160deg, #2c2d38, #16171d 60%);   /* not-a-token: a phone chassis */
  border-radius: 46px;
  box-shadow: 0 40px 80px -30px rgba(10, 10, 16, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  position: relative;
}
.device::after {
  content: ''; position: absolute; inset-block-start: 22px; inset-inline: 0;
  inline-size: 110px; block-size: 26px; border-radius: 14px;
  background: #101015; margin-inline: auto; z-index: 2;        /* not-a-token: the notch */
}
.device iframe {
  inline-size: 100%; block-size: 100%; border: 0;
  border-radius: 36px; background: var(--bg); display: block;
}
.device-sm { transform: scale(0.72); transform-origin: top center; margin-block-end: -170px; }

@media (max-width: 460px) {
  .device { inline-size: 100%; block-size: auto; aspect-ratio: 390 / 844; padding: 8px; border-radius: 36px; }
  .device iframe { border-radius: 28px; }
  .device::after { inline-size: 90px; block-size: 22px; inset-block-start: 18px; }
}
