:root {
  --bg: #f0f4ff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-soft: #f1f5f9;
  --brand: #1d4ed8;
  --brand-600: #1e40af;
  --brand-100: #dbeafe;
  --ok: #16a34a;
  --err: #ef4444;
  --card: #ffffff;
  --shadow: 0 10px 30px rgba(17,24,39,.06);
  --tag-bg: #dbeafe;
  --tag-border: #93c5fd;
  --tag-text: #1e40af;
  --high: #fef2f2;
  --high-border: #fca5a5;
  --high-text: #b91c1c;
  --med: #fffbeb;
  --med-border: #fcd34d;
  --med-text: #92400e;
  --low: #f0fdf4;
  --low-border: #86efac;
  --low-text: #166534;
}

* { box-sizing: border-box }
html, body { height: 100% }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}

/* HEADER */
header {
  padding: 14px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 5;
  gap: 12px;
}
.header-left { display: flex; flex-direction: column; gap: 1px }
header h1 { margin: 0; font-size: 19px; font-weight: 700; color: var(--brand) }
.header-sub { font-size: 11px; color: var(--muted); font-weight: 500; letter-spacing: .02em }
.header-right { display: flex; align-items: center; gap: 10px }

.badge {
  font-size: 10px; padding: 4px 10px; border-radius: 999px;
  border: 1.5px solid var(--brand); background: var(--brand-100);
  color: var(--brand); font-weight: 600;
}

/* MODE TOGGLE */
.mode-toggle {
  display: flex; border: 1.5px solid var(--brand); border-radius: 8px; overflow: hidden;
}
.mode-btn {
  padding: 6px 14px; border: none; background: transparent;
  color: var(--brand); font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: background .15s, color .15s;
}
.mode-btn.active { background: var(--brand); color: #fff }
.mode-btn:not(.active):hover { background: var(--brand-100) }

/* WRAP / CARD */
.wrap { flex: 1; display: flex; justify-content: center; padding: 24px }
.chat {
  width: 100%; max-width: 940px; background: var(--card); border-radius: 16px;
  padding: 18px; border: 1px solid var(--line);
  display: grid; grid-template-rows: auto auto 1fr auto auto auto; gap: 12px;
  box-shadow: var(--shadow);
}

/* REVIEW PANEL */
.review-panel { display: flex; flex-direction: column; gap: 6px }
.review-label { font-size: 13px; font-weight: 600; color: var(--ink) }
.review-panel textarea {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--line);
  border-radius: 10px; font-size: 13px; font-family: inherit;
  color: var(--ink); resize: vertical; outline: none; line-height: 1.5;
}
.review-panel textarea:focus { border-color: #93c5fd; box-shadow: 0 0 0 3px rgba(59,130,246,.12) }

/* MESSAGES */
.messages {
  overflow-y: auto; padding: 4px 2px 12px;
  display: grid; gap: 10px; align-content: start;
  font-size: 15px; line-height: 1.55;
  background: #fff; border-radius: 12px;
}

/* MSG ROWS & AVATARS */
.msg-row { display: flex; align-items: flex-end; gap: 10px }
.msg-row.msg-me { justify-self: end; flex-direction: row-reverse }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--brand); color: #fff;
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; align-self: flex-start;
}

/* BUBBLES */
.bubble { word-wrap: break-word; overflow-wrap: break-word }
.bubble-greeting {
  background: var(--brand-100); border-radius: 14px; padding: 14px 18px;
  font-size: 15px; line-height: 1.6; border: 1px solid var(--line);
}
.bubble-greeting strong { color: var(--brand) }
.bubble-me {
  background: var(--brand); color: #fff;
  border-radius: 18px 18px 4px 18px; padding: 12px 16px;
  font-size: 15px; line-height: 1.6; max-width: 88%;
}
.bubble-bot {
  background: #fff; border: 1px solid var(--line);
  border-radius: 4px 18px 18px 18px; padding: 14px 16px;
  font-size: 15px; line-height: 1.6; flex: 1; min-width: 0;
  box-shadow: 0 1px 0 rgba(17,24,39,.03);
}
.bubble-bot p { margin-bottom: 10px }
.bubble-bot p:last-of-type { margin-bottom: 0 }
.bubble-bot ul { margin: 6px 0 10px 18px }
.bubble-bot li { margin: 4px 0 }
.bubble-bot strong { font-weight: 600 }

/* FINDINGS (review mode) */
.findings { display: flex; flex-direction: column; gap: 8px; margin-top: 10px }
.finding {
  border-radius: 8px; padding: 10px 14px; border: 1px solid;
  font-size: 13px; line-height: 1.5;
}
.finding.high { background: var(--high); border-color: var(--high-border) }
.finding.medium { background: var(--med); border-color: var(--med-border) }
.finding.low { background: var(--low); border-color: var(--low-border) }
.finding-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px }
.severity-badge {
  font-size: 10px; font-weight: 700; padding: 2px 7px;
  border-radius: 999px; text-transform: uppercase; letter-spacing: .04em;
}
.high .severity-badge { background: var(--high-border); color: var(--high-text) }
.medium .severity-badge { background: var(--med-border); color: var(--med-text) }
.low .severity-badge { background: var(--low-border); color: var(--low-text) }
.finding-issue { font-weight: 600; color: var(--ink) }
.finding-evidence { color: var(--muted); font-style: italic; margin: 3px 0 }
.finding-rec { color: var(--ink) }
.finding-basis { color: var(--brand); font-size: 12px; margin-top: 3px }

/* META ROW */
.meta-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin: 0 0 6px; font-size: 12px; color: var(--muted);
}
.meta-row > div:first-child { display: flex; flex-direction: column; align-items: flex-start; gap: 2px }
.meta-time { opacity: .9 }
.meta-count { color: var(--muted); font-size: 12px; opacity: .9 }
.meta-count strong { color: var(--ink); font-weight: 700 }
.meta-right { display: flex; align-items: center; gap: 6px }
.badge-mode {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: var(--brand-100); color: var(--brand); border: 1px solid var(--tag-border);
  font-size: 11px; font-weight: 700; letter-spacing: .02em;
}
.copy-btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 6px 10px; border-radius: 8px; font-size: 12px; cursor: pointer; font-family: inherit;
}
.copy-btn:hover { background: var(--brand-100); border-color: var(--tag-border) }

/* HINT */
.hint { font-size: 12px; color: var(--muted); padding: 0 2px }

/* SOURCES */
.sources {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.sources h3 { margin: 0 0 8px; font-size: 13px; font-weight: 700 }
.sources ul { margin: 0; padding-left: 18px }
.sources li { margin: 6px 0 }
.sources a { color: var(--brand); text-decoration: none }
.sources a:hover { text-decoration: underline }

/* FORM */
form {
  display: flex; gap: 10px; position: sticky; bottom: 0;
  background: #fff; padding-top: 2px;
}
input[type="text"] {
  flex: 1; padding: 12px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff;
  color: var(--ink); font-size: 15px; outline: none; font-family: inherit;
}
input[type="text"]:focus { border-color: #93c5fd; box-shadow: 0 0 0 3px rgba(59,130,246,.12) }
input::placeholder { color: #9aa1ac }
#send-btn {
  padding: 12px 18px; border-radius: 999px; border: 0;
  background: var(--brand); color: #fff; font-size: 14px; font-weight: 700;
  cursor: pointer; font-family: inherit;
  box-shadow: 0 2px 0 rgba(17,24,39,.06); transition: background .15s, transform .02s;
}
#send-btn:hover { background: var(--brand-600) }
#send-btn:active { transform: translateY(1px) }
#send-btn:disabled { opacity: .6; cursor: default }

/* LOADER */
.loader {
  display: inline-block; width: 1.05em; height: 1.05em;
  border: 2px solid var(--brand); border-top-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: -2px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* DISCLAIMER */
.disclaimer {
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--line-soft);
  font-size: 11px; line-height: 1.45; color: var(--muted);
}

@media (max-width: 520px) {
  .bubble-me, .bubble-bot { max-width: 96% }
  .wrap { padding: 14px }
  .mode-btn { padding: 5px 10px; font-size: 12px }
}
