/* AGY Sycap V2 — Flagship iOS 18 Native Standalone Design System */
:root {
  color-scheme: light;
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --header-glass: rgba(255, 255, 255, 0.86);
  --ink: #0f172a;
  --ink-2: #1e293b;
  --muted: #475569;
  --muted-soft: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --teal: #0f766e;
  --teal-bright: #0d9488;
  --teal-light: #14b8a6;
  --teal-soft: #f0fdfa;
  --teal-soft-2: #ccfbf1;
  --teal-border: #99f6e4;
  --focus-ring: rgba(13, 148, 136, 0.24);
  --user-grad: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
  --code-bg: #f8fafc;
  --code-ink: #1e293b;
  --code-border: #e2e8f0;
  --red: #e11d48;
  --red-soft: #ffe4e6;
  --red-border: #fda4af;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --amber-border: #fcd34d;
  --shadow-xs: 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-card: 0 2px 12px rgba(15, 23, 42, 0.045);
  --shadow-composer: 0 8px 28px rgba(15, 23, 42, 0.085);
  --shadow-sheet: 0 -8px 40px rgba(15, 23, 42, 0.18);
  --backdrop: rgba(15, 23, 42, 0.44);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --app-height: 100dvh;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090e16;
  --surface: #111926;
  --surface-2: #162131;
  --surface-3: #1d2b3f;
  --header-glass: rgba(12, 18, 28, 0.86);
  --ink: #f1f5f9;
  --ink-2: #e2e8f0;
  --muted: #94a3b8;
  --muted-soft: #64748b;
  --border: #1e2d40;
  --border-strong: #2c4059;
  --teal: #0d9488;
  --teal-bright: #14b8a6;
  --teal-light: #2dd4bf;
  --teal-soft: rgba(20, 184, 166, 0.12);
  --teal-soft-2: rgba(20, 184, 166, 0.2);
  --teal-border: rgba(45, 212, 191, 0.35);
  --focus-ring: rgba(45, 212, 191, 0.28);
  --user-grad: linear-gradient(135deg, #0d9488 0%, #115e59 100%);
  --code-bg: #0c131d;
  --code-ink: #e2e8f0;
  --code-border: #233347;
  --red: #fb7185;
  --red-soft: rgba(225, 29, 72, 0.18);
  --red-border: rgba(251, 113, 133, 0.35);
  --amber: #fbbf24;
  --amber-soft: rgba(245, 158, 11, 0.16);
  --amber-border: rgba(251, 191, 36, 0.35);
  --shadow-xs: 0 1px 4px rgba(0, 0, 0, 0.25);
  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.28);
  --shadow-composer: 0 10px 32px rgba(0, 0, 0, 0.48);
  --shadow-sheet: 0 -10px 44px rgba(0, 0, 0, 0.65);
  --backdrop: rgba(2, 6, 14, 0.68);
}

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

*::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
*::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  height: var(--app-height);
  overflow: hidden;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  letter-spacing: -0.008em;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  touch-action: manipulation;
}

button, [role="button"], summary {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--teal-bright);
  outline-offset: 2px;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ==================== AUTH SCREEN ==================== */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 20px) 20px calc(var(--safe-bottom) + 20px);
  background:
    radial-gradient(circle at 20% 15%, rgba(20, 184, 166, 0.22), transparent 48%),
    radial-gradient(circle at 85% 85%, rgba(15, 118, 110, 0.28), transparent 52%),
    #09141a;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  color: var(--ink);
  border-radius: 26px;
  padding: 28px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.42);
  border: 1px solid var(--border);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 20px;
}

.auth-logo {
  width: 58px;
  height: 58px;
  border-radius: 17px;
  background: var(--user-grad);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  box-shadow: 0 8px 22px rgba(13, 148, 136, 0.36);
}

.auth-brand h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-brand p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.field-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
  text-align: center;
}

.pin-input {
  width: 100%;
  min-height: 52px;
  padding: 10px 16px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-align: center;
  border-radius: 15px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--ink);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.pin-input:focus {
  outline: none;
  border-color: var(--teal-bright);
  box-shadow: 0 0 0 4px var(--focus-ring);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  margin-top: 14px;
  padding: 12px 18px;
  border: none;
  border-radius: 15px;
  background: var(--user-grad);
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(15, 118, 110, 0.26);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.btn-primary:active {
  transform: scale(0.985);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.error-banner {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--red-soft);
  border: 1px solid var(--red-border);
  color: var(--red);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}

/* ==================== APP SHELL ==================== */
.app-shell {
  display: flex;
  width: 100%;
  max-width: 100%;
  height: var(--app-height);
  overflow: hidden;
  background: var(--bg);
}

/* ==================== SIDEBAR / SLIDE-OVER ==================== */
.sidebar {
  width: 312px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 50;
}

.sidebar-top {
  padding: calc(var(--safe-top) + 12px) 14px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.sidebar-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-mini-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--user-grad);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(13, 148, 136, 0.28);
}

.sidebar-brand-text strong {
  display: block;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.15;
}

.sidebar-brand-text span {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 44px;
  padding: 9px 14px;
  border: none;
  border-radius: 13px;
  background: var(--user-grad);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.2);
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 11px;
  color: var(--muted-soft);
  pointer-events: none;
}

.search-input {
  width: 100%;
  min-height: 40px;
  padding: 7px 12px 7px 35px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 16px;
}

.search-input:focus {
  outline: none;
  border-color: var(--teal-bright);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.segmented-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border-radius: 11px;
  background: var(--surface-3);
}

.seg-btn {
  min-height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: none;
  padding: 10px 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.conv-list::-webkit-scrollbar {
  display: none;
}

.section-cap {
  padding: 8px 8px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.conv-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 13px;
  border: 1px solid transparent;
  background: transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.conv-card:hover {
  background: var(--surface-2);
}

.conv-card.active {
  background: var(--teal-soft);
  border-color: var(--teal-border);
}

.conv-select-btn {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 10px 8px 10px 11px;
  border: none;
  background: transparent;
  color: var(--ink);
}

.conv-title-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.conv-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
  flex-shrink: 0;
}
.conv-dot.pinned {
  background: var(--teal-bright);
}
.conv-dot.running {
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25);
  animation: pulse 1.4s infinite ease-in-out;
}

.conv-title-text {
  font-size: 13.8px;
  font-weight: 650;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-preview-text {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-meta-line {
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted-soft);
}

.ws-chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--muted);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 10.5px;
  font-weight: 600;
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-del-btn {
  min-width: 38px;
  min-height: 44px;
  margin-right: 4px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.72;
}

.conv-del-btn:hover {
  color: var(--red);
  background: var(--red-soft);
  opacity: 1;
}

.sidebar-foot {
  padding: 10px 14px calc(var(--safe-bottom) + 10px);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--muted);
}

.live-foot-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.live-foot-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  backdrop-filter: blur(2px);
  z-index: 45;
}

/* ==================== MAIN CHAT COLUMN ==================== */
.main-pane {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

/* Frosted iOS 18 Navigation Bar */
.topbar {
  flex-shrink: 0;
  background: var(--header-glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
  padding: calc(var(--safe-top) + 5px) 10px 6px;
  z-index: 30;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 44px;
}

.nav-circle-btn {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.15s ease;
}

.nav-circle-btn:hover {
  background: var(--surface-3);
}

.nav-badge-dot {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  border: 1.5px solid var(--surface);
}

.title-pill-btn {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 3px 10px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.title-pill-btn:hover {
  background: var(--surface-3);
}

.header-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--ink);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-sub {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  flex-shrink: 0;
}
.header-live-dot.offline {
  background: #f59e0b;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

/* ==================== MESSAGES STREAM ==================== */
.messages-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 16px 14px 12px;
}

.messages-inner {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.thread-banner {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  box-shadow: var(--shadow-xs);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Empty State Hero */
.empty-state {
  margin: 24px auto 10px;
  max-width: 520px;
  width: 100%;
  text-align: center;
  padding: 8px 6px;
}

.empty-orb {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 18px;
  background: var(--user-grad);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 26px rgba(13, 148, 136, 0.28);
}

.empty-state h2 {
  margin: 0 0 6px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.empty-state p {
  margin: 0 0 18px;
  font-size: 13.5px;
  color: var(--muted);
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  text-align: left;
}

.suggestion-card {
  padding: 13px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
  transition: border-color 0.16s ease, transform 0.15s ease;
}

.suggestion-card:hover {
  border-color: var(--teal-bright);
}

.suggestion-card strong {
  display: block;
  font-size: 13.5px;
  font-weight: 650;
  margin-bottom: 3px;
}

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

/* User Bubble */
.msg-user-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 0;
}

.msg-user-bubble {
  max-width: 84%;
  background: var(--user-grad);
  color: #ffffff;
  padding: 11px 15px;
  border-radius: 20px 20px 5px 20px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  box-shadow: 0 4px 14px rgba(15, 118, 110, 0.18);
}

.msg-time {
  margin-top: 4px;
  padding: 0 4px;
  font-size: 11px;
  color: var(--muted-soft);
}

/* Assistant Card */
.msg-ai-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
  min-width: 0;
}

.msg-ai-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}

.ai-avatar {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--teal-soft-2);
  color: var(--teal);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.ai-model-pill {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
}

.ai-head-right {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted-soft);
}

/* Sleek Thought & Tool Pills */
.trace-pill-box {
  margin: 4px 0 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  overflow: hidden;
}

.trace-pill-box summary {
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  list-style: none;
  user-select: none;
}
.trace-pill-box summary::-webkit-details-marker {
  display: none;
}

.trace-content {
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 240px;
  overflow-y: auto;
}

.tools-stack {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 4px 0 10px;
}

.tool-acc {
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  overflow: hidden;
}

.tool-acc summary {
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  list-style: none;
  min-width: 0;
}
.tool-acc summary::-webkit-details-marker {
  display: none;
}

.tool-badge {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--teal-soft-2);
  color: var(--teal);
  flex-shrink: 0;
}

.tool-badge.active {
  background: var(--amber-soft);
  color: var(--amber);
}

.tool-summary-txt {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.tool-out-pre {
  margin: 0;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--code-bg);
  color: var(--code-ink);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-height: 200px;
  overflow-y: auto;
}

/* Markdown Typography */
.md-body {
  font-size: 15px;
  line-height: 1.62;
  color: var(--ink);
  word-break: break-word;
  overflow-wrap: anywhere;
}

.md-body p { margin: 0 0 10px; }
.md-body p:last-child { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 {
  margin: 14px 0 6px;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.3;
}
.md-body h1 { font-size: 17.5px; }
.md-body h2 { font-size: 16px; }
.md-body h3 { font-size: 15px; }
.md-body ul, .md-body ol { margin: 6px 0 10px; padding-left: 20px; }
.md-body li { margin-bottom: 4px; }
.md-body a { color: var(--teal-bright); text-decoration: none; font-weight: 500; }
.md-body a:hover { text-decoration: underline; }

.md-body code {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12.5px;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  color: var(--code-ink);
}

.code-card {
  margin: 10px 0;
  border-radius: 13px;
  border: 1px solid var(--code-border);
  background: var(--code-bg);
  overflow: hidden;
}

.code-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 11px;
  background: var(--surface-3);
  border-bottom: 1px solid var(--code-border);
  font-size: 11.5px;
  color: var(--muted);
}

.copy-code-btn {
  min-height: 28px;
  padding: 2px 10px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 600;
}

.code-card pre {
  margin: 0;
  padding: 11px 13px;
  background: var(--code-bg);
  color: var(--code-ink);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.code-card pre code {
  padding: 0;
  border: none;
  background: transparent;
}

.md-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 11px;
}
.md-body table { width: 100%; border-collapse: collapse; font-size: 13px; }
.md-body th, .md-body td { padding: 7px 10px; border: 1px solid var(--border); text-align: left; }
.md-body th { background: var(--surface-2); font-weight: 700; }

.live-run-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--teal-bright);
}

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--teal-border);
  border-top-color: var(--teal-bright);
  animation: spin 0.75s linear infinite;
}

/* ==================== FLOATING iOS ISLAND COMPOSER ==================== */
.composer-dock {
  flex-shrink: 0;
  padding: 6px 12px calc(var(--safe-bottom) + 10px);
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}

.composer-island {
  max-width: 780px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  padding: 8px 10px 8px 14px;
  box-shadow: var(--shadow-composer);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.composer-island:focus-within {
  border-color: var(--teal-bright);
  box-shadow: 0 8px 30px rgba(13, 148, 136, 0.14), 0 0 0 3px var(--focus-ring);
}

.composer-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  padding: 4px 2px 6px 0;
  min-height: 34px;
  max-height: 135px;
  resize: none;
  display: block;
}

.composer-input:focus {
  outline: none;
}

.composer-input::placeholder {
  color: var(--muted-soft);
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-top: 4px;
}

.composer-chips {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  min-width: 0;
}
.composer-chips::-webkit-scrollbar {
  display: none;
}

.micro-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.micro-chip:hover {
  border-color: var(--teal-bright);
  background: var(--teal-soft);
}

.micro-chip svg {
  color: var(--teal-bright);
  flex-shrink: 0;
}

.micro-chip.plan {
  background: var(--amber-soft);
  border-color: var(--amber-border);
  color: var(--amber);
}
.micro-chip.plan svg {
  color: var(--amber);
}

.send-orb, .stop-orb {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  flex-shrink: 0;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.send-orb {
  background: var(--user-grad);
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.28);
}

.send-orb:disabled {
  opacity: 0.35;
  box-shadow: none;
  cursor: not-allowed;
}

.stop-orb {
  background: var(--red);
  box-shadow: 0 4px 12px rgba(225, 29, 72, 0.35);
}

/* ==================== iOS BOTTOM SHEETS (DIALOG) ==================== */
.ios-sheet {
  border: none;
  padding: 0;
  margin: auto auto 0 auto;
  width: min(560px, 100vw);
  max-width: 100vw;
  max-height: calc(var(--app-height) - 28px);
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sheet);
  overflow: hidden;
}

@media (min-width: 640px) {
  .ios-sheet {
    margin: auto;
    width: min(520px, calc(100vw - 32px));
    border-radius: 22px;
  }
}

.ios-sheet::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(3px);
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  margin: 9px auto 2px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px 12px;
  border-bottom: 1px solid var(--border);
}

.sheet-header h2 {
  margin: 0;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.sheet-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--surface-3);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sheet-scroll {
  padding: 14px 16px calc(var(--safe-bottom) + 20px);
  overflow-y: auto;
  max-height: calc(var(--app-height) - 96px);
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Picker List inside Sheet */
.picker-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.picker-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 50px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  text-align: left;
}

.picker-option.selected {
  border-color: var(--teal-bright);
  background: var(--teal-soft);
}

.picker-opt-main strong {
  display: block;
  font-size: 14px;
  font-weight: 650;
}

.picker-opt-main span {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
}

.picker-badge {
  font-size: 11px;
  font-weight: 650;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
}

.picker-option.selected .picker-badge {
  background: var(--teal);
  color: #ffffff;
}

/* Grouped Model Family Card (11 Families / 27 Models) */
.model-family-card {
  border-radius: 15px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.model-family-card.active-family {
  border-color: var(--teal-bright);
  background: var(--teal-soft);
}

.model-family-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.model-family-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 650;
  color: var(--ink);
}

.model-new-tag {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
}

.model-new-tag.notice {
  background: var(--amber-soft);
  color: var(--amber);
}

.tier-pills-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(56px, 1fr));
  gap: 5px;
}

.tier-pill-btn {
  min-height: 36px;
  padding: 4px 6px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  transition: background-color 0.14s ease, border-color 0.14s ease;
}

.tier-pill-btn.selected {
  background: var(--user-grad);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(15, 118, 110, 0.25);
}

/* KPI Grid in Hub Sheet */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.kpi-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 15px;
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.kpi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  white-space: nowrap;
}

.kpi-head small {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 10px;
  color: var(--muted-soft);
  white-space: nowrap;
}

.kpi-val {
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.kpi-sub {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-bar {
  height: 4px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 3px;
}
.kpi-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--teal-bright);
}

.hub-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  background: var(--surface-2);
}

.hub-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.hub-card h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.hub-card p {
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--muted);
}

.link-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 8px;
}

.link-row-info {
  min-width: 0;
  flex: 1;
}

.link-row-tag {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 2px;
}

.link-row-url {
  display: block;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 11.5px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-soft {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 7px 13px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.btn-soft.teal {
  background: var(--user-grad);
  border-color: transparent;
  color: #ffffff;
}

.btn-soft.danger {
  color: var(--red);
  border-color: var(--red-border);
  background: var(--red-soft);
}

.btn-group-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--teal-soft-2);
  color: var(--teal);
}

.status-chip.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 92px);
  transform: translateX(-50%);
  z-index: 130;
  background: #0f172a;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  max-width: calc(100vw - 32px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

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

/* ==================== MOBILE SLIDE-OVER (<= 900px) ==================== */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(318px, 86vw);
    transform: translateX(-103%);
    transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 16px 0 40px rgba(0, 0, 0, 0.22);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .suggestion-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 901px) {
  #btnToggleDrawer,
  #btnCloseDrawer,
  .drawer-backdrop {
    display: none !important;
  }
}
