/* ==========================================================================
   OpenChat - Phase 1 styles
   WhatsApp-dark visual language. Vanilla CSS only, no external assets.

   Extends the Phase 0 design system (tokens below are the single source of
   truth for colour / radius / spacing). New Phase 1 tokens are grouped with
   the originals so every value traces back to the system.

   Sections:
     1. Tokens / reset
     2. Layout primitive (.screen)
     3. Login view
     4. App view: top bar
     5. App view: message list / empty state
     6. Chat bubbles (reused from Phase 0)
     7. Thought blocks (streaming reasoning)
     8. Tool-call cards
     9. Typing indicator
    10. Composer
   10b. Phase 2: inner screens, session list, FAB, chat loader
    10c. Phase 3: permission prompts
    10d. Phase 4: settings sheet
    10e. Phase 7: file attachments
    11. Responsive + motion preferences
   ========================================================================== */

/* 1. Tokens / reset ------------------------------------------------------- */
:root {
  --bg:                 #0b141a;
  --bar:                #202c33;
  --surface:            #2a3942;
  --accent:             #00a884;
  --accent-ink:         #0b141a;

  --bubble-out:         #005c4b;
  --bubble-in:          #202c33;

  --text:               #e9edef;
  --text-secondary:     #8696a0;
  --border:             #2a3942;

  --danger:             #ff7a85;
  --error-bg:           #3a2226;
  --error-border:       #f15c6d;

  --status-connected:   #00a884;
  --status-connecting:  #f0c14b;
  --status-disconnected:#f15c6d;

  /* Phase 1 additions - all derived from the palette above. */
  --thought-bg:         rgba(134, 150, 160, 0.10);
  --thought-border:     #2a3942;
  --tool-bg:            #202c33;

  --pill-pending:       #8696a0;
  --pill-progress:      #f0c14b;
  --pill-completed:     #00a884;
  --pill-failed:        #f15c6d;

  --radius:             12px;
  --radius-sm:          4px;
  --shadow-card:        0 14px 44px rgba(0, 0, 0, 0.42);
  --shadow-bubble:      0 1px 1px rgba(0, 0, 0, 0.28);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

/* The [hidden] attribute must win over component display rules. */
[hidden] { display: none !important; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

button, input { font-family: inherit; }
button { cursor: pointer; }

/* 2. Layout primitive ----------------------------------------------------- */
.screen {
  width: 100%;
  min-height: 100vh;   /* fallback */
  min-height: 100dvh;  /* iOS-correct viewport height */
}

/* 3. Login view ----------------------------------------------------------- */
.screen--login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 30px 24px 26px;
  background: var(--bar);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.login-logo {
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 14px;
}

.login-title {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.login-form { display: block; }

.field { display: block; margin-bottom: 16px; }

.field__label {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  color: var(--text-secondary);
}

.field__input {
  display: block;
  width: 100%;
  padding: 12px 13px;
  font-size: 16px;               /* min 16px prevents iOS zoom on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field__input::placeholder { color: var(--text-secondary); }
.field__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.22);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 16px;
  font-size: 16px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 9px;
  transition: filter 0.15s ease, opacity 0.15s ease;
}
.btn--accent {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);       /* dark ink on accent for AA contrast */
}
.btn--accent:active { filter: brightness(0.94); }
.btn:disabled { opacity: 0.5; cursor: default; }

.login-error {
  margin: 12px 0 0;
  font-size: 13.5px;
  line-height: 1.35;
  text-align: center;
  color: var(--danger);
}

/* 4. App view / top bar --------------------------------------------------- */
.screen--app {
  position: relative;   /* anchor for the Phase 4 settings overlay */
  display: flex;
  flex-direction: column;
  height: 100vh;      /* fallback */
  height: 100dvh;
  min-height: 0;
  background: var(--bg);
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  background: var(--bar);
  border-bottom: 1px solid var(--border);
}

/* Title + a subtle current-model line, stacked; the block takes the slack. */
.topbar__heading {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.topbar__title {
  flex: 0 0 auto;
  min-width: 0;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__subtitle {
  flex: 0 0 auto;
  margin-top: 1px;
  font-size: 11.5px;
  line-height: 1.2;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.status__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--status-disconnected);
  transition: background 0.2s ease;
}
.status[data-state="connecting"] .status__dot { background: var(--status-connecting); }
.status[data-state="connected"]  .status__dot { background: var(--status-connected); }

.topbar__btn {
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 16px;
  transition: background 0.15s ease;
}
.topbar__btn:active { background: var(--surface); }

/* Phase 2: square icon button (back control), 44px touch target. */
.topbar__btn--icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  color: var(--text);
  background: transparent;
}
.topbar__btn--icon:active { background: var(--surface); }
.topbar__icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 5. Message list / empty state ------------------------------------------- */
.app-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;   /* momentum scrolling on iOS */
  overscroll-behavior: contain;
}

/* Centred only while the log is empty; hidden once a message lands. */
.empty-state {
  margin: auto;
  padding: 20px;
  text-align: center;
}
.empty-state__text {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

/* 6. Chat bubbles (reused from Phase 0) ----------------------------------- */
.bubble-row {
  display: flex;
  width: 100%;
  flex: 0 0 auto;
}
.bubble-row--out { justify-content: flex-end; }
.bubble-row--in  { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.35;
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  box-shadow: var(--shadow-bubble);
}
.bubble--out {
  background: var(--bubble-out);
  border-top-right-radius: var(--radius-sm);
}
.bubble--in {
  background: var(--bubble-in);
  border-top-left-radius: var(--radius-sm);
}
/* Error must come after --in so it wins when both could apply. */
.bubble--error {
  background: var(--error-bg);
  color: var(--danger);
  border-left: 3px solid var(--error-border);
  border-top-left-radius: var(--radius-sm);
}
.bubble__text { display: block; }
.bubble__meta {
  display: block;
  margin-top: 3px;
  font-size: 10.5px;
  line-height: 1;
  text-align: right;
  color: var(--text-secondary);
}

/* 7. Thought blocks ------------------------------------------------------- */
/* Subdued, collapsible, and visually secondary to the real answer. */
.thought {
  align-self: flex-start;
  flex: 0 0 auto;
  max-width: 78%;
  padding: 6px 10px;
  background: var(--thought-bg);
  border: 1px solid var(--thought-border);
  border-radius: var(--radius);
  border-top-left-radius: var(--radius-sm);
  font-size: 12.5px;
  font-style: italic;
  line-height: 1.45;
  color: var(--text-secondary);
}
.thought__summary {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-style: italic;
  color: var(--text-secondary);
  cursor: pointer;
  list-style: none;
  user-select: none;
  -webkit-user-select: none;
}
.thought__summary::-webkit-details-marker { display: none; }
.thought__summary::after {
  content: "\203A";                 /* single right angle quote */
  display: inline-block;
  transition: transform 0.15s ease;
}
.thought[open] .thought__summary::after { transform: rotate(90deg); }
.thought__text {
  margin-top: 4px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* 8. Tool-call cards ------------------------------------------------------ */
.tool-row {
  display: flex;
  width: 100%;
  flex: 0 0 auto;
}
.tool-card {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 88%;
  padding: 7px 10px;
  background: var(--tool-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12.5px;
  color: var(--text);
}
.tool-card__icon {
  display: inline-flex;
  flex: 0 0 auto;
  color: var(--text-secondary);
}
.tool-card__icon svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool-card__title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tool-card__status {
  flex: 0 0 auto;
  padding: 2px 8px;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--pill-color, var(--text-secondary));
  border: 1px solid var(--pill-color, var(--border));
  border-radius: 999px;
}
.tool-card__status[data-status="pending"]     { --pill-color: var(--pill-pending); }
.tool-card__status[data-status="in_progress"] { --pill-color: var(--pill-progress); }
.tool-card__status[data-status="completed"]   { --pill-color: var(--pill-completed); }
.tool-card__status[data-status="failed"]      { --pill-color: var(--pill-failed); }

/* 9. Typing indicator ----------------------------------------------------- */
.typing-row {
  display: flex;
  width: 100%;
  flex: 0 0 auto;
}
.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 11px 14px;
  background: var(--bubble-in);
  border-radius: var(--radius);
  border-top-left-radius: var(--radius-sm);
}
.typing__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing__dot:nth-child(2) { animation-delay: 0.15s; }
.typing__dot:nth-child(3) { animation-delay: 0.30s; }
@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30%           { opacity: 1;    transform: translateY(-3px); }
}

/* 10. Composer ------------------------------------------------------------ */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: var(--bar);
  border-top: 1px solid var(--border);
}
.composer__input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 11px 14px;
  font-size: 16px;               /* min 16px prevents iOS zoom on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  outline: none;
  transition: border-color 0.15s ease;
}
.composer__input::placeholder { color: var(--text-secondary); }
.composer__input:focus { border-color: var(--accent); }
.composer__input:disabled { opacity: 0.55; }

.composer__send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--accent-ink);
  background: var(--accent);
  border: none;
  border-radius: 50%;
  transition: filter 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}
.composer__send:active { filter: brightness(0.94); }
.composer__send:disabled { opacity: 0.45; }

.composer__icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
  display: block;
}
.composer__icon--stop { display: none; }

/* Stop state: red circle, square glyph. */
.composer__send--stop { background: var(--danger); color: var(--accent-ink); }
.composer__send--stop .composer__icon--send { display: none; }
.composer__send--stop .composer__icon--stop { display: block; }

/* 10b. Phase 2: inner screens, session list, FAB, chat loader ------------- */
/* #view-app holds two inner screens; exactly one is visible at a time. */
.subscreen {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.subscreen--list { position: relative; }

/* Session list ---------------------------------------------------------- */
.session-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Phase 8: each row is a wrapper holding the tap-to-open row button and the
   trailing "..." menu button as siblings (a button cannot legally nest in a
   button). The wrapper owns the divider + active tint so both share them. */
.session-row-wrap {
  display: flex;
  align-items: center;
  width: 100%;
  border-bottom: 1px solid var(--border);
}
.session-row {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 6px 10px 14px;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: none;
  -webkit-tap-highlight-color: transparent;
}
.session-row:active { background: var(--bar); }
.session-row-wrap.session-row--active { background: rgba(0, 168, 132, 0.10); }

/* Phase 8: trailing overflow control; >=44px target, deliberately subdued. */
.session-row__menu {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  margin-right: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, color 0.15s ease;
}
.session-row__menu:active { background: var(--surface); color: var(--text); }
.session-row__menu svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}

.session-row__avatar {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 18px;
  font-weight: 600;
}

.session-row__main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
/* Title row: optional pin indicator + the truncated title. */
.session-row__line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.session-row__pin {
  flex: 0 0 auto;
  display: inline-flex;
  color: var(--accent);
}
.session-row__pin svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}
.session-row__title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 15.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-row__time {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Empty state is centred over the list area. */
#list-empty {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Floating "new chat" button (thumb reachable, bottom-right). */
.fab {
  position: absolute;
  right: 18px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--accent-ink);
  background: var(--accent);
  border: none;
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  transition: filter 0.15s ease;
}
.fab:active { filter: brightness(0.94); }
.fab__icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

/* Chat screen ----------------------------------------------------------- */
.chat-body {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Loading overlay while a session is opening / replaying. */
.session-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 14px;
}
.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spinner-rotate 0.8s linear infinite;
}
@keyframes spinner-rotate { to { transform: rotate(360deg); } }

/* 10c. Phase 3: permission prompts ---------------------------------------- */
/* Docked panel between the message log and the composer. It is a normal flex
   row (not an overlay) so it can never cover or wedge the input below it. */
.permission-panel {
  flex: 0 0 auto;
  padding: 8px 10px;
  background: var(--bar);
  border-top: 1px solid var(--border);
  animation: permission-in 0.16s ease-out;
}
@keyframes permission-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.permission-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

.permission-card__head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.permission-card__icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  color: var(--accent);
  background: rgba(0, 168, 132, 0.14);
  border-radius: 50%;
}
.permission-card__icon svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.permission-card__text {
  flex: 1 1 auto;
  min-width: 0;
}
.permission-card__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.permission-card__preview {
  margin-top: 3px;
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.permission-card__options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* One button per option; every button is a >=44px tap target. */
.permission-btn {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 10px 14px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  background: var(--bar);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: filter 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}
.permission-btn:active { filter: brightness(0.94); }

/* Allow: accent (green) solid. */
.permission-btn--allow {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}
/* Allow always: accent outline, deliberately distinct from the solid allow. */
.permission-btn--allow-always {
  color: var(--accent);
  background: transparent;
  border-color: var(--accent);
}

/* Reject: danger (red) solid. */
.permission-btn--reject {
  color: var(--bg);
  background: var(--danger);
  border-color: var(--danger);
}
/* Reject always: danger outline. */
.permission-btn--reject-always {
  color: var(--danger);
  background: transparent;
  border-color: var(--danger);
}

/* 10d. Phase 4: settings sheet -------------------------------------------- */
/* Absolute inside .screen--app (so it stays within the phone column on large
   screens). Backdrop dims the chat; the sheet slides up from the bottom. */
.settings {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.settings__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  animation: settings-fade 0.18s ease-out;
}
@keyframes settings-fade { from { opacity: 0; } to { opacity: 1; } }

.settings__sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: 82%;
  background: var(--bar);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -14px 44px rgba(0, 0, 0, 0.5);
  animation: settings-rise 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes settings-rise {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.settings__header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px 8px 16px;
}

.settings__title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.settings__close {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}
.settings__close:active { background: var(--surface); }
.settings__close svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}

.settings__subtitle {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 16px 10px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* Scroll container: the (up to 84-row) model list scrolls in here. */
.settings__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 8px 8px;
}

.settings__group { padding: 2px 0 10px; }

.settings__group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 8px 6px;
}
.settings__group-name {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.settings__group-value {
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
  font-size: 12.5px;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings__list { display: flex; flex-direction: column; }

/* One tappable row per select value (min 44px target). */
.settings__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  text-align: left;
  font-size: 15px;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}
.settings__option:active { background: var(--surface); }
.settings__option-name {
  flex: 1 1 auto;
  min-width: 0;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.settings__option-check {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  color: var(--accent);
  opacity: 0;
}
.settings__option-check svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}
.settings__option--selected { background: rgba(0, 168, 132, 0.10); }
.settings__option--selected .settings__option-name { color: var(--accent); font-weight: 600; }
.settings__option--selected .settings__option-check { opacity: 1; }

/* Boolean option: a switch row. */
.settings__switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}
.settings__switch:active { background: var(--surface); }
.settings__switch-label {
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
  font-size: 15px;
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.settings__switch-track {
  flex: 0 0 auto;
  position: relative;
  width: 46px;
  height: 27px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.settings__switch[aria-checked="true"] .settings__switch-track {
  background: var(--accent);
  border-color: var(--accent);
}
.settings__switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 21px;
  height: 21px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.15s ease;
}
.settings__switch[aria-checked="true"] .settings__switch-thumb { transform: translateX(19px); }

.settings__empty {
  margin: 24px 8px;
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
}

/* 10e. Phase 7: file attachments ------------------------------------------ */
/* Attach button sits to the left of the text input inside the composer. */
.composer__attach {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 50%;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.composer__attach:active { background: var(--surface); color: var(--text); }
.composer__attach:disabled { opacity: 0.4; }

/* Stroke-based paperclip (overrides the filled send icon default). */
.composer__icon--attach {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The file picker is driven by the attach button; keep it out of the flow and
   off-screen but clickable on iOS (display:none can break .click()). */
.attach-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Staged attachments strip (above the composer). Horizontal scroll of chips. */
.attach-strip {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bar);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

/* One chip per picked file: thumb + name + size + remove. */
.attach-chip {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 232px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.attach-chip--uploading { opacity: 0.6; }
.attach-chip--error { border-color: var(--error-border); }

.attach-chip__thumb {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 8px;
  background: var(--bar);
  color: var(--text-secondary);
}
.attach-chip__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.attach-chip__glyph svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.attach-chip__info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.attach-chip__name {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-chip__size {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-chip--error .attach-chip__size { color: var(--danger); }

.attach-chip__remove {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}
.attach-chip__remove:active { background: var(--bar); color: var(--text); }
.attach-chip__remove svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}

/* Inline upload error line (same tokens as the chat error bubbles). */
.attach-error {
  flex: 0 0 auto;
  margin: 0;
  padding: 8px 14px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--danger);
  background: var(--error-bg);
  border-top: 1px solid var(--error-border);
}

/* Attachment previews inside an outgoing message bubble. */
.bubble-atts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 6px;
}
.bubble-atts__img {
  display: block;
  max-width: 220px;
  max-height: 220px;
  width: auto;
  height: auto;
  border-radius: 8px;
  object-fit: cover;
}
.bubble-atts__file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 8px;
}
.bubble-atts__glyph {
  flex: 0 0 auto;
  display: inline-flex;
  color: var(--text-secondary);
}
.bubble-atts__glyph svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.bubble-atts__file-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.bubble-atts__file-name {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bubble-atts__file-size {
  font-size: 11px;
  color: var(--text-secondary);
}

/* 10f. Phase 8: session action sheet -------------------------------------- */
/* Absolute inside .screen--app (so it stays within the phone column on large
   screens). Dim backdrop; the sheet slides up from the bottom. Reuses the
   settings sheet's fade/rise keyframes so both overlays move identically. */
.session-menu {
  position: absolute;
  inset: 0;
  z-index: 45;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.session-menu__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  animation: settings-fade 0.18s ease-out;
}

.session-menu__sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
  background: var(--bar);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -14px 44px rgba(0, 0, 0, 0.5);
  animation: settings-rise 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Session title: one line, truncated. */
.session-menu__title {
  margin: 0 2px;
  padding-right: 12px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-menu__actions,
.session-menu__confirm {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-menu__confirm-text {
  margin: 4px 2px 2px;
  font-size: 15px;
  line-height: 1.35;
  color: var(--text);
}

/* One action per row; every action is a >=44px tap target. */
.session-menu__action {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  text-align: left;
  font-size: 15.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.15s ease, opacity 0.15s ease;
}
.session-menu__action:active { filter: brightness(0.94); }
.session-menu__action:disabled { opacity: 0.5; }

.session-menu__icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}
.session-menu__icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}

.session-menu__label {
  flex: 1 1 auto;
  min-width: 0;
}

/* Delete entry: danger tinted, distinct from the solid confirm. */
.session-menu__action--danger {
  color: var(--danger);
  background: rgba(255, 122, 133, 0.12);
  border-color: rgba(255, 122, 133, 0.30);
}
/* Confirm ("Remove"): solid danger, centred, weightier. */
.session-menu__action--danger-strong {
  justify-content: center;
  color: var(--bg);
  background: var(--danger);
  border-color: var(--danger);
  font-weight: 600;
}

.session-menu__cancel {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font-size: 15.5px;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
}
.session-menu__cancel:active { background: var(--surface); }

/* 11. Responsive + motion preferences ------------------------------------- */
@media (min-width: 768px) {
  /* Phone-like column on large screens. */
  .screen--app {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

@media (max-width: 360px) {
  .status__text { display: none; }   /* keep the top bar on one line */
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
