/* Dark values here match Craft's own desktop palette (styles.css's :root)
   token-for-token where a mobile equivalent exists - same charcoal, same
   border, same text grays, same purple/green/red - so switching between
   the desktop app and this companion doesn't feel like two different
   products. Light theme is defined further down: system-default via
   `@media (prefers-color-scheme: light)`, or forced either way via
   `data-theme` on <html> (see applyTheme() in mobile.js). */
:root {
  --bg: #1d1d20;
  --bg-card: #232327;
  --bg-card-hover: #28282d;
  --bg-card-active: #2d2d33;
  --border: #2b2b30;
  --border-strong: rgba(31, 174, 120, 0.38);
  --text: #ececf1;
  --text-muted: #a6a6b0;
  --text-faint: #6f6f7a;
  --violet: #1fae78;
  --violet-light: #4ce0a4;
  --violet-glow: rgba(31, 174, 120, 0.28);
  --green: #4cc38a;
  --green-glow: rgba(76, 195, 138, 0.25);
  --danger: #e5624d;
  --danger-bg: rgba(229, 98, 77, 0.14);
  --bubble-user-bg: #16342a;
  --bubble-user-text: #6ee7a8;
  --chrome-bg: rgba(15, 15, 17, 0.88);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* LIGHT THEME - full white, minimal. System default when the OS prefers
   light and the user hasn't overridden it; :not([data-theme="dark"]) is
   what lets an explicit dark choice win over the OS signal. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ffffff;
    --bg-card: #f6f6f8;
    --bg-card-hover: #eeeef1;
    --bg-card-active: #e6e6ea;
    --border: #e4e4e8;
    --border-strong: rgba(15, 157, 104, 0.32);
    --text: #0a0a0d;
    --text-muted: #14161a;
    --text-faint: #45494f;
    --violet: #0f9d68;
    --violet-light: #14b876;
    --violet-glow: rgba(15, 157, 104, 0.18);
    --green: #16a34a;
    --green-glow: rgba(22, 163, 74, 0.16);
    --danger: #dc2626;
    --danger-bg: #fdecea;
    --bubble-user-bg: #ddf5e3;
    --bubble-user-text: #146c43;
    --chrome-bg: rgba(255, 255, 255, 0.88);
  }
}

/* Explicit choice always wins over the OS signal, in both directions. */
:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-card: #f6f6f8;
  --bg-card-hover: #eeeef1;
  --bg-card-active: #e6e6ea;
  --border: #e4e4e8;
  --border-strong: rgba(15, 157, 104, 0.32);
  --text: #0a0a0d;
  --text-muted: #14161a;
  --text-faint: #45494f;
  --violet: #0f9d68;
  --violet-light: #14b876;
  --violet-glow: rgba(15, 157, 104, 0.18);
  --green: #16a34a;
  --green-glow: rgba(22, 163, 74, 0.16);
  --danger: #dc2626;
  --danger-bg: #fdecea;
  --bubble-user-bg: #ddf5e3;
  --bubble-user-text: #146c43;
  --chrome-bg: rgba(255, 255, 255, 0.88);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  /* height (not min-height) + overflow: hidden locks the PAGE to exactly
     one viewport worth of pixels, so it can never itself grow taller than
     the screen and start scrolling. That's the actual bug behind "have to
     scroll down manually": every container below this was min-height, so
     nothing was ever capped - the page grew with the chat instead of
     .main-scroll's own overflow kicking in, which is the only place
     scrollToBottom() ever touches. */
  height: 100%;
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-main);
  overflow: hidden;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

.hidden {
  display: none !important;
}

/* Ambient glow backdrop */
.bg-ambience {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.glow-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.18;
}

.orb-1 {
  width: 280px;
  height: 280px;
  top: -80px;
  right: -50px;
  background: var(--violet);
}

.orb-2 {
  width: 320px;
  height: 320px;
  bottom: 10%;
  left: -100px;
  background: #3b82f6;
}

/* Main Mobile Shell */
.app-shell {
  position: relative;
  z-index: 1;
  height: 100dvh;
  overflow: hidden;
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* PAIRING SCREEN */
.pair-screen {
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(32px + env(safe-area-inset-top)) 24px calc(28px + env(safe-area-inset-bottom));
}

.pair-header {
  text-align: center;
  margin-top: 20px;
}

.craft-logo {
  position: relative;
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  display: grid;
  place-items: center;
}

.logo-icon-img {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  object-fit: cover;
  box-shadow: 0 10px 28px var(--violet-glow);
}

.badge-tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--violet-glow);
  border: 1px solid var(--border-strong);
  color: var(--violet-light);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 14px;
}

.pair-header h1 {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.15;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
}

.pair-subtext {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 auto;
  max-width: 320px;
}

.pair-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  display: grid;
  gap: 16px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
}

.input-group {
  display: grid;
  gap: 6px;
}

.input-group label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  color: var(--text-faint);
  width: 18px;
  height: 18px;
}

.input-wrapper input {
  width: 100%;
  height: 48px;
  padding: 0 14px 0 42px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper input:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px var(--violet-glow);
}

#pairCode {
  font-family: var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.btn {
  height: 48px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s, background 0.2s, opacity 0.2s;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--violet-light), var(--violet));
  color: #fff;
  box-shadow: 0 4px 16px var(--violet-glow);
}

.btn-block {
  width: 100%;
}

.btn-quiet {
  background: var(--bg-card-hover);
  border: 1px solid var(--border);
  color: var(--text);
}

.form-error {
  color: var(--danger);
  font-size: 12px;
  margin: 4px 0 0;
  text-align: center;
}

.pair-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-faint);
  font-size: 12px;
  margin-top: 20px;
}

/* SYNCING STATE - shown in place of the manual form while a scanned QR's
   ?code= is being exchanged for a token. */
.pair-syncing {
  display: grid;
  justify-items: center;
  gap: 16px;
  padding: 32px 0;
  color: var(--text-muted);
  font-size: 14px;
}

.sync-spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--violet-light);
  animation: sync-spin 0.8s linear infinite;
}

@keyframes sync-spin {
  to { transform: rotate(360deg); }
}

/* WORKSPACE SCREEN */
.workspace {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(10px + env(safe-area-inset-top)) 10px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--chrome-bg);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.icon-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: background 0.15s ease;
}
.icon-btn:active { background: var(--bg-card-hover); }

.topbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 4px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-glow);
}

/* TOPBAR FOLDER PICKER - the one thing Craft needs beyond a plain chat
   topbar. A real native <select>, invisible and positioned exactly over
   this button (see .topbar-folder-select below), rather than a custom
   popover: real OS picker UI for free, nothing to keep in sync by hand. */
.topbar-folder-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 40%;
  padding: 6px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}
.topbar-folder-btn svg { flex-shrink: 0; }
#topbarFolderName {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-folder-select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  /* Fills its parent .topbar-folder-btn exactly (which is the positioning
     context) - tapping anywhere on the visible pill hits this instead. */
}

/* SIDEBAR DRAWER - slides in from the left over everything else (a real
   transform, not a display swap, so it's the smooth slide a drawer is
   expected to have) with a tap-to-dismiss backdrop behind it. Replaces the
   old bottom tab bar entirely: new chat, the paired-PC status screen, full
   session history, and the account/theme/disconnect footer all live here
   now instead of being spread across three always-visible tabs. */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.24s ease;
}
.sidebar-backdrop.open { opacity: 1; }

.sidebar-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 61;
  width: min(300px, 84vw);
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top)) 0 calc(10px + env(safe-area-inset-bottom));
  transform: translateX(-100%);
  transition: transform 0.26s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 12px 0 32px rgba(0, 0, 0, 0.3);
}
.sidebar-drawer.open { transform: translateX(0); }

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px 10px 16px;
}
.sidebar-head-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.sidebar-logo-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 7px;
  object-fit: cover;
}
.sidebar-head-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  margin: 0 8px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  transition: background 0.15s ease;
}
.sidebar-nav-item:active { background: var(--bg-card-hover); }
.sidebar-nav-item svg { flex-shrink: 0; color: var(--text-muted); }

.nav-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-section-label {
  margin: 14px 16px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
}
.sidebar-section-label #sessionCount:not(:empty)::before { content: '· '; }

.sidebar-drawer .session-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 8px;
}

.sidebar-footer {
  padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  margin-top: 6px;
}

.account-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 8px 4px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}

.account-avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--violet);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  display: grid;
  place-items: center;
}

.account-text { min-width: 0; }
.account-text strong {
  display: block;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-text span {
  font-size: 11px;
  color: var(--text-muted);
}

.unpair-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 8px;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s ease;
}
.unpair-btn:active { background: var(--danger-bg); }

/* THEME ROW - dark / light / system, defaulting to system (see
   applyTheme() in mobile.js). */
.theme-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
}
.theme-row-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.theme-toggle {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}
.theme-opt {
  width: 28px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--text-faint);
  background: none;
  border: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.theme-opt svg { width: 14px; height: 14px; }
.theme-opt.active {
  background: var(--bg-card-active);
  color: var(--violet);
}

/* MAIN SCROLL AREA */
.main-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* Bottom padding just needs to clear the floating composer now - there's
     no bottom tab bar underneath it anymore. */
  padding: 16px 18px calc(84px + env(safe-area-inset-bottom));
  background: var(--bg);
}

/* STARTER VIEW */
.starter-hero {
  text-align: center;
  padding: 12px 10px 20px;
}

.starter-hero h2 {
  font-size: 21px;
  font-weight: 800;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
  color: var(--text);
}

.starter-hero p {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
  margin: 0 auto;
  max-width: 300px;
}

.action-grid {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.action-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  text-align: left;
  transition: border-color 0.2s, background 0.2s;
}

.action-card:active {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
}

.card-icon {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--bg-card-hover);
  color: var(--text);
  display: grid;
  place-items: center;
}

.card-icon svg {
  width: 17px;
  height: 17px;
}

.card-text strong {
  display: block;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 2px;
}

.card-text span {
  font-size: 12px;
  color: var(--text-muted);
}

/* CHAT FEED - plain text over cards: a colored bubble for the user's own
   message, everything from Craft (status lines and the final answer alike)
   set straight on the background with no card, border, or icon. */
.chat-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message-bubble {
  max-width: 92%;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  animation: message-in 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
.message-bubble strong { font-weight: 700; }

@keyframes message-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Subagent badge - same mascot system as the desktop app, ball +
   eyes as two independent layers, not one flat image. ---- */
.subagent-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 2px;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  width: fit-content;
  background: var(--bg-card);
  border: 1px solid var(--subagent-color, var(--border));
  animation: subagent-bounce-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.subagent-badge-text {
  font-size: 12.5px;
  color: var(--text-muted);
}
.subagent-badge-text strong { color: var(--text); }

.mascot {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
}
.mascot-ball {
  display: block;
  width: 100%;
  height: 100%;
  animation: mascot-ball-idle 3.4s ease-in-out infinite;
}
.mascot-eyes {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 58%;
  height: 58%;
  animation: mascot-eyes-life 6s ease-in-out infinite;
}

@keyframes subagent-bounce-in {
  0% { transform: scale(0.3) translateY(14px); opacity: 0; }
  55% { transform: scale(1.18) translateY(-5px); opacity: 1; }
  75% { transform: scale(0.92) translateY(2px); }
  100% { transform: scale(1) translateY(0); }
}
@keyframes mascot-ball-idle {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
@keyframes mascot-eyes-life {
  0%   { transform: translate(-50%, -50%) translateX(0) scaleY(1); }
  18%  { transform: translate(-50%, -50%) translateX(-10%) scaleY(1); }
  40%  { transform: translate(-50%, -50%) translateX(-10%) scaleY(1); }
  43%  { transform: translate(-50%, -50%) translateX(-10%) scaleY(0.1); }
  46%  { transform: translate(-50%, -50%) translateX(-10%) scaleY(1); }
  60%  { transform: translate(-50%, -50%) translateX(10%) scaleY(1); }
  80%  { transform: translate(-50%, -50%) translateX(0) scaleY(1); }
  90%  { transform: translate(-50%, -50%) translateX(0) scaleY(0.1); }
  93%  { transform: translate(-50%, -50%) translateX(0) scaleY(1); }
  100% { transform: translate(-50%, -50%) translateX(0) scaleY(1); }
}

.message-bubble.user {
  align-self: flex-end;
  background: var(--bubble-user-bg);
  color: var(--bubble-user-text);
  font-weight: 500;
  padding: 11px 15px;
  border-radius: 18px 18px 4px 18px;
}

.message-bubble.agent {
  align-self: flex-start;
  max-width: 100%;
  color: var(--text);
}

.message-bubble.tool {
  align-self: flex-start;
  max-width: 100%;
  color: var(--text-muted);
  font-size: 13.5px;
}

.tool-name {
  font-weight: 500;
}

.tool-screenshot {
  display: block;
  margin-top: 8px;
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.message-bubble.error {
  align-self: flex-start;
  max-width: 100%;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: var(--radius-md);
}

/* SESSION LIST - flat rows, ChatGPT-style: no card border/background, just
   a hover state and a title that truncates, with a "..." affordance that
   only shows up once you're actually looking at the row. */
.session-list {
  display: grid;
  align-content: start;
  gap: 1px;
}

.session-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 8px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  text-align: left;
  transition: background 0.15s ease;
}
.session-card:active,
.session-card:hover { background: var(--bg-card-hover); }

.session-card.active {
  background: var(--bg-card-active);
}

.session-card-title {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-card-more {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--text-faint);
  opacity: 0;
  transition: opacity 0.15s ease;
}
.session-card:hover .session-card-more,
.session-card.active .session-card-more { opacity: 1; }

/* FLOATING COMPOSER */
.composer {
  position: fixed;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: min(600px, 100%);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  z-index: 20;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.composer-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 6px 16px;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.composer-inner:focus-within {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px var(--violet-glow);
}

.composer textarea {
  flex: 1;
  min-height: 20px;
  max-height: 120px;
  padding: 6px 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  resize: none;
}

.composer textarea::placeholder {
  color: var(--text-faint);
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--violet-light), var(--violet));
  color: #fff;
  display: grid;
  place-items: center;
  transition: transform 0.15s, opacity 0.15s;
}

.send-btn:active {
  transform: scale(0.92);
}

/* APPROVAL SHEET MODAL */
.approval-sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  animation: sheet-backdrop-in 0.22s ease both;
}

.sheet-container {
  position: relative;
  width: min(600px, 100%);
  margin: 0 auto;
  background: var(--bg-card);
  border-top: 1px solid var(--border-strong);
  border-radius: 24px 24px 0 0;
  padding: 12px 24px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.5);
  /* Runs fresh every time the sheet goes from display:none to flex (a CSS
     animation restarts on becoming part of layout, no JS needed) - the
     slide-up-and-settle a bottom sheet is expected to have instead of just
     snapping into place. */
  animation: sheet-slide-in 0.28s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes sheet-backdrop-in {
  from { opacity: 0; }
}
@keyframes sheet-slide-in {
  from { transform: translateY(24px); opacity: 0; }
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 0 auto 16px;
}

.sheet-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.sheet-overline {
  color: var(--danger);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.sheet-header h2 {
  font-size: 18px;
  margin: 2px 0 0;
}

.sheet-detail {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  background: var(--bg-card);
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin: 0 0 20px;
  white-space: pre-wrap;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 12px;
}

/* SESSION MENU SHEET - the phone's stand-in for desktop's 3-dot popover. */
.session-menu-container {
  padding-top: 12px;
}

.session-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  border-radius: var(--radius-sm);
  transition: background 0.15s ease;
}
.session-menu-item:active { background: var(--bg-card-hover); }
.session-menu-item.danger { color: var(--danger); }

/* AGENT VIEW SHEET - one row per specialist currently dispatched and
   running on the PC. Tapping a row opens that specialist's own chat (see
   renderAgentsList/openAgentView in mobile.js); the stop icon kills it
   without leaving the sheet. */
.agent-view-container { padding-top: 12px; max-height: 70vh; }
.agent-view-list { max-height: calc(70vh - 90px); overflow-y: auto; }
.agent-view-empty {
  padding: 24px 8px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
}
.agent-view-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease;
}
.agent-view-row:active { background: var(--bg-card-hover); }
.agent-view-row .mascot { width: 32px; height: 32px; }
.agent-view-row-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.agent-view-row-text strong { font-size: 14px; color: var(--text); }
.agent-view-row-text span {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-view-stop {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--danger);
  background: var(--danger-bg);
}
.agent-view-stop:active { opacity: 0.7; }

/* IMAGE PICKER SHEET - mirrors the desktop's search-and-click image card
   (app.js's addImagePickerCard) inside the same bottom-sheet chrome the
   approval sheet uses above. Taller and scrollable internally (the grid can
   run long), capped so it never grows past a usable size on a short phone. */
.image-pick-container {
  max-height: 82vh;
  display: flex;
  flex-direction: column;
}

.image-pick-badge {
  background: var(--violet-glow);
}
.image-pick-badge svg {
  color: var(--violet-light);
}

.img-search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.img-search-input {
  flex: 1;
  height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
}
.img-search-input:focus {
  border-color: var(--violet);
}

.img-search-btn {
  padding: 0 16px;
  border-radius: var(--radius-md);
  background: var(--bg-card-hover);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.img-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.img-grid-status {
  grid-column: 1 / -1;
  padding: 24px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.img-tile {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--border);
  background: var(--bg-card-hover);
}
.img-tile:active {
  border-color: var(--violet);
}
/* contain, not cover - a search result whose actual subject isn't
   centered (or isn't landscape-shaped) was getting its subject cropped
   clean out of frame by a tight cover crop, leaving what looked like a
   blank/irrelevant thumbnail even when the photo itself was a real,
   on-topic match. Showing the whole photo, letterboxed, means the tile
   never lies about what the result actually is. */
.img-tile img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.img-tile-credit {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 4px 8px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent);
  color: #fff;
  font-size: 10px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 601px) {
  .app-shell {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* ---- Sign-in: PC offline card ---- */
.find-title { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 800; }
.find-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 4px var(--danger-bg); }
.find-tips { margin: 0; padding-left: 18px; display: grid; gap: 8px; color: var(--text-muted); font-size: 13px; line-height: 1.5; }
.find-tips strong { color: var(--text); }
.find-hint { margin: 0; color: var(--text-muted); font-size: 12.5px; line-height: 1.5; text-align: center; }
.link-btn { background: none; border: 0; padding: 6px; color: var(--text-muted); font: inherit; font-size: 13px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ---- What actually happened ---- */
.turn-summary { margin: 6px 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-card); font-size: 13px; display: grid; gap: 6px; }
.ts-head { font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.ts-files { display: flex; flex-wrap: wrap; gap: 6px; }
.ts-files span, .ts-check code { font-family: var(--font-mono); font-size: 12px; }
.ts-files span { padding: 2px 8px; border-radius: 6px; background: var(--bg-card-hover); }
.ts-check { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ts-check.pass { color: var(--green); }
.ts-check.fail { color: var(--danger); }
.ts-check code { color: var(--text-muted); }
.ts-warn { padding: 6px 10px; border-radius: 8px; background: rgba(226, 194, 106, .14); color: #d9b24c; font-size: 12.5px; }

/* ---- Goal card ---- */
.goal-card { margin: 6px 0; padding: 12px 14px; border-radius: var(--radius-md); border: 1px solid var(--border-strong); background: var(--bg-card); display: grid; gap: 6px; }
.goal-head { display: flex; align-items: center; justify-content: space-between; font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.goal-pill { padding: 2px 9px; border-radius: var(--radius-full); background: var(--violet-glow); color: var(--violet-light); letter-spacing: 0; text-transform: none; font-size: 11.5px; }
.goal-card[data-status="achieved"] .goal-pill { background: var(--green-glow); color: var(--green); }
.goal-card[data-status="blocked"] .goal-pill, .goal-card[data-status="incomplete"] .goal-pill { background: rgba(226, 194, 106, .16); color: #d9b24c; }
.goal-card[data-status="failed"] .goal-pill, .goal-card[data-status="stopped"] .goal-pill { background: var(--danger-bg); color: var(--danger); }
.goal-text { font-size: 14px; line-height: 1.45; }
.goal-note { font-size: 12.5px; color: var(--text-faint); }

/* ---- Composer tools: model + permission ---- */
.composer-tools { display: flex; gap: 8px; padding: 0 4px 8px; overflow-x: auto; scrollbar-width: none; }
.composer-tools::-webkit-scrollbar { display: none; }
.tool-pill { position: relative; flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--radius-full); border: 1px solid var(--border); background: var(--bg-card); color: var(--text-muted); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; max-width: 62vw; }
.tool-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-pill:active { background: var(--bg-card-hover); }
.tool-pill.danger { color: var(--danger); border-color: rgba(229, 98, 77, .4); background: var(--danger-bg); }
.model-pill select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 16px; }
.model-pill-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: #a78bfa; }
.model-pill-dot[data-kind="custom"] { background: #66a3ff; }
.model-pill-dot[data-kind="local"] { background: var(--green); }

/* Long chat titles end in "..." instead of widening the drawer: a grid column
   otherwise grows to fit its longest item, so ellipsis never kicks in. */
.session-list { grid-template-columns: minmax(0, 1fr); }
.session-card { min-width: 0; }
.sidebar-drawer, .sidebar-drawer .session-list { overflow-x: hidden; }

/* The composer floats over the chat; reserve exactly its real height (kept in
   --composer-h by mobile.js) so the last message never slides under it. */
.main-scroll { padding-bottom: calc(var(--composer-h, 132px) + 12px + env(safe-area-inset-bottom)); }
.composer { background: linear-gradient(to top, var(--bg) 82%, transparent); padding-top: 18px; }

/* Thinking steps (folded narration while the agent works) */
.thinking-step { margin: 2px 0; color: var(--text-faint); font-size: 13px; }
.thinking-step summary { list-style: none; display: inline-flex; align-items: center; gap: 6px; padding: 4px 0; cursor: pointer; font-weight: 600; }
.thinking-step summary::-webkit-details-marker { display: none; }
.thinking-step summary svg { transition: transform .15s ease; }
.thinking-step[open] summary svg { transform: rotate(90deg); }
.thinking-text { margin: 4px 0 6px; padding: 8px 12px; border-left: 2px solid var(--border); color: var(--text-muted); line-height: 1.5; }

/* ---- Tool rows (tap to see the command, the diff, the screenshot) ---- */
.tool-item { margin: 2px 0; border-radius: var(--radius-md); background: var(--bg-card); border: 1px solid var(--border); font-size: 13px; overflow: hidden; }
.tool-item summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 9px 12px; cursor: pointer; min-width: 0; }
.tool-item summary::-webkit-details-marker { display: none; }
.tool-item .tool-verb { font-weight: 700; color: var(--text); flex-shrink: 0; }
.tool-item .tool-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }
.tool-item .tool-stats { flex-shrink: 0; display: inline-flex; gap: 6px; font-family: var(--font-mono); font-size: 11.5px; font-weight: 600; }
.stat-add, .stat-ok { color: var(--green); }
.stat-del { color: var(--danger); }
.tool-item .tool-chev { flex-shrink: 0; color: var(--text-faint); transition: transform .15s ease; }
.tool-item[open] .tool-chev { transform: rotate(90deg); }
.tool-item.no-body .tool-chev { visibility: hidden; }
.tool-item.failed { border-color: rgba(229, 98, 77, .35); }
.tool-body { padding: 0 12px 10px; display: grid; gap: 6px; }
.tool-body:empty { display: none; }
.tool-body-label { font-size: 11.5px; color: var(--text-faint); font-family: var(--font-mono); overflow-wrap: anywhere; }
.tool-code { margin: 0; padding: 8px 10px; border-radius: 8px; background: var(--bg); font-family: var(--font-mono); font-size: 11.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 260px; overflow-y: auto; color: var(--text-muted); }
.tool-code.diff-del { background: rgba(229, 98, 77, .10); color: #f0a497; }
.tool-code.diff-add { background: rgba(76, 195, 138, .10); color: #8fe0b7; }
.tool-item .tool-screenshot { width: 100%; border-radius: 8px; border: 1px solid var(--border); display: block; }

.lightbox { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .9); }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }
.tool-item .tool-screenshot { cursor: zoom-in; }
