/*
 * The web app's page (plan 61 §2.5). Load after tokens.css. Every colour, space, radius and type
 * size is a token or a type-role class from tokens.css. The bt-* rules are the Bates App design
 * system's web forms (ios/design/web/bundle.css), copied for the parts this page draws: the bubble,
 * the typing bubble, the header, the composer, buttons, cards, banners and pills.
 */

/* ── Base ─────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper); color: var(--ink);
  font-family: var(--font-system); -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
.dim { color: var(--dim); }
.faint { color: var(--faint); }
.error-text { color: var(--error-text); }
.pre { white-space: pre-wrap; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
button { font: inherit; }

.screen { min-height: 100%; padding: var(--xl) var(--l); }
.screen--center { display: flex; align-items: center; justify-content: center; }

/* ── Link screen ──────────────────────────────────────────────────────────── */
.link-panel {
  display: flex; flex-direction: column; gap: var(--l); align-items: center; text-align: center;
  width: 100%; max-width: 440px; padding: var(--xxl) var(--xl);
  background: var(--card); border: 1px solid var(--hairline); border-radius: var(--large);
}
.link-code { color: var(--deep-teal); letter-spacing: 0.06em; user-select: all; }

/* ── The app: conversations beside the chat ───────────────────────────────── */
.app { display: flex; height: 100%; }
.sidebar {
  display: flex; flex-direction: column; gap: var(--m);
  width: 280px; flex: none; padding: var(--l);
  background: var(--paper); border-right: 0.5px solid var(--hairline);
}
.sidebar__brand { display: flex; align-items: center; gap: var(--s); padding: var(--xs) var(--xs) var(--s); }
.avatar-s { width: 32px; height: 32px; font-family: var(--font-georgia); font-weight: 700; }
.conversation-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--xxs); flex: 1; overflow-y: auto; }
.conversation {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--xxs);
  width: 100%; padding: var(--s) var(--m); border: 0; border-radius: var(--medium);
  background: transparent; color: var(--ink); text-align: left; cursor: pointer;
}
.conversation:hover { background: var(--card); }
.conversation--current { background: var(--card); box-shadow: var(--elevation-bubble); }
.conversation__name { font-weight: 600; }
.conversation__sub { color: var(--dim); }
.signout { align-self: stretch; }

.chat { display: flex; flex-direction: column; flex: 1; min-width: 0; background: var(--chat-background); }
.pinned { display: flex; flex-direction: column; gap: var(--s); padding: var(--s) var(--l) 0; }
.pinned:empty { display: none; }
.messages {
  list-style: none; margin: 0; flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--s);
  padding: var(--l) var(--l) var(--m);
}
.empty { margin: auto; color: var(--dim); text-align: center; }
.day { display: flex; justify-content: center; padding: var(--s) 0; }
.notice-row { display: flex; flex-direction: column; align-items: center; gap: var(--xxs); color: var(--dim); text-align: center; padding: 0 var(--xl); }

/* ── Approval cards: read-only here (plan 61 R11) ─────────────────────────── */
.approval { display: flex; flex-direction: column; gap: var(--xs); }
.approval__heading { font-weight: 600; margin-top: var(--xs); }
.approval__details { margin: 0; padding-left: var(--l); color: var(--dim); }
.approval__phone { align-self: flex-start; margin-top: var(--s); }

/* ── Messages (ChatBubble.swift's web form) ───────────────────────────────── */
.bt-bubble-row { display: flex; justify-content: flex-start; }
.bt-bubble-row--out { justify-content: flex-end; }
.bt-bubble {
  position: relative; max-width: min(82%, 680px);
  display: flex; flex-direction: column; gap: var(--xxs);
  padding: var(--bubble-inset-top) var(--bubble-inset-trailing) var(--bubble-inset-bottom) var(--m);
  border-radius: var(--bubble); color: var(--ink);
  box-shadow: 0 1px 0 var(--bubble-shadow);
}
.bt-bubble--incoming { background: var(--card); border-top-left-radius: var(--tucked); }
.bt-bubble--outgoing { background: var(--outgoing); border-top-right-radius: var(--tucked); }
.bt-bubble--queued { background: var(--queued); box-shadow: none; border: 1px dashed var(--queued-border); border-top-right-radius: var(--tucked); }
.bt-bubble__body { overflow-wrap: anywhere; }
.bt-bubble--out .bt-bubble__body { white-space: pre-wrap; }
.bt-bubble__body a { color: var(--deep-teal); }
.bt-bubble__body p + p, .bt-bubble__body p + ul, .bt-bubble__body p + ol, .bt-bubble__body ul + p, .bt-bubble__body ol + p, .bt-bubble__body pre + p, .bt-bubble__body p + pre { margin-top: var(--s); }
.bt-bubble__body ul, .bt-bubble__body ol { margin: 0; padding-left: var(--xl); }
.bt-bubble__body code { font-family: var(--font-mono); font-size: 0.875em; background: var(--chat-background); border-radius: var(--small); padding: 0 var(--xs); }
.bt-bubble__body pre { margin: 0; padding: var(--s); background: var(--chat-background); border-radius: var(--small); overflow-x: auto; }
.bt-bubble__body pre code { padding: 0; background: none; }
.link-host { color: var(--faint); font-size: 0.85em; }
.bt-bubble__meta { display: inline-flex; gap: var(--xxs); white-space: nowrap; color: var(--faint); }
.bt-bubble__meta--alone { align-self: flex-end; }
.bt-bubble--out .bt-bubble__meta { color: var(--outgoing-meta); }
.bt-bubble__sender { font-weight: 600; color: var(--deep-teal); }
.bt-bubble__label { font-weight: 600; color: var(--deep-teal); }
.bt-bubble__action {
  align-self: flex-start; margin: 0; padding: 0; border: 0; background: none;
  color: var(--deep-teal); cursor: pointer; text-decoration: underline;
}
.quote { border-left: 3px solid var(--teal); padding-left: var(--s); color: var(--dim); white-space: pre-wrap; overflow-wrap: anywhere; }
.photo { display: block; max-width: 100%; max-height: 360px; width: auto; height: auto; border-radius: var(--medium); background: var(--hairline); }

/* ── The typing bubble, with the activity label (plan 38) ─────────────────── */
.bt-typing {
  display: inline-flex; align-items: center; gap: var(--s);
  max-width: 82%; min-height: 40px; padding: var(--s) var(--m);
  background: var(--card); border-radius: var(--tucked) var(--bubble) var(--bubble) var(--bubble);
  box-shadow: 0 1px 0 var(--bubble-shadow);
}
.bt-typing__dots { display: inline-flex; gap: var(--xs); flex: none; }
.bt-typing__dot { width: var(--s); height: var(--s); border-radius: 50%; background: var(--faint); animation: bt-typing-pulse 1.2s ease-in-out infinite; }
.bt-typing__dot:nth-child(2) { opacity: 0.65; animation-delay: 0.18s; }
.bt-typing__dot:nth-child(3) { opacity: 0.35; animation-delay: 0.36s; }
@keyframes bt-typing-pulse { 0%, 100% { transform: scale(0.7); } 50% { transform: scale(1); } }
.bt-typing__label { color: var(--dim); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.bt-typing__label:empty { display: none; }

/* ── Header (Conversation.swift) ──────────────────────────────────────────── */
.bt-header {
  display: flex; align-items: center; gap: var(--s); min-height: 56px; padding: var(--s) var(--l);
  background: color-mix(in srgb, var(--paper) 85%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(1.6); backdrop-filter: blur(18px) saturate(1.6);
  border-bottom: 0.5px solid var(--hairline);
}
.bt-header__title { display: flex; flex-direction: column; min-width: 0; }
.bt-header__brand, .bt-header__status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bt-header__status { color: var(--dim); }
.bt-header__status--busy { color: var(--deep-teal); font-weight: 500; }

/* ── Composer ─────────────────────────────────────────────────────────────── */
.composer { display: flex; flex-direction: column; gap: var(--s); padding: var(--s) var(--l) var(--l); }
.composer__note { color: var(--error-text); }
.draft-photo { display: flex; align-items: flex-end; gap: var(--m); }
.draft-photo img { max-height: 120px; max-width: 200px; border-radius: var(--medium); }
.bt-glass {
  background: color-mix(in srgb, var(--card) 72%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(1.6); backdrop-filter: blur(18px) saturate(1.6);
  border: 0.5px solid color-mix(in srgb, var(--strong-hairline) 60%, transparent);
  box-shadow: var(--elevation-bubble);
}
.bt-composer { display: flex; align-items: flex-end; gap: var(--s); }
.bt-composer__field { flex: 1; display: flex; align-items: center; min-width: 0; min-height: 44px; padding: var(--m) var(--l); border-radius: 22px; }
.bt-composer__input { flex: 1; min-width: 0; margin: 0; padding: 0; border: 0; outline: none; resize: none; background: transparent; color: var(--ink); caret-color: var(--teal); font: inherit; }
.bt-composer__input::placeholder { color: var(--faint); }
.bt-composer-button {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 44px; height: 44px; border-radius: 50%; color: var(--teal); font-size: var(--icon-l); cursor: pointer;
}

/* ── Buttons (Buttons.swift) ──────────────────────────────────────────────── */
.bt-button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s);
  min-height: 44px; margin: 0; padding: var(--m) var(--xl);
  border-radius: 999px; border: 1px solid transparent; text-align: center; cursor: pointer;
}
.bt-button--primary { background: var(--primary-button); color: var(--on-primary-button); }
.bt-button--secondary { background: var(--card); color: var(--deep-teal); border-color: var(--strong-hairline); }
.bt-button--destructive { background: var(--card); color: var(--error-text); border-color: var(--error-border); }
.bt-button:active:not(:disabled) { opacity: 0.75; }
.bt-iconbutton {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 44px; height: 44px; margin: 0; padding: 0; border-radius: 50%; border: 0; cursor: pointer;
}
.bt-iconbutton--filled { background: var(--teal); color: var(--on-accent); font-size: var(--icon-m); }
.bt-iconbutton--filled:disabled { background: var(--strong-hairline); cursor: default; }

/* ── Surfaces and labels (Surfaces.swift, Rows.swift) ─────────────────────── */
.bt-card { width: 100%; padding: var(--l); background: var(--card); border: 1px solid var(--hairline); border-radius: var(--medium); }
.bt-banner { display: flex; align-items: baseline; gap: var(--s); width: 100%; padding: var(--s) var(--l); border-top: 1px solid; border-bottom: 0.5px solid; }
.pinned .bt-banner { border: 1px solid; border-radius: var(--medium); }
.bt-banner__text { display: flex; flex-direction: column; gap: var(--xxs); min-width: 0; }
.bt-banner--info { background: var(--card); border-color: var(--hairline); color: var(--ink); }
.bt-banner--warn { background: var(--warn-background); border-color: var(--warn-border); color: var(--warn-text); }
.bt-pill { display: inline-flex; align-items: center; gap: var(--xs); padding: var(--xs) var(--m); border-radius: var(--small); font-weight: 600; }
.bt-pill--quiet { color: var(--dim); background: var(--chat-background); }
.bt-pill--accent { color: var(--deep-teal); background: color-mix(in srgb, var(--teal) 14%, transparent); }
.bt-avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  border-radius: 50%; color: var(--mark); background: linear-gradient(to bottom, var(--avatar-top), var(--avatar-bottom));
}

/* ── Turn details (TurnDetailsView.swift) ─────────────────────────────────── */
.turn {
  width: min(640px, calc(100vw - 2 * var(--l))); max-height: calc(100vh - 2 * var(--xl));
  padding: 0; border: 1px solid var(--hairline); border-radius: var(--large);
  background: var(--paper); color: var(--ink); box-shadow: var(--elevation-raised);
}
.turn::backdrop { background: rgba(0, 0, 0, 0.35); }
.turn__header {
  position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between;
  padding: var(--m) var(--l); background: var(--paper); border-bottom: 0.5px solid var(--hairline);
}
.turn__body { display: flex; flex-direction: column; gap: var(--m); padding: var(--l); }
.turn__call { display: flex; flex-direction: column; gap: var(--s); }
.turn__call-title { text-transform: uppercase; letter-spacing: 0.04em; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--xs) var(--l); margin: 0; }
.facts dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.turn__tool { display: flex; flex-direction: column; gap: var(--xxs); padding-top: var(--s); border-top: 0.5px solid var(--hairline); }
.turn__tool-head { display: flex; justify-content: space-between; gap: var(--m); }
.turn__tool-name { font-weight: 500; }
.turn__tool--failed .turn__tool-name { color: var(--error-text); }
.turn__args { font-family: var(--font-mono); color: var(--dim); overflow-wrap: anywhere; }
.turn__text {
  margin: var(--xxs) 0 0; padding: var(--s); white-space: pre-wrap; overflow-wrap: anywhere;
  font-family: var(--font-mono); background: var(--chat-background); border-radius: var(--small);
}
.turn details summary { cursor: pointer; color: var(--deep-teal); }

/* ── A phone-width window: the conversations above the chat ───────────────── */
@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; flex-direction: row; align-items: center; padding: var(--s) var(--m); border-right: 0; border-bottom: 0.5px solid var(--hairline); }
  .sidebar__brand .brand { display: none; }
  .conversation-list { flex-direction: row; overflow-x: auto; }
  .conversation { width: auto; white-space: nowrap; }
  .conversation__sub { display: none; }
  .signout { align-self: center; padding: var(--s) var(--m); min-height: 36px; }
  .chat { min-height: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .bt-typing__dot { animation: none; }
}
