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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  color: #1a1a1a;
  background: #f5f5f4;
  min-height: 100vh;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: #1a1a2e;
  color: #fff;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.02em; }
.btn-link { background: none; border: none; color: #ccc; cursor: pointer; font-size: 0.9rem; }
.btn-link:hover { color: #fff; }

.main { max-width: 900px; margin: 2rem auto; padding: 0 1.5rem; }

h1 { font-size: 1.6rem; margin-bottom: 1rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 0.75rem; }

.auth-box {
  max-width: 400px;
  margin: 4rem auto;
  background: #fff;
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
.auth-box h1 { margin-bottom: 1.5rem; }
.auth-box label { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 1rem; font-size: 0.9rem; color: #555; }
.auth-box input { padding: 0.5rem 0.75rem; border: 1px solid #ddd; border-radius: 6px; font-size: 1rem; }
.auth-box input:focus { outline: 2px solid #4f46e5; border-color: transparent; }

.btn-primary {
  display: inline-block;
  padding: 0.5rem 1.25rem;
  background: #4f46e5;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary:hover { background: #4338ca; }
.btn-sm {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: #e5e7eb;
  color: #1a1a1a;
  border: none;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
}
.btn-sm:hover { background: #d1d5db; }

.error { color: #dc2626; margin-bottom: 1rem; font-size: 0.9rem; }
.empty { color: #999; font-style: italic; }

.status-badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.status-draft            { background: #e5e7eb; color: #6b7280; }
.status-ready            { background: #d1fae5; color: #065f46; }
.status-processing       { background: #dbeafe; color: #1e40af; }
.status-error            { background: #fee2e2; color: #991b1b; }
.status-pending          { background: #e5e7eb; color: #6b7280; }

.cat-badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 4px; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.cat-authoritative { background: #fee2e2; color: #991b1b; }
.cat-advisory      { background: #fef3c7; color: #92400e; }
.cat-form          { background: #dbeafe; color: #1e40af; }
.cat-sample        { background: #e5e7eb; color: #6b7280; }
.status-intake_pending   { background: #fef3c7; color: #92400e; }
.status-intake_complete  { background: #dbeafe; color: #1e40af; }
.status-compliance_screening { background: #ede9fe; color: #5b21b6; }
.status-auto_approved    { background: #d1fae5; color: #065f46; }
.status-pending_drc_review { background: #fef3c7; color: #92400e; }
.status-pending_vote     { background: #fed7aa; color: #9a3412; }
.status-approved         { background: #d1fae5; color: #065f46; }
.status-approved_with_conditions { background: #d1fae5; color: #065f46; }
.status-denied           { background: #fee2e2; color: #991b1b; }

.result-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}
.assessment--approved .result-badge  { background: #d1fae5; color: #065f46; }
.assessment--edge_case .result-badge { background: #fef3c7; color: #92400e; }
.assessment--denied .result-badge    { background: #fee2e2; color: #991b1b; }

.vote-badge { font-weight: 600; }
.vote-approve { color: #065f46; }
.vote-approve_with_conditions { color: #1e40af; }
.vote-deny { color: #991b1b; }

.submission-list { list-style: none; }
.submission-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid #e5e7eb;
}
.submission-list li a { flex: 1; text-decoration: none; color: #4f46e5; }
.submission-list li a:hover { text-decoration: underline; }
.date { font-size: 0.8rem; color: #9ca3af; }

table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; }
th { background: #f9fafb; text-align: left; padding: 0.6rem 1rem; font-size: 0.85rem; color: #6b7280; font-weight: 600; }
td { padding: 0.7rem 1rem; border-top: 1px solid #f3f4f6; font-size: 0.9rem; }
tr:hover td { background: #f9fafb; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }

/* ── Two-column chat layout ─────────────────────────────────────────────── */

/* When chat-layout is used, expand the .main wrapper to full width */
.main:has(.chat-layout) {
  max-width: 100%;
  padding: 0;
  margin: 0;
}

.chat-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 1.5rem;
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  align-items: start;
}

@media (max-width: 700px) {
  .chat-layout { grid-template-columns: 1fr; }
  .chat-sidebar { order: -1; }
}

.chat-main { display: flex; flex-direction: column; min-width: 0; }

.chat-sidebar {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  position: sticky;
  top: 1rem;
}
.chat-sidebar h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: #9ca3af; margin-bottom: 0.75rem; }

/* Status tracker */
.status-tracker { list-style: none; padding: 0; margin: 0; }
.tracker-step {
  padding: 0.35rem 0.5rem 0.35rem 1.5rem;
  font-size: 0.875rem;
  color: #9ca3af;
  position: relative;
  border-left: 2px solid #e5e7eb;
}
.tracker-step::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e5e7eb;
}
.tracker-done {
  color: #6b7280;
  border-left-color: #10b981;
}
.tracker-done::before { background: #10b981; }
.tracker-current {
  color: #1a1a1a;
  font-weight: 600;
  border-left-color: #4f46e5;
}
.tracker-current::before { background: #4f46e5; box-shadow: 0 0 0 3px #ede9fe; }

/* Sidebar assessment cards */
.sidebar-assessment {
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
  border-left: 3px solid #e5e7eb;
}
.sidebar-assessment--approved  { border-left-color: #10b981; }
.sidebar-assessment--edge_case { border-left-color: #f59e0b; }
.sidebar-assessment--denied    { border-left-color: #ef4444; }
.sidebar-track { font-size: 0.8rem; font-weight: 600; color: #374151; margin-bottom: 0.2rem; }
.sidebar-result { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.result-approved  { color: #065f46; }
.result-edge_case { color: #92400e; }
.result-denied    { color: #991b1b; }
.sidebar-conf { font-size: 0.75rem; color: #9ca3af; margin-top: 0.15rem; }

/* ── Chat header, window, messages ──────────────────────────────────────── */

.chat-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.chat-header .back-link { color: #4f46e5; text-decoration: none; font-size: 0.9rem; }
.chat-header .back-link:hover { text-decoration: underline; }

.chat-window {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1rem;
  min-height: 200px;
  max-height: 520px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.chat-welcome { color: #6b7280; padding: 1rem 0; }
.chat-welcome p { margin-bottom: 0.5rem; }
.chat-welcome-examples { font-size: 0.85rem; color: #9ca3af; font-style: italic; }

.chat-msg { margin-bottom: 1rem; }
.chat-bubble { max-width: 90%; }
.chat-msg--homeowner .chat-bubble { margin-left: auto; text-align: right; }
.chat-sender {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9ca3af;
  display: block;
  margin-bottom: 0.2rem;
}
.chat-msg--agent   .chat-sender { color: #4f46e5; }
.chat-msg--homeowner .chat-sender { color: #059669; }

.chat-content { line-height: 1.65; }
.chat-content code { background: #f3f4f6; padding: 0.1em 0.35em; border-radius: 3px; font-size: 0.88em; }
.chat-content .render-list { padding-left: 1.25rem; margin: 0.4rem 0; }
.chat-content .render-list li { margin-bottom: 0.2rem; }
.chat-content .render-heading { display: block; margin: 0.5rem 0 0.25rem; }
.chat-thinking { color: #9ca3af; font-style: italic; }
.chat-error { color: #dc2626; }

.chat-form { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.chat-form textarea {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  resize: vertical;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.5;
}
.chat-form textarea:focus { outline: 2px solid #4f46e5; border-color: transparent; }

.chat-hint { font-size: 0.78rem; color: #9ca3af; margin-bottom: 1rem; }
.chat-hint kbd {
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 3px;
  padding: 0.05em 0.4em;
  font-size: 0.85em;
}

.chat-closed {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  color: #6b7280;
  margin-top: 0.5rem;
}

.assessments { margin-top: 1.5rem; }
.assessment { background: #fff; border-radius: 8px; padding: 1rem; margin-bottom: 0.75rem; border-left: 4px solid #e5e7eb; }
.assessment--approved  { border-left-color: #10b981; }
.assessment--edge_case { border-left-color: #f59e0b; }
.assessment--denied    { border-left-color: #ef4444; }
.assessment .confidence { font-size: 0.8rem; color: #9ca3af; margin-left: 0.5rem; }
.citations { margin-top: 0.5rem; padding-left: 1.5rem; font-size: 0.85rem; color: #4b5563; }
.alternatives { margin-top: 0.75rem; font-size: 0.85rem; }

.vote-form label { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 1rem; }
.vote-form select, .vote-form textarea, .vote-form input[type=text] {
  padding: 0.4rem 0.6rem; border: 1px solid #ddd; border-radius: 6px; font-size: 0.9rem;
}

.decision-box {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.inline-form input, .inline-form select { padding: 0.4rem 0.6rem; border: 1px solid #ddd; border-radius: 6px; font-size: 0.9rem; }

.settings-form { max-width: 400px; }
.settings-form label { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 1rem; font-size: 0.9rem; }
.settings-form input[type=number] { width: 100px; padding: 0.4rem 0.6rem; border: 1px solid #ddd; border-radius: 6px; }
.settings-form input[type=checkbox] { width: auto; margin-right: 0.5rem; }

section { margin-bottom: 2.5rem; }

.overdue { color: #dc2626; font-weight: 700; }

.upload-form label { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.5rem; }
.upload-form input[type=file] { padding: 0.5rem 0; }

.doc-meta { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.token-count { font-size: 0.85rem; color: #6b7280; }

.processing-notice {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.processing-notice p { margin-bottom: 0.75rem; color: #1e40af; }
progress { width: 100%; }

.error-box {
  background: #fff1f2;
  border: 1px solid #fecdd3;
  border-radius: 8px;
  padding: 1.5rem;
}
.error-box pre { font-size: 0.8rem; white-space: pre-wrap; margin-top: 0.75rem; color: #991b1b; }

.rules-summary {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1.25rem;
  white-space: pre-wrap;
  font-size: 0.9rem;
  line-height: 1.7;
  max-height: 500px;
  overflow-y: auto;
}

.restrictions-list { padding-left: 1.5rem; }
.restrictions-list li { padding: 0.3rem 0; font-size: 0.9rem; line-height: 1.5; }

.section-table th:first-child { width: 60px; }
.section-table th:nth-child(2) { width: 220px; }

.text-preview {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 1rem;
  font-size: 0.8rem;
  white-space: pre-wrap;
  overflow-x: auto;
  max-height: 300px;
  overflow-y: auto;
}
