:root {
  --bg: #f4f6f8;
  --panel: #fff;
  --panel-soft: #f8fafc;
  --border: #e5e7eb;
  --text: #0f172a;
  --muted: #64748b;
  --green: #22c55e;
  --green-deep: #15803d;
  --danger: #ef4444;
  --shadow: 0 12px 40px #0f172a14;
}

* { box-sizing: border-box; }
html, body, #root {
  background: var(--bg);
  min-height: 100%;
  color: var(--text);
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, sans-serif;
}
button, input, textarea, select { font: inherit; }
body { min-height: 100vh; }
.loading-screen { min-height: 100vh; color: var(--muted); place-items: center; display: grid; }
.app-shell { display: grid; grid-template-columns: 320px 1fr; min-height: 100vh; }
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 16px;
  color: #e5e7eb;
  background: #111827;
  border-right: 1px solid #ffffff14;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; }
.sidebar-brand h1 { margin: 0; font-size: 1.15rem; }
.sidebar-brand p { margin: 4px 0 0; font-size: .92rem; color: #94a3b8; }
.brand-mark, .avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  color: #062312;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  font-weight: 800;
}
.sidebar-nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.nav-pill, .ghost-button, .primary-button {
  cursor: pointer;
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  transition: all .18s;
}
.nav-pill { color: #cbd5e1; background: #ffffff0f; }
.nav-pill.active { color: #dcfce7; background: #22c55e33; }
.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid #ffffff14;
  border-radius: 18px;
  background: #ffffff08;
}
.section-label {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #94a3b8;
}
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.section-note { color: #94a3b8; font-size: .78rem; }
.sidebar-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border-radius: 14px;
  background: #0b1220;
  border: 1px solid #ffffff10;
}
.stat-card strong { font-size: 1rem; color: #f8fafc; }
.stat-card span { font-size: .78rem; color: #94a3b8; }
.conversation-section { flex: 1; min-height: 0; }
.conversation-list { display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow: auto; }
.conversation-item {
  width: 100%;
  padding: 12px;
  text-align: left;
  cursor: pointer;
  color: #e5e7eb;
  background: #ffffff0a;
  border: 1px solid transparent;
  border-radius: 16px;
}
.conversation-item.active { background: #22c55e24; border-color: #22c55e59; }
.conversation-item-top, .conversation-item-middle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.conversation-item-top strong { font-size: .96rem; }
.conversation-item-top span, .conversation-subtitle, .conversation-item-preview {
  color: #94a3b8;
  font-size: .82rem;
}
.conversation-item-preview {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 8px;
  line-height: 1.4;
}
.badge, .tag, .chip, .setup-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .76rem;
}
.badge, .tag, .chip { color: #475569; background: #eef2f7; }
.setup-badge { margin-bottom: 10px; color: #166534; background: #dcfce7; }
.sidebar-footer { display: flex; flex-direction: column; gap: 8px; }
.ghost-button { color: #0f172a; background: #f3f4f6; }
.sidebar .ghost-button { color: #e5e7eb; background: #ffffff0f; }
.ghost-button:hover, .primary-button:hover, .nav-pill:hover, .conversation-item:hover { transform: translateY(-1px); }
.ghost-button.danger { color: var(--danger); }
.primary-button { color: #05130a; background: linear-gradient(135deg, var(--green), var(--green-deep)); font-weight: 700; }
.primary-button:disabled { opacity: .45; cursor: not-allowed; }
.main-layout { display: grid; grid-template-columns: minmax(460px, 1fr) 360px; min-height: 100vh; }
.chat-pane { display: flex; flex-direction: column; min-width: 0; }
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: #ffffffb8;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.chat-header-main { display: flex; flex-direction: column; gap: 8px; }
.chat-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.chat-header h2 { margin: 0; }
.chat-header p, .chat-header small, .helper-text { margin: 0; line-height: 1.45; color: var(--muted); }
.chat-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.status-banner {
  margin: 12px 24px 0;
  padding: 12px 14px;
  border: 1px solid #bbf7d0;
  border-radius: 14px;
  color: #166534;
  background: #ecfdf5;
}
.message-list { display: flex; flex: 1; flex-direction: column; gap: 16px; padding: 20px 24px; overflow: auto; }
.message-row { display: flex; align-items: flex-start; gap: 12px; }
.message-row.mine { justify-content: flex-end; }
.message-row.mine .bubble-wrap { align-items: flex-end; }
.message-row.event { justify-content: center; }
.bubble-wrap { display: flex; flex-direction: column; gap: 6px; max-width: min(72ch, 78%); }
.speaker-name, .message-time { font-size: .8rem; color: var(--muted); }
.bubble { white-space: pre-wrap; padding: 12px 14px; border-radius: 18px; line-height: 1.6; box-shadow: var(--shadow); }
.bubble-ai { background: var(--panel); }
.bubble-user { background: #dcfce7; }
.bubble-event {
  text-align: center;
  background: #eff6ff;
  border: 1px dashed #bfdbfe;
  box-shadow: none;
}
.typing-indicator { color: var(--muted); }
.composer {
  padding: 16px 24px 24px;
  border-top: 1px solid var(--border);
  background: #ffffffb8;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.composer textarea,
.form-card input,
.form-card textarea,
.form-card select,
.setup-grid input,
.setup-grid textarea,
.setup-grid select {
  width: 100%;
  padding: 12px 14px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  resize: vertical;
}
.composer textarea:focus,
.form-card input:focus,
.form-card textarea:focus,
.form-card select:focus,
.setup-grid input:focus,
.setup-grid textarea:focus,
.setup-grid select:focus {
  outline: 3px solid #22c55e24;
  border-color: #22c55e73;
}
.composer-actions, .button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}
.button-row.vertical { flex-direction: column; align-items: stretch; }
.button-row.end { justify-content: flex-end; }
.composer-actions span { font-size: .84rem; color: var(--muted); }
.inspector {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  overflow: auto;
  background: #f8fafc;
  border-left: 1px solid var(--border);
}
.panel, .form-card, .memory-card, .empty-card, .preview-card {
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
}
.panel h3, .panel h4, .form-card h4, .preview-card strong { margin: 0 0 8px; }
.panel p, .memory-card p, .preview-card p { margin: 0; line-height: 1.55; color: var(--muted); }
.meta-list { margin: 0; padding-left: 18px; line-height: 1.6; color: #334155; }
.chips, .memory-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.memory-grid { display: flex; flex-direction: column; gap: 12px; }
.memory-card.compact { padding: 12px 14px; }
.form-card { display: flex; flex-direction: column; gap: 12px; }
.form-card label, .setup-grid label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: #334155;
  font-weight: 600;
}
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.checkbox-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 10px !important;
  font-weight: 500 !important;
}
.checkbox-row input { width: auto; }
.setup-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #0f172a8c;
}
.setup-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: min(840px, 100%);
  padding: 24px;
  background: #fff;
  border-radius: 28px;
  box-shadow: 0 30px 80px #0f172a3d;
}
.setup-card h2 { margin: 0; }
.setup-card p { margin: 8px 0 0; color: var(--muted); }
.setup-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.setup-grid label:nth-child(4), .setup-grid label:nth-child(5) { grid-column: 1 / -1; }
.preview-card { background: #f8fafc; }

@media (width <= 1200px) {
  .main-layout { grid-template-columns: 1fr; }
  .inspector { border-top: 1px solid var(--border); border-left: 0; }
}

@media (width <= 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid #ffffff14; }
}

@media (width <= 720px) {
  .chat-header, .message-list, .composer, .inspector, .setup-card { padding-left: 16px; padding-right: 16px; }
  .setup-grid, .grid-2, .sidebar-stats { grid-template-columns: 1fr; }
  .bubble-wrap { max-width: 92%; }
  .section-heading { align-items: flex-start; flex-direction: column; }
}
