:root {
  /* Premium Color Palette */
  --bg-color: #F6F8F6; /* Zeer lichte, warme groentint */
  --surface-color: #FFFFFF;
  --surface-alt: #FAFAFA;
  
  --primary-color: #4A6C5B; /* Premium Saliegroen / Bosgroen */
  --primary-hover: #375344;
  --primary-light: #E9EFEB;
  
  --text-main: #242A27;
  --text-muted: #6B7280;
  
  --border-color: #E2E8F0;
  --border-glass: rgba(226, 232, 240, 0.6);
  
  --danger-color: #EF4444;
  --danger-bg: #FEF2F2;
  --danger-hover: #DC2626;

  --user-bubble-bg: #F0F4F2;
  --assistant-bubble-bg: #FFFFFF;

  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-blur: blur(24px);
  
  /* Shadows for depth */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
  --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.05);
  --shadow-composer: 0 12px 40px -8px rgba(74, 108, 91, 0.15);

  --sidebar-width: 320px;
  --header-height: 76px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden; /* App layout, scrolling inside containers */
}

/* Elegant Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(107, 114, 128, 0.2);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(107, 114, 128, 0.4);
}

h1, h2, h3, h4 {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 700;
  color: var(--text-main);
}

@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes glassGlow {
  0% { box-shadow: 0 0 0 0 rgba(74, 108, 91, 0.0); }
  50% { box-shadow: 0 0 20px 0 rgba(74, 108, 91, 0.1); }
  100% { box-shadow: 0 0 0 0 rgba(74, 108, 91, 0.0); }
}

/* =========================================
   Layout Grid
========================================= */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
  position: relative;
}

/* =========================================
   Sidebar
========================================= */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 40;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-glass);
}

/* Ensure the sidebar NEVER disappears completely (e.g. when app.js adds .hidden) */
.sidebar.hidden {
  display: none !important;
}

.sidebar-header {
  padding: 12px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  border-bottom: 1px solid var(--border-glass);
}

.brand {
  display: flex;
  align-items: center;
  width: 100%;
}

.sidebar-close-button {
  display: none;
  flex: 0 0 auto;
}

.brand-logo-container {
  width: 100%;
  display: block;
}

.brand-logo-image {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
}

.brand-logo-image-sidebar-desktop {
  width: 100%;
  height: auto;
  max-width: 100%;
}

.brand-logo-image-sidebar-mobile {
  display: none;
  width: 48px;
  height: 60px;
  max-width: none;
  object-fit: contain;
}

body, .app-layout, .main-content {
  height: 100vh; /* Fallback */
  height: 100dvh; /* Dynamic Viewport Height: dit is de fix! */
}

@media (max-width: 768px) {
  .sidebar-header {
    padding: 12px;
  }

  .brand-logo-image-sidebar-desktop {
    display: none;
  }

  .brand-logo-image-sidebar-mobile {
    display: block;
  }
}

.sidebar-actions {
  padding: 20px 24px;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 24px 16px;
}

.sidebar-nav-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}

.sidebar-nav-link {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--text-main);
  background: transparent;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar-nav-link:hover {
  background-color: var(--surface-alt);
  color: var(--primary-color);
}

.sidebar-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 12px;
  padding-left: 8px;
}

/* Sidebar List */
.conversation-list-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.conversation-row {
  position: relative;
  display: block;
}

.conversation-item {
  width: 100%;
  background: rgba(233, 239, 235, 0.78);
  border: 1px solid rgba(74, 108, 91, 0.1);
  text-align: left;
  padding: 12px 96px 12px 14px;
  border-radius: 14px;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.42);
}

.conversation-item:hover {
  background-color: rgba(226, 236, 229, 0.94);
  border-color: rgba(74, 108, 91, 0.16);
  transform: translateY(-1px);
}

.conversation-item.active {
  background-color: var(--primary-light);
  border-color: rgba(74, 108, 91, 0.2);
}

.conversation-row-actions {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  z-index: 1;
}

.conversation-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 4px;
}

.conversation-item-preview {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

.conversation-edit-button {
  background: rgba(74, 108, 91, 0.08);
  border: 1px solid rgba(74, 108, 91, 0.16);
  color: var(--primary-color);
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  cursor: pointer;
  opacity: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.conversation-edit-button:hover {
  background: rgba(74, 108, 91, 0.14);
}

.conversation-delete-button {
  background: rgba(239, 68, 68, 0.06);
  border: 1px solid rgba(239, 68, 68, 0.14);
  color: #b42318;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.conversation-delete-button:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.24);
  transform: translateY(-1px);
}

/* =========================================
   Main Area & Header
========================================= */
.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  /* Premium organic background with subtle pattern */
  background: 
    radial-gradient(circle at top right, rgba(74, 108, 91, 0.03) 0%, transparent 60%),
    radial-gradient(circle at bottom left, rgba(74, 108, 91, 0.04) 0%, transparent 50%),
    var(--bg-color);
  background-image: radial-gradient(var(--border-color) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: 0 0;
}

.topbar {
  height: var(--header-height);
  padding: 0 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border-bottom: 1px solid var(--border-glass);
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-title-wrap {
  display: flex;
  flex-direction: column;
}

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-family: 'Roboto', sans-serif;
}

.topbar-title-wrap h1 {
  font-size: 18px;
  margin: 0;
  line-height: 1.2;
}

.topbar-title-mobile {
  display: none;
  margin: 2px 0 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-main);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-pill {
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
  background-color: var(--primary-light);
  color: var(--primary-color);
  box-shadow: inset 0 0 0 1px rgba(74, 108, 91, 0.1);
}

.status-pill.error {
  background-color: var(--danger-bg);
  color: var(--danger-hover);
  box-shadow: inset 0 0 0 1px rgba(220, 38, 38, 0.2);
}

/* =========================================
   Chat Area (Messages & Outcome)
========================================= */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  scroll-behavior: smooth;
}

.phase-strip {
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--border-glass);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.intake-card {
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  padding: 22px 24px 24px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--border-glass);
  border-radius: 22px;
  box-shadow: var(--shadow-md);
}

.intake-card-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}

.intake-card-header h2 {
  font-size: 24px;
  line-height: 1.2;
}

.intake-card-intro {
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.6;
  max-width: 58ch;
}

.intake-form {
  display: grid;
  gap: 16px;
}

.intake-fieldset {
  border: 1px solid rgba(74, 108, 91, 0.14);
  border-radius: 16px;
  padding: 16px 16px 14px;
  background: linear-gradient(180deg, rgba(249, 251, 249, 0.98) 0%, rgba(242, 246, 243, 0.98) 100%);
}

.intake-fieldset legend {
  padding: 0 8px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--text-main);
}

.intake-fieldset label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  font-size: 14px;
  color: var(--text-main);
}

.intake-fieldset label + label {
  margin-top: 4px;
}

.intake-fieldset input[type="radio"] {
  accent-color: var(--primary-color);
}

.intake-card-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.intake-step-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary-color);
  background: rgba(74, 108, 91, 0.1);
  border: 1px solid rgba(74, 108, 91, 0.2);
  border-radius: 20px;
  padding: 3px 10px;
  white-space: nowrap;
  flex-shrink: 0;
}

.intake-fieldset {
  transition: opacity 0.15s ease;
}

.intake-step-hint {
  font-size: 13px;
  color: var(--primary-color);
  text-align: center;
  padding: 4px 0 2px;
  opacity: 0.8;
}

.intake-summary {
  border: 1px solid rgba(74, 108, 91, 0.14);
  border-radius: 16px;
  padding: 18px 18px 14px;
  background: linear-gradient(180deg, rgba(249, 251, 249, 0.98) 0%, rgba(242, 246, 243, 0.98) 100%);
}

.intake-summary-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

.intake-summary-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.intake-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 14px;
}

.intake-summary-row dt {
  color: var(--text-muted);
  font-weight: 500;
  flex-shrink: 0;
}

.intake-summary-row dd {
  color: var(--text-main);
  font-weight: 600;
  text-align: right;
  margin: 0;
}

.intake-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 8px;
  gap: 8px;
}

.intake-actions-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.intake-back-btn {
  font-size: 13px;
  padding: 6px 12px;
}

/* ── Delete confirmation inline ───────────────────────────────────── */
.conversation-delete-confirm {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.conversation-delete-confirm span {
  color: var(--text-main);
  font-weight: 500;
}

.delete-confirm-yes {
  font-size: 12px;
  font-weight: 600;
  color: #c0392b;
  background: none;
  border: 1px solid rgba(192, 57, 43, 0.3);
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
  line-height: 1.6;
}

.delete-confirm-yes:hover {
  background: rgba(192, 57, 43, 0.08);
}

.delete-confirm-no {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border-glass);
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
  line-height: 1.6;
}

.delete-confirm-no:hover {
  background: rgba(0,0,0,0.04);
}

.phase-strip-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.phase-strip-label,
.phase-strip-current {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.phase-steps {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.phase-step {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.phase-step.active {
  background: rgba(74, 108, 91, 0.12);
  border-color: rgba(74, 108, 91, 0.22);
  color: var(--primary-color);
}

.phase-step.done {
  background: rgba(74, 108, 91, 0.08);
  color: var(--text-main);
}

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.message-row {
  display: flex;
  width: 100%;
}

.phase-marker-row {
  display: flex;
  justify-content: center;
  width: 100%;
  margin: -6px 0 4px;
}

.phase-marker {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(74, 108, 91, 0.1);
  border: 1px solid rgba(74, 108, 91, 0.16);
  color: var(--primary-color);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.message-row.user {
  justify-content: flex-end;
}

.message-bubble {
  max-width: 85%;
  padding: 16px 20px;
  border-radius: 20px;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s;
  animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.message-bubble:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.message-row.user .message-bubble {
  background-color: var(--user-bubble-bg);
  border-bottom-right-radius: 6px;
}

.message-row.assistant .message-bubble {
  background-color: var(--assistant-bubble-bg);
  border: 1px solid var(--border-glass);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-md);
}

.message-row.assistant .message-bubble.semantic-confirmation-bubble {
  background: linear-gradient(180deg, #eef4f0 0%, #e8f0eb 100%);
  border: 1px solid rgba(74, 108, 91, 0.22);
  box-shadow: var(--shadow-md);
}

.semantic-confirmation-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.semantic-confirmation-text {
  font-size: 15px;
  line-height: 1.6;
  font-weight: 500;
}

.semantic-confirmation-help {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
}

.semantic-confirmation-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* Outcome Card embedded inside messages (from app.js) */
.message-row.assistant .message-bubble.outcome-bubble {
  width: 100%;
  max-width: 100% !important;
  background: linear-gradient(180deg, #f8f4ee 0%, #f4eee5 100%) !important;
  border: 1px solid #ddd2c3 !important;
  box-shadow: var(--shadow-md) !important;
}

.outcome-bubble-toggle {
  width: 100%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
}

.outcome-bubble-title {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 20px;
  color: var(--text-main);
  margin-top: 4px;
}

.outcome-bubble-chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(128, 99, 60, 0.12);
  color: #6f593c;
  border-radius: 50%;
  font-size: 18px;
}

.outcome-bubble-body {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(111, 89, 60, 0.14);
}

.outcome-section {
  margin-bottom: 16px;
}

.outcome-section:last-child {
  margin-bottom: 0;
}

.outcome-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.outcome-section-text, .outcome-section-list {
  font-size: 14px;
  line-height: 1.6;
}

.outcome-section-list {
  padding-left: 20px;
}

/* Global Outcome Card */
.outcome-card {
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  background-color: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: 24px;
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-composer);
  margin-bottom: 24px;
  overflow: hidden;
  animation: slideUpFade 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.outcome-toggle {
  width: 100%;
  background: transparent;
  border: none;
  padding: 20px 24px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  transition: background-color 0.3s;
}

.outcome-toggle:hover {
  background-color: rgba(255, 255, 255, 0.5);
}

.outcome-header h2 {
  margin: 0;
  margin-top: 4px;
  font-size: 20px;
  color: var(--primary-color);
}

.outcome-chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--primary-light);
  color: var(--primary-color);
  border-radius: 50%;
  font-size: 20px;
  font-weight: 300;
  transition: transform 0.3s;
}

.outcome-body {
  padding: 0 24px 24px 24px;
}

.outcome-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-top: 20px;
  margin-bottom: 8px;
}

.outcome-profile {
  font-size: 14px;
  line-height: 1.6;
}

.outcome-steps, .outcome-unclear, .outcome-directions, .outcome-signals {
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.6;
}

.outcome-directions li,
.outcome-signals li,
.outcome-steps li,
.outcome-unclear li {
  margin-bottom: 8px;
}

.outcome-directions li strong {
  display: inline;
  color: var(--primary-color);
}

.outcome-directions li::marker {
  color: var(--primary-color);
}

.outcome-signals li::marker {
  color: rgba(74, 108, 91, 0.72);
}

.outcome-toolbar {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid rgba(74, 108, 91, 0.12);
  display: flex;
  justify-content: flex-end;
}

.outcome-export-button {
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid rgba(74, 108, 91, 0.18);
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff 0%, #f6faf7 100%);
  color: var(--primary-color);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
  box-shadow: 0 8px 18px -14px rgba(74, 108, 91, 0.45);
}

.outcome-export-button:hover {
  transform: translateY(-1px);
  background: #ffffff;
  box-shadow: 0 12px 24px -16px rgba(74, 108, 91, 0.45);
}

.outcome-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.outcome-action {
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.outcome-action.primary {
  background-color: var(--primary-color);
  color: white;
  box-shadow: 0 4px 10px rgba(74, 108, 91, 0.2);
}

.outcome-action.primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.outcome-action.secondary {
  background-color: var(--surface-color);
  color: var(--text-main);
  box-shadow: inset 0 0 0 1px var(--border-color);
}

.outcome-action.secondary:hover {
  background-color: var(--surface-alt);
}

.outcome-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* =========================================
   Composer / Input
========================================= */
.composer-wrapper {
  padding: 0 32px 32px;
  background: linear-gradient(to top, rgba(246, 248, 246, 0.95) 40%, rgba(246, 248, 246, 0));
  z-index: 10;
}

.composer {
  max-width: 800px;
  margin: 0 auto;
  position: relative;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: 24px;
  box-shadow: var(--shadow-composer);
  border: 1px solid var(--border-glass);
  display: flex;
  align-items: flex-end;
  padding: 10px 12px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.composer.disabled {
  opacity: 0.72;
  box-shadow: var(--shadow-sm);
}

.composer.disabled:focus-within {
  transform: none;
  border-color: var(--border-glass);
  box-shadow: var(--shadow-sm);
  background: var(--glass-bg);
}

.composer-textarea-wrap {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
}

.composer:focus-within {
  box-shadow: 0 0 0 2px rgba(74, 108, 91, 0.3), var(--shadow-composer);
  border-color: var(--primary-color);
  transform: translateY(-2px);
  background: var(--surface-color);
}

#composer-input {
  background: transparent;
  border: none;
  resize: none;
  padding: 12px 16px 6px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-main);
  max-height: 180px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}

/* Character counter */
.char-counter {
  font-size: 11px;
  text-align: right;
  padding: 0 16px 6px;
  color: var(--text-muted);
  line-height: 1;
  transition: color 0.2s;
  user-select: none;
}

.char-counter.warn {
  color: #b45309;
}

.char-counter.error {
  color: #b91c1c;
  font-weight: 600;
}

#composer-input::placeholder {
  color: #9CA3AF;
}

.btn-send {
  background-color: var(--primary-color);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 4px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-send:hover {
  background-color: var(--primary-hover);
  transform: scale(1.05);
}

.btn-send:disabled {
  background-color: var(--border-color);
  color: #9CA3AF;
  transform: none;
  cursor: not-allowed;
}

/* =========================================
   Buttons & Utilities
========================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 9999px;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  font-family: inherit;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  background-color: var(--primary-light);
  color: var(--primary-color);
}

.btn-icon.danger:hover {
  background-color: var(--danger-bg);
  color: var(--danger-hover);
}

.hidden {
  display: none !important;
}

.hidden-desktop {
  display: none !important;
}

/* =========================================
   Mobile Overlays & Responsive
========================================= */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(36, 42, 39, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* =========================================
   Documentation Page
========================================= */
.docs-body {
  overflow: auto;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(74, 108, 91, 0.06) 0%, transparent 55%),
    radial-gradient(circle at bottom left, rgba(74, 108, 91, 0.05) 0%, transparent 45%),
    var(--bg-color);
}

.docs-page {
  max-width: 980px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

.docs-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.docs-hero-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.docs-logo {
  width: 48px;
  height: 60px;
  object-fit: contain;
  flex-shrink: 0;
}

.docs-title {
  font-size: 34px;
  line-height: 1.1;
  margin-top: 4px;
}

.docs-version {
  display: inline-flex;
  align-items: center;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(74, 108, 91, 0.1);
  border: 1px solid rgba(74, 108, 91, 0.18);
  color: var(--primary-color);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.docs-intro {
  max-width: 760px;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1.7;
  margin-bottom: 28px;
}

.docs-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.docs-card {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--border-glass);
  border-radius: 22px;
  padding: 24px;
  box-shadow: var(--shadow-md);
}

.docs-card-full {
  grid-column: 1 / -1;
}

.docs-card h2 {
  font-size: 20px;
  margin-bottom: 14px;
}

.docs-card p {
  color: var(--text-main);
  line-height: 1.7;
}

.docs-card ul,
.docs-card ol {
  padding-left: 20px;
  color: var(--text-main);
  line-height: 1.7;
}

.docs-card li + li {
  margin-top: 8px;
}

.docs-note {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(74, 108, 91, 0.08);
  color: var(--text-main);
}

.docs-card strong {
  font-weight: 700;
}

.docs-disclaimer {
  background: linear-gradient(180deg, #f8f4ee 0%, #f4eee5 100%);
  border-color: #ddd2c3;
}

.docs-actions {
  margin-top: 28px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.docs-link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
  border: 1px solid rgba(74, 108, 91, 0.16);
}

.docs-link-button.primary {
  background: var(--primary-color);
  color: #fff;
}

.docs-link-button.secondary {
  background: #fff;
  color: var(--primary-color);
}

/* Hide Hamburger by default on desktop */
#toggle-conversations-button {
  display: none;
}

body.narrow-layout #toggle-conversations-button {
  display: flex;
}

body.narrow-layout .hidden-desktop {
  display: block !important;
}

body.narrow-layout .sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 100vw;
  max-width: 100vw;
  transform: translateX(-100%);
  border-right: none;
  background-color: rgba(255, 255, 255, 0.98);
  z-index: 60;
}

body.narrow-layout .sidebar.hidden {
  display: none !important;
  transform: translateX(-100%);
}

body.narrow-layout .sidebar.active-mobile {
  display: flex !important;
  transform: translateX(0);
}

body.narrow-layout .sidebar.active-mobile .sidebar-header {
  justify-content: space-between;
}

body.narrow-layout .sidebar.active-mobile .sidebar-close-button {
  display: inline-flex;
}

body.narrow-layout .main-content {
  position: relative;
  width: 100%;
}

body.narrow-layout.conversation-list-open .main-content {
  display: none !important;
}

body.narrow-layout .conversation-row {
  display: block;
}

body.narrow-layout .conversation-row-actions {
  right: 8px;
}

/* Mobile Layout */
@media (max-width: 1100px) {
  #toggle-conversations-button {
    display: flex;
  }
  
  .hidden-desktop {
    display: block !important;
  }
  
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    width: 100vw;
    max-width: 100vw;
    border-right: none;
    background-color: rgba(255, 255, 255, 0.98);
    z-index: 60;
  }
  
  .sidebar.active-mobile {
    transform: translateX(0);
  }

  .sidebar.active-mobile .sidebar-header {
    justify-content: space-between;
  }

  .sidebar.active-mobile .sidebar-close-button {
    display: inline-flex;
  }

  .sidebar.active-mobile + .main-content {
    visibility: hidden;
    pointer-events: none;
  }
  
  .topbar {
    padding: 0 16px;
    height: 64px;
  }
  
  /* Make the logo container in the sidebar hidden on mobile *if* we want it only in topbar.
     Or let's just make sure topbar has a mobile logo */
  .mobile-brand-logo-container {
    display: block;
    width: 34px;
    height: 42px;
    margin-right: 4px;
    flex: 0 0 auto;
  }

  .mobile-brand-logo-image {
    display: block;
    width: 100%;
    height: 100%;
  }
  
  .messages-container {
    padding: 20px 16px;
    gap: 16px;
  }

  .phase-strip {
    padding: 12px 14px;
  }

  .phase-strip-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .phase-step {
    font-size: 12px;
    padding: 7px 10px;
  }

  .conversation-row {
    display: block;
  }

  .conversation-row-actions {
    right: 8px;
  }
  
  .composer-wrapper {
    padding: 0 16px 20px;
    background: linear-gradient(to top, rgba(246, 248, 246, 0.98) 50%, rgba(246, 248, 246, 0));
  }
  
  .composer {
    box-shadow: 0 8px 30px -5px rgba(74, 108, 91, 0.2);
  }

  .topbar-title-wrap h1 {
    display: none;
  }

  .topbar-title-mobile {
    display: block;
  }

  .topbar-left {
    gap: 10px;
    min-width: 0;
  }

  .topbar-title-wrap {
    min-width: 0;
  }

  .topbar-title-mobile,
  .eyebrow {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-right {
    gap: 8px;
  }

  .docs-hero {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .docs-title {
    font-size: 28px;
  }
  
  .message-bubble {
    max-width: 94%;
    padding: 14px 18px;
    font-size: 14px;
  }

  .outcome-toolbar {
    justify-content: stretch;
  }

  .outcome-export-button {
    width: 100%;
  }
  
  .status-pill {
    padding: 4px 8px;
    font-size: 11px;
  }

  .phase-strip {
    border-radius: 16px;
  }

  .intake-card {
    padding: 18px 16px 20px;
    border-radius: 18px;
  }

  .intake-card-header h2 {
    font-size: 20px;
  }

  .intake-fieldset {
    padding: 14px 14px 12px;
  }

  .phase-marker {
    font-size: 11px;
    padding: 6px 10px;
  }
}

@media (min-width: 1101px) {
  .sidebar {
    position: relative;
    transform: none;
    display: flex !important;
  }

  .sidebar.hidden {
    display: flex !important;
  }

  .sidebar-overlay {
    display: none !important;
  }
}

/* =========================================
   Streaming / Loading bubble
========================================= */
@keyframes loadingPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

.message-bubble.loading-bubble {
  font-style: italic;
  color: var(--text-muted);
  animation: loadingPulse 1.4s ease-in-out infinite;
}

.message-bubble.loading-bubble:hover {
  transform: none;
}

/* =========================================
   Inline rename input (conversation sidebar)
========================================= */
.conversation-inline-edit {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  padding: 4px 6px;
}

.conversation-inline-input {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  background: var(--surface-color);
  border: 1.5px solid var(--primary-color);
  border-radius: 8px;
  padding: 6px 10px;
  outline: none;
  min-width: 0;
}

.conversation-inline-confirm,
.conversation-inline-cancel {
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  padding: 0;
  color: var(--primary-color);
}

.conversation-inline-confirm:hover {
  background: var(--primary-light);
}
.conversation-inline-cancel:hover {
  background: rgba(200, 50, 50, 0.08);
  color: #c83232;
}

/* =========================================
   Interim understanding card
========================================= */
.interim-card {
  margin: 0 24px 12px;
  border-radius: 16px;
  background: linear-gradient(180deg, #eef4f0 0%, #e8efeb 100%);
  border: 1px solid rgba(74, 108, 91, 0.2);
  overflow: hidden;
  animation: slideUpFade 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.interim-card.hidden {
  display: none;
}

.interim-toggle {
  width: 100%;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 14px 18px;
  text-align: left;
}

.interim-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.interim-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary-color);
  margin: 2px 0 0;
}

.interim-chevron {
  font-size: 20px;
  font-weight: 300;
  color: var(--primary-color);
  line-height: 1;
  flex-shrink: 0;
}

.interim-body {
  padding: 0 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.interim-body.hidden {
  display: none;
}

.interim-picture {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-main);
  margin: 0;
}

.interim-clusters,
.interim-directions {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.interim-clusters li,
.interim-directions li {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-main);
  padding: 5px 10px;
  background: rgba(74, 108, 91, 0.07);
  border-radius: 8px;
}

/* =========================================
   Custom title-prompt overlay (replaces window.prompt)
========================================= */
.title-prompt-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36, 42, 39, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  animation: fadeIn 0.15s ease-out;
}

.title-prompt-overlay.hidden {
  display: none;
}

.title-prompt-dialog {
  background: var(--surface-color);
  border-radius: 20px;
  padding: 28px 28px 24px;
  width: min(420px, calc(100vw - 32px));
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slideUpFade 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.title-prompt-dialog label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.title-prompt-input {
  width: 100%;
  font-size: 15px;
  color: var(--text-main);
  background: var(--surface-alt);
  border: 1.5px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 14px;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.2s;
}

.title-prompt-input:focus {
  border-color: var(--primary-color);
}

.title-prompt-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.title-prompt-cancel {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 8px 18px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.title-prompt-cancel:hover {
  background: var(--surface-alt);
}

.title-prompt-confirm {
  background: var(--primary-color);
  border: none;
  color: #fff;
  padding: 8px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.title-prompt-confirm:hover {
  background: var(--primary-hover);
}

.title-prompt-confirm:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
