/* =========================================================================
   AG app shell — mobile first. Nothing here assumes a mouse or a wide screen.

   Layout is a three-row grid: header / scrolling pane / tab bar. Only the
   middle row scrolls, so the tab bar stays put when the iOS keyboard opens
   and the header never slides away mid-scroll.
   ========================================================================= */

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;   /* dvh, not vh: vh is wrong while iOS Safari's bars animate */
  max-width: var(--container);
  margin: 0 auto;
  background: var(--bg);
}

/* ===================== Header ===================== */

.hdr {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  padding-top: calc(var(--s3) + env(safe-area-inset-top));
  border-bottom: 1px solid var(--hairline);
  background: var(--elevated);
}

.hdr__title { flex: 1; font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }

.hdr__sub {
  display: block;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--muted);
}

/* ===================== Panes ===================== */

.pane {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: var(--s4);
}

.pane[hidden] { display: none; }

.stack { display: flex; flex-direction: column; gap: var(--s4); }

/* ===================== Cards ===================== */

.card {
  background: var(--elevated);
  border: 1px solid var(--hairline);
  border-radius: var(--r);
  padding: var(--s4);
  box-shadow: var(--elev);
}

.card__label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--s2);
}

.muted { color: var(--muted); font-size: 14px; }

/* ===================== Controls =====================
   44px min touch target throughout — below that, thumbs miss. */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 44px;
  padding: 0 var(--s4);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--t-fast) var(--ease),
              background-color var(--t-fast) var(--ease);
}

.btn:active { transform: scale(0.97); }

.btn--accent {
  background: var(--accent);
  color: var(--on-accent);
  border-color: transparent;
  font-weight: 600;
}

.btn--icon {
  min-width: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
}

.btn--block { width: 100%; }

/* ===================== Tab bar ===================== */

.tabbar {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border-top: 1px solid var(--hairline);
  background: var(--elevated);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tabbar-h);
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--t-fast) var(--ease);
}

.tab__icon { font-size: 20px; line-height: 1; }

.tab[aria-selected="true"] { color: var(--accent); }

/* ===================== Status dot ===================== */

.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  margin-inline-end: var(--s2);
  vertical-align: baseline;
}

.dot--ok   { background: var(--ok); }
.dot--warn { background: var(--warn); }
.dot--bad  { background: var(--danger); }

/* ===================== Empty state ===================== */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  height: 100%;
  min-height: 240px;
  text-align: center;
  color: var(--muted);
  padding: var(--s6) var(--s4);
}

.empty__icon {
  font-size: 40px;
  opacity: 0.55;
}

/* ===================== Phase banner =====================
   Removed once Phase 1 lands — it exists so the shell never looks broken
   while the features behind it are still being built. */

.banner {
  border: 1px dashed var(--control);
  border-radius: var(--r);
  padding: var(--s3) var(--s4);
  font-size: 13px;
  color: var(--muted);
  background: var(--surface);
}

code {
  font-family: var(--ff-mono);
  font-size: 0.9em;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  padding: 1px 5px;
}

/* ===================== Login gate ===================== */

.gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: var(--s5) var(--s4);
  padding-top: calc(var(--s5) + env(safe-area-inset-top));
}

.gate__card {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.gate__mark { display: flex; justify-content: center; margin-bottom: var(--s2); }
.gate__card h1 { font-size: 30px; }
.gate__card .muted { margin-bottom: var(--s3); }

/* ===================== Fields ===================== */

.field { display: block; text-align: start; }

.field__label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: var(--s1);
}

.input {
  width: 100%;
  min-height: 46px;
  padding: 0 var(--s3);
  /* --control, not --hairline: a hairline border on an input fails 3:1. */
  border: 1px solid var(--control);
  border-radius: var(--r-input);
  background: var(--bg);
  color: var(--text);
  /* 16px minimum, or iOS zooms the whole page when the field is focused. */
  font: inherit;
  font-size: 16px;
}

.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--elev-glow); }

.field__error {
  color: var(--danger);
  font-size: 14px;
  text-align: start;
}

/* ===================== Chat ===================== */

.pane--chat {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.thread {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  padding: var(--s4);
}

.bubble {
  max-width: 78%;
  padding: var(--s2) var(--s3);
  border-radius: var(--r-lg);
  line-height: 1.4;
  overflow-wrap: anywhere;
  animation: rise var(--t) var(--ease);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.bubble--them {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-bottom-left-radius: var(--r-sm);
}

.bubble--me {
  align-self: flex-end;
  background: var(--accent);
  color: var(--on-accent);
  border-bottom-right-radius: var(--r-sm);
}

.bubble--bad {
  align-self: flex-start;
  background: transparent;
  border: 1px dashed var(--danger);
  color: var(--danger);
  font-size: 14px;
}

.bubble__time {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  opacity: 0.65;
}

.composer {
  display: flex;
  gap: var(--s2);
  padding: var(--s3) var(--s4);
  padding-bottom: calc(var(--s3) + env(safe-area-inset-bottom) / 2);
  border-top: 1px solid var(--hairline);
  background: var(--elevated);
}

.composer__input { flex: 1; border-radius: var(--r-pill); }
.composer__send { flex: none; font-size: 20px; font-weight: 700; }

/* ===================== Safety code ===================== */

.safety {
  font-family: var(--ff-mono);
  font-size: 18px;
  letter-spacing: 0.08em;
  text-align: center;
  padding: var(--s3);
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--hairline);
  overflow-wrap: anywhere;
}

/* ===================== Call ===================== */

.call-card { text-align: center; }

.call-card__avatar,
.callscreen__avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 88px;
  height: 88px;
  margin: 0 auto var(--s3);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 36px;
}

.call-card h2 { margin-bottom: var(--s1); }
.call-card .btn { margin-top: var(--s4); }

.callscreen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: var(--s5) var(--s4);
  padding-bottom: calc(var(--s6) + env(safe-area-inset-bottom));
}

.callscreen[hidden] { display: none; }

.callscreen__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  text-align: center;
  width: 100%;
  max-width: 340px;
}

.callscreen__avatar { width: 120px; height: 120px; font-size: 48px; }
.callscreen__name { font-size: 26px; }
.callscreen__state { color: var(--muted); }
.callscreen__quality { font-size: 13px; color: var(--muted); }

.callscreen__actions {
  display: flex;
  gap: var(--s6);
  justify-content: center;
  margin-top: var(--s6);
}

.callscreen__actions[hidden] { display: none; }

.btn--round {
  width: 68px;
  height: 68px;
  min-height: 68px;
  padding: 0;
  border-radius: 50%;
  font-size: 26px;
}

.btn--danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn--ok     { background: var(--ok);     color: #fff; border-color: transparent; }
.btn--muted-on { background: var(--warn); color: #fff; border-color: transparent; }

/* A ringing call should be impossible to miss on a glance. */
.callscreen--ringing .callscreen__avatar {
  animation: pulse 1.4s var(--ease) infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1);    box-shadow: 0 0 0 0 var(--accent-soft); }
  50%      { transform: scale(1.06); box-shadow: 0 0 0 18px transparent; }
}
