:root {
  --bg: #f4f6f9;
  --bg-elevated: #ffffff;
  --bg-muted: #e8ecf1;
  --border: #d8dee6;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --accent-text: #1e40af;
  --sidebar-bg: #0f172a;
  --sidebar-text: #f1f5f9;
  --sidebar-muted: #94a3b8;
  --sidebar-active: #1e293b;
  --sidebar-accent: #3b82f6;
  --success: #059669;
  --warning: #d97706;
  --error: #dc2626;
  --favorite: #f59e0b;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 20px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 48px rgba(15, 23, 42, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --sidebar-width: 272px;
  --header-height: 60px;
  --tabs-height: 44px;
}

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

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100dvh;
}

.hidden { display: none !important; }
.hide-mobile { display: inline-flex; }

/* Buttons */
.btn-primary, .btn-secondary, .btn-ghost, .btn-icon, .btn-link {
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.875rem;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 0.875rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
}
.btn-secondary:hover { background: var(--bg-muted); }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
}
.btn-ghost:hover { background: var(--bg-muted); color: var(--text); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg-muted); color: var(--text); }

.btn-link {
  background: none;
  color: var(--sidebar-accent);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0;
}
.btn-link:hover { text-decoration: underline; }

.btn-full { width: 100%; }
.btn-sm { font-size: 0.75rem; padding: 0.375rem 0.625rem; }
.btn-send { width: 2.5rem; height: 2.5rem; padding: 0; border-radius: 50%; flex-shrink: 0; }

/* Fields */
.field { display: flex; flex-direction: column; gap: 0.375rem; }
.field-label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.field input, .field textarea, .field select {
  font-family: inherit;
  font-size: 0.875rem;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.875rem; }

/* Onboarding */
.onboarding {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: linear-gradient(160deg, #eff6ff 0%, var(--bg) 50%);
}
.onboarding-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 2.25rem 1.75rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.onboarding-brand { text-align: center; margin-bottom: 1.75rem; }
.logo-icon { font-size: 1.75rem; line-height: 1; }
.logo-icon.large { font-size: 2.75rem; display: block; margin-bottom: 0.5rem; }
.onboarding-title { font-size: 2rem; font-weight: 700; margin: 0; letter-spacing: -0.03em; color: var(--text); }
.onboarding-tagline { color: var(--text-muted); margin: 0.25rem 0 0; font-size: 0.875rem; }
.onboarding-step h2 { font-size: 1.125rem; margin: 0 0 0.375rem; font-weight: 600; }
.step-desc { color: var(--text-muted); font-size: 0.875rem; margin: 0 0 1.25rem; }
#connect-form { display: flex; flex-direction: column; gap: 0.875rem; }
#btn-resume-session { display: block; margin: 1rem auto 0; }

/* Layout */
.app { display: flex; height: 100dvh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1.125rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.logo { display: flex; align-items: center; gap: 0.625rem; }
.logo-title { font-size: 1.25rem; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.logo-subtitle { margin: 0; font-size: 0.6875rem; color: var(--sidebar-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.sidebar-close { display: none; color: var(--sidebar-muted); }
.sidebar-close:hover { background: rgba(255,255,255,0.08); color: #fff; }

.company-badge { padding: 0.75rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.06); }
.company-badge-name { display: block; font-weight: 600; font-size: 0.875rem; margin-bottom: 0.125rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.agents-nav { flex: 1; overflow-y: auto; padding: 0.5rem; }

.agent-nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.625rem 0.75rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-family: inherit;
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
  margin-bottom: 2px;
}
.agent-nav-item:hover { background: rgba(255,255,255,0.05); }
.agent-nav-item.active { background: var(--sidebar-active); box-shadow: inset 3px 0 0 var(--sidebar-accent); }
.agent-nav-icon { font-size: 1.125rem; flex-shrink: 0; }
.agent-nav-name { display: block; font-weight: 500; }
.agent-nav-role { display: block; font-size: 0.6875rem; color: var(--sidebar-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer { padding: 0.625rem; border-top: 1px solid rgba(255,255,255,0.06); }
.sidebar-footer .btn-ghost { color: var(--sidebar-muted); width: 100%; justify-content: center; font-size: 0.75rem; }
.sidebar-footer .btn-ghost:hover { background: rgba(255,255,255,0.05); color: #fff; }

.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 90; }

.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.main-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  height: var(--header-height);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 50;
}

#sidebar-open { display: none; }

.agent-header { display: flex; align-items: center; gap: 0.625rem; flex: 1; min-width: 0; }
.agent-header-icon { font-size: 1.375rem; flex-shrink: 0; }
.agent-header-title { font-size: 0.9375rem; font-weight: 600; margin: 0; }
.agent-header-desc { font-size: 0.75rem; color: var(--text-muted); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Welcome */
.welcome { flex: 1; padding: 2rem 1.25rem; overflow-y: auto; }
.welcome-content { max-width: 880px; margin: 0 auto; }
.welcome-eyebrow { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); margin: 0 0 0.5rem; }
.welcome-title { font-size: clamp(1.5rem, 4vw, 2.125rem); font-weight: 700; line-height: 1.2; margin: 0 0 0.75rem; letter-spacing: -0.03em; }
.welcome-text { color: var(--text-muted); max-width: 520px; margin: 0 0 1.75rem; font-size: 0.9375rem; }

.agents-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.875rem; }

.agent-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.125rem;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.agent-card:hover { border-color: var(--accent); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.agent-card-icon { font-size: 1.75rem; margin-bottom: 0.625rem; display: block; }
.agent-card-name { font-size: 0.9375rem; font-weight: 600; margin: 0 0 0.25rem; color: var(--text); }
.agent-card-desc { font-size: 0.75rem; color: var(--text-muted); margin: 0; line-height: 1.45; }

/* Chat */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* Barre du haut du chat : toggle + onglets (hors zone scroll) */
.chat-top {
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--bg-elevated);
}

.view-toggle {
  display: inline-flex;
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.view-toggle-btn {
  position: relative;
  padding: 0.375rem 0.875rem;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.view-toggle-btn:hover { color: var(--text); }
.view-toggle-btn.active { background: var(--bg-elevated); color: var(--text); box-shadow: var(--shadow-sm); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.125rem;
  height: 1.125rem;
  padding: 0 0.3rem;
  margin-left: 0.25rem;
  background: var(--favorite);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  border-radius: 99px;
}

/* Thread tabs */
.thread-tabs {
  background: var(--bg-elevated);
  padding: 0 0.5rem 0.25rem;
}

.thread-tabs-hint {
  margin: 0;
  padding: 0 0.75rem 0.375rem;
  font-size: 0.6875rem;
  color: var(--text-subtle);
}

.thread-tabs-scroll {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  min-height: var(--tabs-height);
}

.thread-tabs-list {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 0.375rem 0;
}
.thread-tabs-list::-webkit-scrollbar { display: none; }

.thread-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  max-width: 180px;
  transition: background 0.15s, border-color 0.15s;
}
.thread-tab:hover { background: var(--bg-muted); }
.thread-tab.active { background: var(--accent-soft); border-color: #bfdbfe; }

.thread-tab-label {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0.375rem 0.25rem 0.375rem 0.625rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.thread-tab.active .thread-tab-label { color: var(--accent-text); font-weight: 600; }

.thread-tab-rename {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 4px;
  color: var(--text-subtle);
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.thread-tab:hover .thread-tab-rename,
.thread-tab.active .thread-tab-rename { opacity: 1; }
.thread-tab-rename:hover { background: var(--bg-muted); color: var(--accent); }

.thread-tab-input {
  font-family: inherit;
  font-size: 0.8125rem;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--accent);
  border-radius: 4px;
  width: 130px;
  outline: none;
}

.thread-tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.375rem;
  height: 1.375rem;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 4px;
  color: var(--text-subtle);
  cursor: pointer;
  flex-shrink: 0;
  margin-right: 0.25rem;
}
.thread-tab-close:hover { background: rgba(220,38,38,0.1); color: var(--error); }

.thread-tab-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 1px dashed var(--border);
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
}
.thread-tab-add:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message { max-width: min(720px, 100%); animation: fadeIn 0.2s ease; }
.message-user { align-self: flex-end; }
.message-assistant { align-self: flex-start; }

.message-bubble {
  position: relative;
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  line-height: 1.55;
}
.message-user .message-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.message-assistant .message-bubble { background: var(--bg-elevated); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.msg-action-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: none;
  background: var(--bg-muted);
  border-radius: 6px;
  color: var(--text-subtle);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.message-bubble:hover .msg-action-btn { opacity: 1; }
.msg-action-btn.is-favorite, .msg-action-btn:hover { opacity: 1; background: #fef3c7; color: var(--favorite); }

.message-meta { font-size: 0.6875rem; color: var(--text-subtle); margin-top: 0.25rem; padding: 0 0.25rem; }
.message-user .message-meta { text-align: right; }
.message-content p { margin: 0 0 0.625rem; }
.message-content p:last-child { margin-bottom: 0; }

.message-loading .message-bubble { display: flex; align-items: center; gap: 0.5rem; color: var(--text-muted); }
.message-error .message-bubble { background: #fef2f2; border-color: #fecaca; color: var(--error); }

.loading-dots { display: flex; gap: 3px; }
.loading-dots span { width: 5px; height: 5px; background: var(--text-subtle); border-radius: 50%; animation: bounce 1.2s infinite; }
.loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.loading-dots span:nth-child(3) { animation-delay: 0.3s; }

/* Canvas */
.canvas-block { margin: 0.75rem 0; }
.canvas-block:first-child { margin-top: 0.25rem; }

.canvas-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.canvas-card-header, .canvas-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border);
}
.canvas-card-title { font-weight: 600; font-size: 0.75rem; color: var(--text); flex: 1; min-width: 0; }
.canvas-card-body { padding: 0.75rem; font-size: 0.8125rem; white-space: pre-wrap; }

.canvas-metric-wrap, .canvas-quote-wrap, .canvas-list-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  background: var(--bg);
}
.canvas-metric-wrap .canvas-actions,
.canvas-quote-wrap .canvas-actions,
.canvas-list-wrap .canvas-list-header .canvas-actions { margin-left: auto; }

.canvas-metric {
  display: inline-flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.625rem 0.875rem;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
}
.canvas-metric-label { font-size: 0.6875rem; color: var(--accent-text); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.canvas-metric-value { font-size: 1.25rem; font-weight: 700; color: var(--accent-text); }
.canvas-metric-trend { font-size: 0.6875rem; color: var(--success); }

.canvas-list { margin: 0.5rem 0 0; padding-left: 1.125rem; font-size: 0.8125rem; }
.canvas-list li { margin-bottom: 0.3rem; }

.canvas-quote { border-left: 3px solid var(--accent); padding: 0.25rem 0 0.25rem 0.875rem; font-size: 0.9375rem; font-style: italic; color: var(--text-muted); }

.canvas-actions { display: inline-flex; gap: 0.25rem; flex-shrink: 0; }
.canvas-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.625rem;
  height: 1.625rem;
  padding: 0;
  border: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.canvas-action-btn:hover { background: var(--bg-muted); color: var(--text); }
.canvas-action-btn.is-favorite { background: #fef3c7; border-color: #fcd34d; color: var(--favorite); }

/* Favorites */
.favorites-empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
  max-width: 360px;
  margin: auto;
}
.favorites-empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.favorites-empty h3 { margin: 0 0 0.375rem; font-size: 1rem; color: var(--text); }
.favorites-empty p { margin: 0; font-size: 0.875rem; }

.favorite-item { max-width: 720px; width: 100%; }
.favorite-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.6875rem;
  color: var(--text-subtle);
  margin-bottom: 0.375rem;
}
.favorite-thread { font-weight: 600; color: var(--accent-text); }

.favorite-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.favorite-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border);
}
.favorite-type { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.favorite-actions { display: flex; gap: 0.25rem; }
.favorite-body { padding: 0.875rem; }
.favorite-actions-bar { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

/* Chat input */
.chat-input-area {
  padding: 0.75rem 1rem 1rem;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 0.625rem;
  max-width: 800px;
  margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.5rem 0.5rem 0.875rem;
}
.chat-input-wrapper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.875rem;
  resize: none;
  max-height: 140px;
  line-height: 1.5;
  padding: 0.375rem 0;
  min-width: 0;
}
.chat-input:focus { outline: none; }

.chat-hint { text-align: center; font-size: 0.6875rem; color: var(--text-subtle); margin: 0.375rem 0 0; }

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  background: var(--sidebar-bg);
  color: #fff;
  padding: 0.625rem 1.125rem;
  border-radius: 99px;
  font-size: 0.8125rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 200;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Modal */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(680px, calc(100vw - 1.5rem));
  width: 100%;
  max-height: calc(100dvh - 1.5rem);
}
.modal::backdrop { background: rgba(15, 23, 42, 0.5); }

.modal-content {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: calc(100dvh - 1.5rem);
  margin: 0;
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1.125rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { margin: 0; font-size: 1.125rem; font-weight: 600; }
.modal-subtitle { margin: 0.2rem 0 0; font-size: 0.8125rem; color: var(--text-muted); }
.modal-body { flex: 1; overflow-y: auto; padding: 1.125rem 1.25rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.625rem; padding: 0.875rem 1.25rem; border-top: 1px solid var(--border); flex-shrink: 0; }

.profile-section { border: none; margin: 0 0 1.5rem; padding: 0; }
.profile-section legend { font-weight: 600; font-size: 0.875rem; padding: 0; margin-bottom: 0.75rem; }

.repeatable { margin-top: 0.75rem; }
.repeatable-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.625rem; }
.repeatable-item { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.875rem; margin-bottom: 0.625rem; position: relative; }
.repeatable-item .btn-remove {
  position: absolute; top: 0.375rem; right: 0.375rem;
  width: 1.5rem; height: 1.5rem; padding: 0; background: transparent; border: none;
  color: var(--text-subtle); cursor: pointer; border-radius: 4px; font-size: 1rem;
}
.repeatable-item .btn-remove:hover { background: var(--bg-muted); color: var(--error); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-3px); } }

/* Responsive */
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }

  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-flex; }
  .sidebar-overlay.open { display: block; }
  .main { margin-left: 0; }
  #sidebar-open { display: inline-flex; }

  .main-header { padding: 0 0.75rem; gap: 0.5rem; }
  .agent-header-desc { display: none; }

  .welcome { padding: 1.25rem 0.875rem; }
  .agents-grid { grid-template-columns: 1fr; }

  .chat-toolbar { padding: 0.375rem 0.75rem; }
  .thread-tabs { padding: 0 0.375rem; }
  .thread-tab { max-width: 140px; }
  .thread-tab-label { max-width: 100px; font-size: 0.75rem; }

  .chat-messages { padding: 0.875rem 0.75rem; }
  .message { max-width: 100%; }
  .message-bubble { padding: 0.75rem 0.875rem; font-size: 0.8125rem; }

  .msg-action-btn { opacity: 1; width: 1.5rem; height: 1.5rem; }

  .chat-input-area { padding: 0.625rem 0.75rem 0.875rem; }
  .onboarding-card { padding: 1.75rem 1.25rem; }

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

@media (max-width: 380px) {
  .view-toggle-btn { padding: 0.375rem 0.625rem; font-size: 0.75rem; }
  .thread-tab-add { width: 1.5rem; height: 1.5rem; }
}

@media (hover: none) {
  .msg-action-btn { opacity: 1; }
  .canvas-action-btn { width: 1.75rem; height: 1.75rem; }
  .thread-tab-rename { opacity: 1; }
}
