:root {
  --navy: #152B50;
  --teal: #4AC6D6;
  --teal-dark: #2CA6B6;
  --aqua: #B4DCDE;
  --blush: #E0BAA9;
  --rose: #C79688;
  --cream: #F0E8E0;
  --paper: #FBF6F2;
  --ink: #2F3231;
  --muted: #6E6A68;
  --line: rgba(21, 43, 80, 0.12);
  --danger: #A6413A;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { background: #F3E2DA; }
body {
  font-family: 'Roboto', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: linear-gradient(160deg, #F7EDE6 0%, #F3E2DA 45%, #EFE6E4 100%);
  background-attachment: fixed;
}
h1, h2, h3, .brand { font-family: 'Arima', Georgia, serif; color: var(--navy); font-weight: 700; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--teal-dark); }

/* ---------- chat ---------- */
.chat-shell { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; padding: 0 16px; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0 10px; }
.chat-head .brand { font-size: 1.5rem; margin: 0; }
.brand .ai { color: var(--teal); }
a.ghost { text-decoration: none; display: inline-block; }
.chat-head .brand small { display: block; font-family: 'Roboto', sans-serif; font-weight: 400; font-size: 0.8rem; color: var(--muted); }
.head-actions { display: flex; gap: 8px; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; cursor: pointer; color: var(--navy); }
.ghost:hover { border-color: var(--teal); }

.disclaimer { font-size: 0.82rem; color: var(--muted); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 8px 0; }

.log { flex: 1; overflow-y: auto; padding: 18px 0; display: flex; flex-direction: column; gap: 18px; scroll-behavior: smooth; }
.msg { max-width: 88%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: rgba(74, 198, 214, 0.16); padding: 10px 14px; border-radius: 18px 18px 4px 18px; }
.msg.assistant { align-self: flex-start; }
.msg.assistant .who { font-family: 'Arima', serif; color: var(--rose); font-size: 0.85rem; margin-bottom: 2px; }
.msg .src { margin-top: 6px; font-size: 0.78rem; color: var(--muted); }
.msg.note { align-self: center; font-size: 0.85rem; color: var(--muted); text-align: center; }
.msg.error { align-self: center; color: var(--danger); font-size: 0.9rem; text-align: center; }
.thinking { color: var(--muted); font-style: italic; }
.thinking::after { content: ''; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

.crisis { align-self: stretch; border-left: 3px solid var(--danger); padding: 8px 14px; background: rgba(166, 65, 58, 0.06); }
.crisis strong { color: var(--danger); }
.crisis ul { margin: 6px 0 0; padding-left: 18px; }

.welcome { margin: auto 0; text-align: center; color: var(--muted); padding: 24px 8px; }
.welcome h2 { font-size: 1.7rem; margin: 0 0 8px; }
.starters { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 16px; }

.composer { padding: 10px 0 16px; }
.attached { font-size: 0.82rem; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--line); border-radius: 22px; padding: 6px 6px 6px 14px; background: rgba(255, 255, 255, 0.55); }
.row:focus-within { border-color: var(--teal); }
.row textarea { flex: 1; border: 0; outline: 0; background: transparent; resize: none; max-height: 160px; padding: 8px 0; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 8px; border-radius: 50%; color: var(--navy); line-height: 0; }
.icon-btn:hover { background: rgba(21, 43, 80, 0.06); }
.send { background: var(--navy); color: #fff; border: 0; border-radius: 999px; padding: 9px 18px; cursor: pointer; }
.send:disabled { opacity: 0.45; cursor: default; }
.foot { text-align: center; font-size: 0.78rem; color: var(--muted); margin-top: 8px; }

.drawer { position: fixed; inset: 0; background: rgba(21, 43, 80, 0.25); display: none; }
.drawer.open { display: block; }
.drawer .panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(340px, 90vw); background: var(--paper); padding: 20px 16px; overflow-y: auto; }
.drawer h3 { margin: 0 0 12px; }
.conv-item { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.conv-item button { background: none; border: 0; cursor: pointer; text-align: left; padding: 0; color: var(--navy); }
.conv-item .del { color: var(--muted); }

/* ---------- admin ---------- */
.admin { max-width: 1040px; margin: 0 auto; padding: 20px 16px 60px; }
.admin header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; padding: 10px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--navy); border-bottom-color: var(--teal); }
.admin section { display: none; }
.admin section.active { display: block; }
.admin label { display: block; font-size: 0.85rem; color: var(--muted); margin: 10px 0 4px; }
.admin input[type=text], .admin input[type=password], .admin select, .admin textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: rgba(255,255,255,0.7);
}
.admin textarea { min-height: 280px; font-size: 0.92rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
.primary { background: var(--navy); color: #fff; border: 0; border-radius: 999px; padding: 9px 18px; cursor: pointer; margin-top: 14px; }
.small { font-size: 0.82rem; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.pill { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 0.78rem; background: var(--cream); }
.pill.approved { background: rgba(74,198,214,0.25); }
.pill.failed, .pill.crisis { background: rgba(166,65,58,0.15); color: var(--danger); }
.pill.concern { background: rgba(199,150,136,0.3); }
.linkish { background: none; border: 0; color: var(--teal-dark); cursor: pointer; padding: 0 4px; text-decoration: underline; }
.kpis { display: flex; gap: 32px; flex-wrap: wrap; margin: 8px 0 20px; }
.kpis div strong { display: block; font-family: 'Arima', serif; font-size: 1.8rem; color: var(--navy); }
.transcript { border-left: 2px solid var(--line); padding-left: 14px; margin-top: 12px; }
.transcript p { white-space: pre-wrap; }
.login { max-width: 360px; margin: 12vh auto; }
.err { color: var(--danger); font-size: 0.9rem; min-height: 1.2em; }
