:root {
  --plum: #6B516E;
  --mauve: #AE8AA6;
  --mid: #846F86;
  --soft: #9D8B9F;
  --pale: #B6A9B8;
  --ice: #DBEDF0;
  --bg: #F1EDEF;
  --text: #575757;
  --white: #ffffff;
  --line: #e2dbe0;
  --danger: #9a3b3b;
  --serif: "DM Serif Display", Georgia, serif;
  --sans: "Raleway", Calibri, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 16px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--serif); color: var(--plum); font-weight: 400; margin: 0 0 .5em; line-height: 1.2; }
a { color: var(--plum); }
button { font-family: var(--sans); font-size: 15px; cursor: pointer; }
.btn {
  border: 0; border-radius: 999px; padding: 11px 22px; background: var(--plum); color: var(--white);
  font-weight: 600; letter-spacing: .01em; transition: background .15s;
}
.btn:hover { background: #5a425d; }
.btn:disabled { background: var(--pale); cursor: default; }
.btn.ghost { background: transparent; color: var(--plum); border: 1px solid var(--pale); }
.btn.ghost:hover { background: var(--white); }
.btn.small { padding: 6px 14px; font-size: 13px; }
input, select, textarea {
  font-family: var(--sans); font-size: 16px; color: var(--text);
  border: 1px solid var(--pale); border-radius: 10px; padding: 11px 14px; background: var(--white); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--mauve); outline-offset: 1px; border-color: var(--mauve); }
.muted { color: var(--mid); font-size: 14px; }
.hidden { display: none !important; }

/* ---------- centred card pages (sign in, notice) ---------- */
.centre { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card {
  background: var(--white); border-radius: 18px; padding: 40px 36px; width: 100%; max-width: 460px;
  box-shadow: 0 1px 2px rgba(107,81,110,.06), 0 12px 40px rgba(107,81,110,.08);
}
.card.wide { max-width: 620px; }
.brand-mark { font-family: var(--serif); color: var(--plum); font-size: 34px; margin-bottom: 4px; }
.brand-mark span { color: var(--mauve); }
.card form { display: grid; gap: 14px; margin-top: 22px; }
.notice-box { background: var(--ice); border-radius: 12px; padding: 14px 18px; margin: 18px 0 0; font-size: 15px; }
.notice-box.warm { background: var(--bg); }
.consent-list { padding-left: 1.2em; margin: 14px 0 22px; }
.consent-list li { margin-bottom: 10px; }

/* ---------- chat layout ---------- */
.shell { display: grid; grid-template-columns: 290px 1fr; height: 100vh; height: 100dvh; }
.sidebar {
  background: var(--white); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0;
}
.side-head { padding: 22px 20px 14px; }
.side-head .brand-mark { font-size: 26px; }
.side-head .btn { width: 100%; margin-top: 12px; }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 10px; min-height: 0; }
.conv-list .label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--soft); padding: 10px 10px 4px; }
.conv-item {
  display: block; width: 100%; text-align: left; border: 0; background: transparent; color: var(--text);
  padding: 9px 12px; border-radius: 10px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--bg); color: var(--plum); font-weight: 600; }
.side-foot { border-top: 1px solid var(--line); padding: 14px 20px; font-size: 14px; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.side-foot .who { width: 100%; color: var(--mid); overflow: hidden; text-overflow: ellipsis; }
.linkish { background: none; border: 0; padding: 0; color: var(--plum); text-decoration: underline; font-size: 14px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: none; }
.thread { flex: 1; overflow-y: auto; padding: 32px 24px 12px; min-height: 0; }
.thread-inner { max-width: 760px; margin: 0 auto; }
.welcome { text-align: center; padding: 12vh 12px 0; }
.welcome h1 { font-size: 40px; }
.welcome p { max-width: 460px; margin: 0 auto; }
.msg { margin: 0 0 22px; display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 85%; padding: 14px 18px; border-radius: 18px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--plum); color: var(--white); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--white); border-bottom-left-radius: 6px; box-shadow: 0 1px 2px rgba(107,81,110,.06); }
.bubble p { margin: 0 0 .8em; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 .8em; padding-left: 1.3em; }
.bubble strong { color: var(--plum); }
.msg.error .bubble { background: #fbefef; color: var(--danger); }
.thinking { display: inline-flex; gap: 10px; align-items: center; color: var(--mid); font-size: 14px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--mauve); animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer { padding: 10px 24px 14px; }
.composer-inner { max-width: 760px; margin: 0 auto; }
.compose-box {
  display: flex; gap: 10px; align-items: flex-end; background: var(--white); border: 1px solid var(--pale);
  border-radius: 18px; padding: 8px 8px 8px 16px;
}
.compose-box:focus-within { border-color: var(--mauve); }
.compose-box textarea { border: 0; padding: 8px 0; resize: none; max-height: 220px; outline: none; background: transparent; }
.compose-box .btn { padding: 10px 18px; }
.small-print { text-align: center; font-size: 12.5px; color: var(--mid); margin-top: 8px; }

/* ---------- admin ---------- */
.admin { max-width: 1100px; margin: 0 auto; padding: 32px 16px 60px; }
.admin-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin: 20px 0 28px; }
.tile { background: var(--white); border-radius: 14px; padding: 16px 18px; }
.tile .k { font-size: 13px; color: var(--mid); }
.tile .v { font-family: var(--serif); font-size: 30px; color: var(--plum); }
.panel { background: var(--white); border-radius: 14px; padding: 20px; margin-bottom: 24px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; background: var(--plum); color: var(--white); font-weight: 600; padding: 9px 10px; white-space: nowrap; }
th:first-child { border-top-left-radius: 8px; } th:last-child { border-top-right-radius: 8px; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:nth-child(even) td { background: var(--bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.over { color: var(--danger); font-weight: 700; }
td select { width: auto; min-width: 128px; padding: 7px 10px; font-size: 14px; }
.pill { display: inline-block; font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--ice); }
.pill.private { background: #efe6ee; }
.add-form { display: grid; grid-template-columns: 1.2fr 1.6fr 1fr auto; gap: 10px; align-items: end; }
.add-form label { font-size: 13px; color: var(--mid); display: grid; gap: 4px; }
.transcript .msg .bubble { max-width: 92%; }
.back { margin-bottom: 14px; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 84%; max-width: 320px; z-index: 20; transform: translateX(-102%); transition: transform .2s; visibility: hidden; }
  .sidebar.open { transform: none; visibility: visible; box-shadow: 0 0 40px rgba(0,0,0,.15); }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--white); border-bottom: 1px solid var(--line); }
  .topbar .brand-mark { font-size: 22px; margin: 0; }
  .thread { padding: 20px 16px 8px; }
  .composer { padding: 8px 12px 12px; }
  .bubble { max-width: 92%; }
  .welcome h1 { font-size: 32px; }
  .card { padding: 30px 22px; }
  .add-form { grid-template-columns: 1fr; }
}
