/* =====================================================================
 * shell.css — iOS-themed shell layer (UI refactor, Phase 1 foundation)
 *
 * This is the long-lived foundation: an iOS-style shell that hosts
 * discrete apps (Messages / Phone / Photos / Calendar / Settings) plus
 * system-level interrupts (incoming call overlay, notification banners).
 *
 * The shell is the BASE layer. It deliberately sits at a low stacking
 * level so the existing wrap-mode overlays continue to cover it
 * unchanged:
 *   #shell        z-index: 1     (this file)
 *   info/upcoming z-index: 60    (legacy panels, migrated in later phases)
 *   date-mode     z-index: 80    (wrap mode, owned by date terminal)
 *   auth modal    z-index: 100   (still a top-level modal)
 *   photo-lightbox z-index: 200
 *
 * Because #shell establishes its own stacking context at z-index:1, none
 * of its internal layers (apps, call overlay, banners) can ever paint
 * over a wrap mode. That is the intended contract.
 * ===================================================================== */

/* ---------- iOS design tokens ----------
 * Namespaced with --ios- so they never collide with the existing
 * --blue / --gray-* tokens the Messages chrome already uses. */
:root {
  /* Palette */
  --ios-blue: #0A84FF;
  --ios-green: #34C759;
  --ios-red: #FF3B30;
  --ios-gray: #8E8E93;

  /* Home-screen wallpaper: deep, slightly warm graphite gradient. */
  --ios-home-bg: radial-gradient(120% 90% at 50% 0%, #2a2a32 0%, #18181c 45%, #0a0a0c 100%);

  /* App-chrome surfaces (in-app top bars, list rows). Light by default,
   * dark under prefers-color-scheme: dark (handled below). */
  --ios-chrome-bg: rgba(249, 249, 249, 0.94);
  --ios-chrome-text: #000000;
  --ios-chrome-hairline: rgba(60, 60, 67, 0.29);
  --ios-app-bg: #ffffff;

  /* Typography */
  --ios-font: "SF Pro Display", "SF Pro Text", -apple-system,
              BlinkMacSystemFont, system-ui, "Segoe UI", sans-serif;

  /* Spacing scale (4pt grid) */
  --ios-sp-1: 4px;
  --ios-sp-2: 8px;
  --ios-sp-3: 12px;
  --ios-sp-4: 16px;
  --ios-sp-5: 20px;
  --ios-sp-6: 24px;

  /* Radii */
  --ios-radius-tile: 14px;   /* app-icon squircle (~22% of a 60px tile) */
  --ios-radius-sheet: 12px;  /* modal sheet top corners */
  --ios-radius-card: 10px;

  /* Motion */
  --ios-ease: cubic-bezier(0.32, 0.72, 0, 1);  /* iOS spring-ish */
  --ios-app-anim: 360ms;

  /* Status bar + home indicator metrics */
  --ios-statusbar-h: 44px;
  --ios-home-indicator-h: 34px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ios-chrome-bg: rgba(28, 28, 30, 0.94);
    --ios-chrome-text: #ffffff;
    --ios-chrome-hairline: rgba(84, 84, 88, 0.4);
    --ios-app-bg: #000000;
  }
}

/* Hide the legacy chat root while the shell owns the screen. Phase 2
 * lifts the chat into the Messages app and removes this. #app uses an id
 * selector with display:flex, so we need !important to win the cascade. */
#app.shell-app-hidden { display: none !important; }

/* ---------- Shell root ---------- */
.shell {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  font-family: var(--ios-font);
  background: var(--ios-home-bg);
  color: #fff;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.shell.hidden { display: none; }

/* ---------- The stage: holds home screen + sliding app container ---------- */
.shell-stage {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
  /* Pull up under the status bar so the home wallpaper bleeds behind it,
   * matching iOS. The status bar is a sibling above in flow, but the
   * wallpaper continuity is purely cosmetic via the shared background. */
}

/* ---------- Home screen ---------- */
.home-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  /* Top padding clears the device's real iOS status bar. */
  padding: calc(env(safe-area-inset-top) + 28px) 16px 0;
  transition: transform var(--ios-app-anim) var(--ios-ease),
              opacity var(--ios-app-anim) var(--ios-ease),
              filter var(--ios-app-anim) var(--ios-ease);
}
/* When an app launches, the home screen recedes slightly (iOS depth). */
.shell.app-active .home-screen {
  transform: scale(0.92);
  opacity: 0;
  filter: blur(2px);
  pointer-events: none;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px 12px;
  max-width: 460px;
  width: 100%;
  margin: 0 auto;
}

.app-icon {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 120ms ease, opacity 120ms ease;
}
.app-icon:active { transform: scale(0.9); opacity: 0.8; }

.icon-tile {
  width: 60px;
  height: 60px;
  border-radius: var(--ios-radius-tile);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.icon-tile svg { display: block; }

.icon-label {
  font-size: 11px;
  font-weight: 400;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  line-height: 1;
  max-width: 68px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Canonical iOS icon tiles */
.icon-phone    { background: linear-gradient(180deg, #5df07a 0%, #2cc14e 100%); }
.icon-messages { background: linear-gradient(180deg, #3aa0ff 0%, #0a6cff 100%); }
.icon-photos   { background: #ffffff; }
.icon-calendar { background: #ffffff; position: relative; }
.icon-settings { background: linear-gradient(180deg, #c9ccd1 0%, #8d9199 100%); }

/* Calendar glyph: red weekday over a large dark day number. */
.icon-calendar .cal-dow {
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--ios-red);
  text-transform: uppercase;
}
.icon-calendar .cal-num {
  margin-top: 8px;
  font-size: 30px;
  font-weight: 300;
  color: #1c1c1e;
  line-height: 1;
}

/* Page indicator dots */
.page-dots {
  display: flex;
  justify-content: center;
  gap: 7px;
  margin-top: auto;
  padding-bottom: calc(var(--ios-home-indicator-h) + 6px);
}
.page-dots .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
}
.page-dots .dot.active { background: rgba(255, 255, 255, 0.9); }

/* ---------- App container (slides in from the right) ---------- */
.app-container {
  position: absolute;
  inset: 0;
  background: var(--ios-app-bg);
  transform: translateX(100%);
  transition: transform var(--ios-app-anim) var(--ios-ease);
  display: flex;
  flex-direction: column;
  will-change: transform;
}
.shell.app-active .app-container { transform: translateX(0); }
/* When idle (home), keep it out of the layout for hit-testing. */
.app-container:not(.mounted) { visibility: hidden; }

/* Individual app screens stack inside the container; only the active one
 * is shown. Each owns an in-app top bar + a content area. */
.app-screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--ios-app-bg);
  color: var(--ios-chrome-text);
}
.app-screen.active { display: flex; }

/* iOS in-app top bar: small centered title, Done/Back nav, hairline.
 * Top padding clears the device's real status bar. */
.app-topbar {
  flex: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(44px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 8px 0;
  background: var(--ios-chrome-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--ios-chrome-hairline);
}
.app-topbar .app-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--ios-chrome-text);
}
.app-topbar .app-nav {
  position: absolute;
  top: env(safe-area-inset-top);
  bottom: 0;
  display: flex;
  align-items: center;
  font-size: 17px;            /* iOS nav-button text size (was oversized) */
  line-height: 1;
  color: var(--ios-blue);
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 0 10px;
  z-index: 2;
}
.app-topbar .app-nav.left { left: 8px; }
/* The bare back chevron reads as a glyph, so it gets sized up vs text nav. */
.messages-topbar .app-nav.left { font-size: 40px; font-weight: 300; padding: 0 8px; }
.app-topbar .app-nav.right { right: 8px; }
.app-topbar .app-nav:active { opacity: 0.4; }

/* ---------- Messages conversation top bar ---------- */
/* Stacked avatar + name centered (iOS conversation header), tappable to
 * open the contact card. The left chevron returns to the home screen. */
/* Taller conversation header (iOS Messages proportions). Height is sized to
 * fully clear the avatar + name below the device status bar with margin, so
 * neither clips against the top of the screen or the bar's bottom edge. */
.messages-topbar { height: calc(84px + env(safe-area-inset-top)); }
.messages-contact {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: none;
  padding: 2px 8px;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 120ms ease;
}
.messages-contact:active { opacity: 0.5; }
.messages-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--gray-bubble);
}
.messages-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--ios-chrome-text);
  line-height: 1.2;
}
.messages-chevron { color: var(--ios-gray); font-weight: 400; }

/* The lifted chat fills the Messages screen: #messages scrolls, the
 * composer sits at the bottom. Both keep their existing styles.css rules;
 * we only ensure the flex sizing works inside .app-screen. */
.app-screen[data-app="messages"] #messages { flex: 1 1 auto; min-height: 0; }
.app-screen[data-app="messages"] #composer-bar { flex: none; }

/* Stub content (Phase 1): centered app name. Real content lands later. */
.app-content {
  flex: 1 1 auto;
  overflow: hidden;
  position: relative;
}
.app-stub {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  color: var(--ios-gray);
}

/* ---------- Settings app (dev mode call unlock) ---------- */
.settings-list {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 0 32px;
  background: #f2f2f7;
}
.settings-section {
  margin: 24px 0;
}
.settings-section-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--ios-gray);
  padding: 0 16px 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  padding: 12px 16px;
  font-size: 17px;
  border-bottom: 1px solid rgba(60, 60, 67, 0.12);
}
.settings-row:last-of-type {
  border-bottom: none;
}
.settings-row-label {
  color: #000;
  flex: 1 1 auto;
}
.settings-row-value {
  color: var(--ios-gray);
  font-size: 15px;
}
body.dev-mode .settings-row-value#settings-dev-status {
  color: #ff7a00;
  font-weight: 600;
}
.settings-row-button {
  padding: 8px 16px;
}
.settings-action-btn {
  width: 100%;
  border: none;
  background: #007aff;
  color: #fff;
  font-size: 17px;
  font-weight: 500;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
}
.settings-action-btn:active {
  opacity: 0.7;
}
.settings-action-btn[disabled] {
  background: var(--ios-gray);
  cursor: default;
  opacity: 0.55;
}
.settings-row-note {
  font-size: 13px;
  color: var(--ios-gray);
  padding: 8px 16px 0;
  line-height: 1.35;
}
/* Hide the force-call row + note when not in dev mode. The section
   itself stays so the "Inactive" status is still visible. */
body:not(.dev-mode) #settings-force-call-row,
body:not(.dev-mode) #settings-dev-note {
  display: none;
}

/* Settings additions (Phase 6): Account token row + Milestones. Reuse the
   main terminal's .settings-list / .settings-section / .settings-row. */
.settings-row-tappable {
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid rgba(60, 60, 67, 0.12);
  font-family: inherit;
  cursor: pointer;
}
.settings-row-tappable:active { background: #e9e9ee; }
.settings-token-editor {
  background: #fff;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(60, 60, 67, 0.12);
}
.settings-token-editor.hidden { display: none; }
#settings-token-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid var(--ios-chrome-hairline);
  border-radius: 8px;
  background: #fff;
  color: #000;
  font-family: inherit;
  outline: none;
}
#settings-token-input:focus { border-color: var(--ios-blue); }
.settings-token-actions { display: flex; gap: 10px; margin-top: 10px; }
.settings-token-actions .settings-action-btn { flex: 1; }
.settings-action-btn-danger {
  background: #fff;
  color: var(--ios-red);
  border: 1px solid rgba(255, 59, 48, 0.4);
}
.settings-row-empty {
  background: #fff;
  color: var(--ios-gray);
  font-size: 15px;
  padding: 12px 16px;
}

/* ---------- Photos app grid (Phase 3) ---------- */
.photos-grid {
  position: absolute;
  inset: 0;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(3, 1fr);  /* 3 across on mobile */
  grid-auto-rows: 1fr;
  gap: 2px;
  padding: 2px;
  align-content: start;
}
@media (min-width: 600px) {
  .photos-grid { grid-template-columns: repeat(4, 1fr); }  /* 4 at wider widths */
}
.photos-grid .photo-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: none;
  background: var(--gray-bubble);
  overflow: hidden;
  cursor: pointer;
  transition: opacity 120ms ease;
}
.photos-grid .photo-thumb:active { opacity: 0.7; }
.photos-grid .photo-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photos-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  color: var(--ios-gray);
}
.photos-empty.hidden { display: none; }

/* ---------- Phone app (Phase 5) ---------- */
.app-screen[data-app="phone"] .app-content { display: flex; flex-direction: column; }
.phone-view {
  position: absolute;
  inset: 0 0 50px 0;          /* leave room for the bottom tab bar */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.phone-view.hidden { display: none; }

/* Recents list */
.recents-list { display: flex; flex-direction: column; }
.recents-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-bottom: 0.5px solid var(--ios-chrome-hairline);
  background: var(--ios-app-bg);
  cursor: pointer;
}
.recents-row:active { background: #e9e9ee; }
.recents-row .rr-dir {
  flex: none;
  width: 16px;
  height: 16px;
  color: var(--ios-gray);
  display: flex;
  align-items: center;
  justify-content: center;
}
.recents-row .rr-main { flex: 1 1 auto; min-width: 0; }
.recents-row .rr-name {
  font-size: 17px;
  font-weight: 400;
  color: var(--ios-chrome-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.recents-row.missed .rr-name { color: var(--ios-red); }
.recents-row .rr-sub { font-size: 13px; color: var(--ios-gray); margin-top: 1px; }
.recents-row .rr-time { flex: none; font-size: 15px; color: var(--ios-gray); }
.phone-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ios-gray);
  font-size: 17px;
}
.phone-empty.hidden { display: none; }

/* Contact view */
.contact-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 36px 16px;
  gap: 10px;
}
.contact-avatar {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--gray-bubble);
}
.contact-name { font-size: 26px; font-weight: 600; color: var(--ios-chrome-text); }
.contact-actions { display: flex; gap: 36px; margin-top: 18px; }
.contact-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: var(--ios-blue);
}
.contact-action .ca-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(10, 132, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
}
.contact-action .ca-label { font-size: 13px; color: var(--ios-blue); }
.contact-action:active { opacity: 0.5; }
.contact-action.disabled { color: var(--ios-gray); cursor: default; opacity: 0.5; }
.contact-action.disabled .ca-icon { background: rgba(142, 142, 147, 0.14); }
.contact-action.disabled .ca-label { color: var(--ios-gray); }

/* Bottom tab bar */
.phone-tabbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(50px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--ios-chrome-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--ios-chrome-hairline);
}
.phone-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: var(--ios-gray);
  font-size: 11px;
}
.phone-tab svg { stroke: currentColor; width: 30px; height: 30px; }
.phone-tab.active { color: var(--ios-blue); }

/* Call view (outgoing ring + active call) */
.call-view {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: var(--ios-home-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(env(safe-area-inset-top) + 56px) 24px
           calc(env(safe-area-inset-bottom) + 48px);
}
.call-view.hidden { display: none; }
.call-avatar {
  width: 116px;
  height: 116px;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.15);
  box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4);
}
.call-view.connected .call-avatar { animation: call-pulse 2s ease-out infinite; }
@keyframes call-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.35); }
  100% { box-shadow: 0 0 0 22px rgba(255, 255, 255, 0); }
}
.call-name { font-size: 30px; font-weight: 500; margin-top: 18px; }
.call-status { font-size: 17px; color: rgba(255, 255, 255, 0.7); margin-top: 6px; }
.call-status.hidden { display: none; }
.call-timer { font-size: 17px; color: rgba(255, 255, 255, 0.7); margin-top: 6px; font-variant-numeric: tabular-nums; }
.call-timer.hidden { display: none; }
.call-level { display: flex; align-items: flex-end; gap: 4px; height: 26px; margin-top: 18px; }
.call-level.hidden { display: none; }
.call-level span {
  width: 5px;
  height: 5px;
  border-radius: 3px;
  background: var(--ios-green);
  transition: height 90ms ease;
}
.call-controls {
  margin-top: auto;
  display: flex;
  gap: 40px;
  align-items: center;
  justify-content: center;
}
.call-ctl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: #fff;
}
.call-ctl.hidden { display: none; }
.call-ctl .ctl-glyph {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.call-ctl .ctl-glyph svg { width: 30px; height: 30px; fill: currentColor; display: block; }
.call-ctl.end .ctl-glyph { background: var(--ios-red); }
/* End/hang-up uses the handset rotated 135° (iOS convention). */
.call-ctl.end .ctl-glyph svg { transform: rotate(135deg); }
.call-ctl.muted .ctl-glyph { background: #fff; color: #000; }
.call-ctl .ctl-label { font-size: 13px; color: rgba(255, 255, 255, 0.9); margin-top: 8px; }
.call-ctl:active { opacity: 0.6; }

/* Toast */
.phone-toast {
  position: absolute;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%);
  z-index: 8;
  max-width: 80%;
  padding: 10px 16px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  font-size: 14px;
  text-align: center;
  transition: opacity 200ms ease;
}
.phone-toast.hidden { opacity: 0; pointer-events: none; }

/* Call-detail sheet (tap a Recents row) */
.call-detail-sheet {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  align-items: flex-end;
}
.call-detail-sheet.hidden { display: none; }
.cds-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.4); }
.cds-card {
  position: relative;
  width: 100%;
  background: var(--ios-app-bg);
  border-radius: 14px 14px 0 0;
  padding: 22px 20px calc(env(safe-area-inset-bottom) + 18px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  animation: cds-up 280ms var(--ios-ease);
}
@keyframes cds-up { from { transform: translateY(100%); } to { transform: none; } }
.cds-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--gray-bubble);
  margin-bottom: 4px;
}
.cds-name { font-size: 22px; font-weight: 600; color: var(--ios-chrome-text); }
.cds-type { font-size: 16px; color: var(--ios-chrome-text); }
.cds-meta { font-size: 14px; color: var(--ios-gray); }
.cds-meta.hidden { display: none; }
.cds-call {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--ios-green);
  color: #fff;
  border: none;
  border-radius: 22px;
  padding: 11px 30px;
  font-size: 17px;
  font-family: inherit;
  cursor: pointer;
}
.cds-call:active { opacity: 0.7; }
.cds-close {
  margin-top: 4px;
  background: transparent;
  border: none;
  color: var(--ios-blue);
  font-size: 17px;
  font-family: inherit;
  cursor: pointer;
  padding: 8px;
}

/* ---------- Calendar app (Phase 4) ---------- */
/* The upcoming-dates panel used to be a fixed slide-in overlay (z60,
 * translateX). Inside the Calendar app it's a normal flow container that
 * fills the content area; the shell app-container handles show/hide. */
.app-screen[data-app="calendar"] .app-content { display: flex; }
.app-screen[data-app="calendar"] .upcoming-panel {
  position: static;
  inset: auto;
  z-index: auto;
  transform: none;
  transition: none;
  max-width: none;
  margin: 0;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
}
/* Inside the app, the panel's own hidden-slide is a no-op. The inner
 * month/day-view .hidden toggles (display:none) keep working. */
.app-screen[data-app="calendar"] .upcoming-panel.hidden {
  transform: none;
  pointer-events: auto;
}

/* ---------- Home indicator (tap / swipe-up to go home) ---------- */
.home-indicator {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--ios-home-indicator-h);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Only intercepts gestures while an app is open. */
  pointer-events: none;
  touch-action: none;
}
.shell.app-active .home-indicator { pointer-events: auto; }
/* While the composer (or any field) inside the open app is focused, the
 * keyboard is up and the composer sits where the indicator's hot-zone is.
 * Suppress the indicator so typing never accidentally triggers "go home". */
.app-container:focus-within ~ .home-indicator {
  opacity: 0;
  pointer-events: none;
}
.home-indicator .bar {
  width: 140px;
  height: 5px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.32);
  transition: background 120ms ease;
}
@media (prefers-color-scheme: dark) {
  .home-indicator .bar { background: rgba(255, 255, 255, 0.45); }
}
.home-indicator:active .bar { background: rgba(0, 0, 0, 0.5); }

/* ---------- Notification layer (Phase 8 fills this) ---------- */
.notification-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding-top: env(safe-area-inset-top);
  pointer-events: none;
}

/* iOS-style notification banners (Phase 8): for activity in apps you're not
 * in (new message, missed call). NOT incoming calls (those take over via the
 * call overlay). Slide down from the top, hold, slide up. One at a time. */
.notif-banner-card {
  pointer-events: auto;
  margin: 8px 8px 0;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(250, 250, 250, 0.86);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-radius: 18px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  transform: translateY(-150%);
  opacity: 0;
  transition: transform 320ms var(--ios-ease), opacity 320ms var(--ios-ease);
  cursor: pointer;
}
.notif-banner-card.shown { transform: translateY(0); opacity: 1; }
.notif-banner-card .nb-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.notif-banner-card .nb-icon.nb-messages { background: linear-gradient(180deg, #3aa0ff, #0a6cff); }
.notif-banner-card .nb-icon.nb-phone { background: linear-gradient(180deg, #5df07a, #2cc14e); }
.notif-banner-card .nb-body { flex: 1 1 auto; min-width: 0; }
.notif-banner-card .nb-title { font-size: 16px; font-weight: 600; color: #000; line-height: 1.2; }
.notif-banner-card .nb-text {
  font-size: 17px;
  color: #000;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (prefers-color-scheme: dark) {
  .notif-banner-card { background: rgba(40, 40, 42, 0.9); }
  .notif-banner-card .nb-title, .notif-banner-card .nb-text { color: #fff; }
}

/* ---------- Incoming-call overlay (Phase 7 fills this) ---------- */
.call-overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  background: var(--ios-home-bg);
}
.call-overlay.hidden { display: none; }

/* Incoming-call screen (Phase 7) */
.call-overlay .incoming {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 72px) 24px
           calc(env(safe-area-inset-bottom) + 56px);
  color: #fff;
}
.incoming-top { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.incoming-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.15);
  animation: call-pulse 2s ease-out infinite;
}
.incoming-name { font-size: 32px; font-weight: 500; }
.incoming-sub { font-size: 17px; color: rgba(255, 255, 255, 0.7); }
.incoming-actions { display: flex; gap: 80px; align-items: flex-end; }
.incoming-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: #fff;
}
.incoming-btn .ib-glyph {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.incoming-btn.decline .ib-glyph { background: var(--ios-red); }
.incoming-btn.decline .ib-glyph svg { transform: rotate(135deg); }  /* hang-up handset */
.incoming-btn.accept .ib-glyph { background: var(--ios-green); }
.incoming-btn .ib-label { font-size: 15px; }
.incoming-btn:active { opacity: 0.6; }

/* ---------- Contact card (Phase 10 polish) ---------- */
/* Body-level overlay above the shell (z55) but below #info-panel (z60), so
 * "More info" drills the relationship panel in on top of it, iOS-style. */
.contact-card-panel {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: flex;
  flex-direction: column;
  background: #f2f2f7;
  font-family: var(--ios-font);
}
@media (prefers-color-scheme: dark) { .contact-card-panel { background: #000; } }
.contact-card-panel.hidden { display: none; }
.contact-card-panel .cc-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 0 32px;
}
.cc-hero { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 8px 16px 20px; }
.cc-avatar {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--gray-bubble);
}
.cc-name { font-size: 26px; font-weight: 600; color: var(--ios-chrome-text); }
.cc-actions { display: flex; justify-content: center; gap: 28px; padding-bottom: 24px; }
.cc-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: var(--ios-blue);
}
.cc-action .cc-action-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(10, 132, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cc-action .cc-action-label { font-size: 13px; color: var(--ios-blue); }
.cc-action:active { opacity: 0.5; }
/* Hide the text labels under the call / FaceTime buttons (icon-only), in
 * both the Phone app contact view (.ca-label) and the contact card
 * (.cc-action-label). aria-labels on the buttons keep them accessible. */
.ca-label, .cc-action-label { display: none; }

/* Greyed-out FaceTime (matches the Phone app's disabled FaceTime action). */
.cc-action.disabled { color: var(--ios-gray); cursor: default; opacity: 0.5; }
.cc-action.disabled .cc-action-icon { background: rgba(142, 142, 147, 0.14); }
.cc-action.disabled .cc-action-label { color: var(--ios-gray); }

/* Texting UI: nudge every character up ~1pt for readability (incl. the
 * composer input while typing). Scoped to the Messages app; overrides the
 * base sizes in styles.css. */
.app-screen[data-app="messages"] .bubble { font-size: 17px; }
.app-screen[data-app="messages"] .bubble-caption { font-size: 17px; }
.app-screen[data-app="messages"] #composer { font-size: 17px; }
.app-screen[data-app="messages"] .separator { font-size: 12px; }
.app-screen[data-app="messages"] .status { font-size: 12px; }
.app-screen[data-app="messages"] .msg-time { font-size: 11px; }
.cc-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: none;
  border-top: 0.5px solid var(--ios-chrome-hairline);
  border-bottom: 0.5px solid var(--ios-chrome-hairline);
  padding: 14px 16px;
  font-size: 17px;
  font-family: inherit;
  color: var(--ios-chrome-text);
  cursor: pointer;
}
@media (prefers-color-scheme: dark) { .cc-row { background: #1c1c1e; } }
.cc-row:active { background: #e9e9ee; }
.cc-row .cc-chevron { color: var(--ios-gray); font-size: 20px; }

/* ---------- Generic tap feedback utility ---------- */
.tappable { transition: transform 120ms ease, opacity 120ms ease; }
.tappable:active { transform: scale(0.96); opacity: 0.7; }
