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

:root {
  --orange: #E8500A;
  --orange-light: #f97316;
  --dark: #111827;
  --dark-2: #1f2937;
  --dark-3: #374151;
  --border: #2d3748;
  --text: #f9fafb;
  --text-dim: #9ca3af;
  --text-dimmer: #6b7280;
  --surface: #1a2234;
  --surface-2: #232d3f;
  --inv: #3b82f6;
  --bmu: #10b981;
  --gms: #f59e0b;
  --manta: #8b5cf6;
  --radius: 10px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--dark); color: var(--text); font-size: 14px; line-height: 1.6; }

.layout { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
.sidebar { width: 260px; min-width: 260px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto; }

.sidebar-header { padding: 20px 16px 16px; border-bottom: 1px solid var(--border); }
.logo { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.subtitle { font-size: 11px; color: var(--text-dimmer); padding-left: 38px; }

.sidebar-section { padding: 16px; border-bottom: 1px solid var(--border); }
.section-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dimmer); margin-bottom: 10px; }

/* Audience toggles */
.audience-toggles { display: flex; flex-direction: column; gap: 5px; }
.aud-toggle {
  display: flex; align-items: center; gap: 8px;
  background: var(--dark-3); border: 1px solid var(--border);
  color: var(--text-dimmer); padding: 8px 10px; border-radius: 6px;
  cursor: pointer; text-align: left; font-size: 13px; transition: all 0.15s;
}
.aud-toggle:hover { border-color: var(--text-dimmer); color: var(--text); }
.aud-toggle.active { background: var(--dark-2); border-color: var(--border); color: var(--text); }
.aud-toggle .aud-check { margin-left: auto; font-size: 11px; opacity: 0; color: var(--orange); }
.aud-toggle.active .aud-check { opacity: 1; }
.aud-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; opacity: 0.4; }
.aud-toggle.active .aud-dot { opacity: 1; }
.aud-hint { font-size: 11px; color: var(--text-dimmer); margin-top: 8px; line-height: 1.4; }

.device-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; letter-spacing: 0.05em; }
.tag.inv { background: rgba(59,130,246,0.15); color: var(--inv); border: 1px solid rgba(59,130,246,0.3); }
.tag.bmu { background: rgba(16,185,129,0.15); color: var(--bmu); border: 1px solid rgba(16,185,129,0.3); }
.tag.gms { background: rgba(245,158,11,0.15); color: var(--gms); border: 1px solid rgba(245,158,11,0.3); }
.tag.manta { background: rgba(139,92,246,0.15); color: var(--manta); border: 1px solid rgba(139,92,246,0.3); }

.examples { display: flex; flex-direction: column; gap: 5px; }
.example-btn { background: transparent; border: 1px solid var(--border); color: var(--text-dim); padding: 7px 10px; border-radius: 6px; cursor: pointer; text-align: left; font-size: 12px; transition: all 0.15s; }
.example-btn:hover { border-color: var(--orange); color: var(--text); background: rgba(232,80,10,0.05); }

.sidebar-nav { padding: 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.nav-link { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 6px; color: var(--text-dim); text-decoration: none; font-size: 13px; transition: all 0.15s; }
.nav-link:hover { background: var(--dark-2); color: var(--text); }
.nav-link.active { background: rgba(232,80,10,0.12); color: var(--orange); font-weight: 600; }
.nav-link svg { flex-shrink: 0; opacity: 0.7; }
.nav-link.active svg { opacity: 1; }

.sidebar-footer { margin-top: auto; padding: 16px; border-top: 1px solid var(--border); }
.kb-status { font-size: 11px; color: var(--text-dimmer); margin-bottom: 10px; }
.new-chat-btn { width: 100%; background: var(--dark-3); border: 1px solid var(--border); color: var(--text-dim); padding: 9px; border-radius: 6px; cursor: pointer; font-size: 13px; transition: all 0.15s; }
.new-chat-btn:hover { background: var(--dark-2); color: var(--text); }

/* ── Main chat ── */
.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.chat-header { padding: 16px 24px; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.chat-title { font-size: 16px; font-weight: 700; }
.chat-subtitle { font-size: 12px; color: var(--text-dimmer); margin-top: 2px; }

.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 20px; }
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.message { display: flex; gap: 12px; max-width: 820px; }
.message.user { flex-direction: row-reverse; margin-left: auto; }

.message-avatar { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.message.assistant .message-avatar { background: var(--orange); color: white; }
.message.user .message-avatar { background: var(--dark-3); color: var(--text-dim); }

.message-content { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; font-size: 14px; line-height: 1.65; flex: 1; }
.message.user .message-content { background: var(--dark-3); border-color: var(--dark-3); }

.message-content p { margin-bottom: 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin: 8px 0 8px 20px; }
.message-content li { margin-bottom: 4px; }
.message-content strong { color: var(--text); font-weight: 600; }
.message-content code { background: rgba(255,255,255,0.08); padding: 1px 6px; border-radius: 4px; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }
.message-content h1, .message-content h2, .message-content h3 { margin: 12px 0 6px; }
.message-content h2 { font-size: 14px; color: var(--orange-light); border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.message-content h3 { font-size: 13px; color: var(--text-dim); }

/* Severity badges in messages */
.severity-critical { color: #ef4444; font-weight: 700; }
.severity-high { color: #f97316; font-weight: 700; }
.severity-medium { color: #eab308; font-weight: 600; }
.severity-low { color: #22c55e; font-weight: 600; }

/* Typing indicator */
.typing .message-content { display: flex; align-items: center; gap: 4px; padding: 14px 18px; }
.dot { width: 7px; height: 7px; background: var(--text-dimmer); border-radius: 50%; animation: bounce 1.2s infinite; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* ── Input area ── */
.input-area { padding: 16px 24px 20px; border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.input-wrapper { display: flex; gap: 10px; align-items: flex-end; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; transition: border-color 0.15s; }
.input-wrapper:focus-within { border-color: var(--orange); }

#userInput { flex: 1; background: transparent; border: none; color: var(--text); font-size: 14px; line-height: 1.5; resize: none; outline: none; max-height: 160px; font-family: inherit; }
#userInput::placeholder { color: var(--text-dimmer); }

.send-btn { background: var(--orange); border: none; color: white; width: 34px; height: 34px; border-radius: 7px; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all 0.15s; }
.send-btn:hover:not(:disabled) { background: var(--orange-light); }
.send-btn:disabled { background: var(--dark-3); color: var(--text-dimmer); cursor: not-allowed; }

.tool-btn { background: transparent; border: none; color: var(--text-dimmer); width: 34px; height: 34px; border-radius: 7px; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all 0.15s; }
.tool-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.tool-btn.recording { color: #ef4444; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* Image preview bar */
.image-preview-bar { display: flex; gap: 8px; padding: 8px 0 4px; flex-wrap: wrap; }
.img-preview-wrap { position: relative; }
.img-preview-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.img-preview-remove { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%; background: #ef4444; border: none; color: white; font-size: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center; line-height: 1; }

/* Images in messages */
.message-images { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.message-image { max-width: 240px; max-height: 180px; border-radius: 6px; border: 1px solid var(--border); object-fit: cover; cursor: pointer; }
.message-image:hover { opacity: 0.9; }

.input-hint { font-size: 11px; color: var(--text-dimmer); margin-top: 6px; }

/* Feedback bar */
.feedback-bar { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.feedback-label { font-size: 12px; color: var(--text-dimmer); }
.feedback-btn { background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; cursor: pointer; font-size: 14px; transition: all 0.15s; }
.feedback-btn:hover { border-color: var(--orange); background: rgba(232,80,10,0.08); }
.feedback-thanks { font-size: 12px; color: var(--bmu); }

/* ── Three-column layout ── */
.columns-area {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  overflow: hidden;
  min-height: 0;
}

.audience-col {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
  min-height: 0;
}
.audience-col:last-child { border-right: none; }
.audience-col.hidden { display: none; }

.col-label {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  white-space: nowrap;
}
.col-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.dot-homeowner { background: #4ade80; }
.dot-installer { background: #60a5fa; }
.dot-support   { background: #c084fc; }

.col-hint {
  color: var(--text-dimmer);
  font-weight: 400;
  font-size: 11px;
  margin-left: 2px;
}

.col-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}
.col-messages::-webkit-scrollbar { width: 3px; }
.col-messages::-webkit-scrollbar-track { background: transparent; }
.col-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.col-empty {
  color: var(--text-dimmer);
  font-size: 12px;
  text-align: center;
  padding: 40px 16px;
  line-height: 1.6;
}

.col-turn {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.col-question {
  background: var(--dark-3);
  border-radius: 7px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  gap: 6px;
  align-items: flex-start;
}
.col-question-images { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.col-question-img { width: 48px; height: 48px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); }

.col-answer {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.65;
}
.col-answer p { margin-bottom: 7px; }
.col-answer p:last-child { margin-bottom: 0; }
.col-answer ul, .col-answer ol { margin: 7px 0 7px 18px; }
.col-answer li { margin-bottom: 3px; }
.col-answer strong { color: var(--text); font-weight: 600; }
.col-answer h2 { font-size: 13px; color: var(--orange-light); border-bottom: 1px solid var(--border); padding-bottom: 3px; margin: 10px 0 5px; }
.col-answer h3 { font-size: 12px; color: var(--text-dim); margin: 8px 0 4px; }
.col-answer code { background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 3px; font-family: monospace; font-size: 11px; }

.col-typing {
  display: flex; align-items: center; gap: 4px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
}

/* Responsive */
@media (max-width: 900px) {
  .columns-area { grid-template-columns: 1fr; }
  .audience-col { border-right: none; border-bottom: 1px solid var(--border); max-height: 40vh; }
}
@media (max-width: 700px) {
  .sidebar { display: none; }
}
