:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1c1b19;
  --muted: #6b6760;
  --line: #e5e2db;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --mine: #4f46e5;
  --mine-text: #ffffff;
  --theirs: #ffffff;
  --error: #b91c1c;
  --ok: #15803d;
  --radius: 18px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15141a;
    --surface: #1f1e26;
    --text: #f1efe9;
    --muted: #a19d95;
    --line: #2f2d38;
    --accent: #818cf8;
    --accent-text: #0f0e14;
    --mine: #6366f1;
    --mine-text: #ffffff;
    --theirs: #262530;
    --error: #f87171;
    --ok: #4ade80;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }

.btn {
  border: 0; border-radius: 999px; padding: 10px 18px; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}
.btn:disabled { opacity: .5; cursor: default; }
.btn--quiet { background: transparent; color: var(--muted); padding: 8px 12px; }
.btn--small { padding: 6px 12px; font-size: 14px; }
.btn--line { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn--danger { background: transparent; color: var(--error); border: 1px solid var(--line); }

/* ---- Welcome and PIN ---- */
.center { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 32px 24px; text-align: center; }
.card h1 { font-size: 24px; margin: 8px 0 4px; }
.card p { margin: 0 0 20px; }
.logo { width: 56px; height: 56px; margin: 0 auto; border-radius: 18px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: 28px; font-weight: 700; }
.pin {
  width: 100%; text-align: center; font-size: 28px; letter-spacing: .4em; padding: 12px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--bg);
}
.card form .btn { width: 100%; margin-top: 16px; padding: 12px; }

/* ---- Chat ---- */
.chat { height: 100%; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }
.chat__head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--bg); }
.chat__head .logo { width: 36px; height: 36px; font-size: 18px; border-radius: 12px; margin: 0; flex: none; }
.chat__title { flex: 1; min-width: 0; }
.chat__title strong { display: block; }
.chat__title span { font-size: 13px; color: var(--muted); }
.chat__log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 82%; padding: 10px 14px; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble--user { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 6px; }
.bubble--assistant { align-self: flex-start; background: var(--theirs); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble--typing { color: var(--muted); }
.bubble--error { align-self: center; background: transparent; color: var(--error); font-size: 14px; }
.chat__hello { margin: auto 0; text-align: center; color: var(--muted); padding: 24px 8px; }
.chat__hello strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.suggestion { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-size: 14px; }
.chat__form { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.chat__input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 10px 16px; }

/* ---- Admin ---- */
.admin { max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; }
.admin__head { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.admin__head h1 { flex: 1; margin: 0; font-size: 24px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 20px; margin-bottom: 16px; }
.panel h2 { margin: 0 0 4px; font-size: 18px; }
.panel > p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.row:first-of-type { border-top: 0; }
.row__main { flex: 1; min-width: 180px; }
.row__main strong { display: block; }
.row__main span { font-size: 14px; color: var(--muted); }
.tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.tag--ok { color: var(--ok); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.form-grid input[type="text"], .form-grid select { border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; color: var(--text); }
.form-grid .check { flex-direction: row; align-items: center; gap: 8px; grid-column: 1 / -1; color: var(--text); }
.form-actions { display: flex; justify-content: flex-end; margin-top: 16px; }
.link-box { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--bg); border: 1px dashed var(--line); font-size: 14px; overflow-wrap: anywhere; }
.link-box code { display: block; margin: 6px 0 10px; color: var(--text); }
@media (max-width: 520px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
}
.pin + .pin { margin-top: 10px; }
a.btn { text-decoration: none; display: inline-block; }
.row select { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 10px; font-size: 14px; }
.panel h2.muted { margin-top: 20px; font-size: 15px; }
.notice { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; padding: 12px 16px; font-size: 14px; margin: 0 0 16px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.chat__attach { cursor: pointer; flex: none; padding-left: 12px; padding-right: 12px; }
.chat__attach:focus-within { outline: 2px solid var(--accent, currentColor); outline-offset: 2px; }
.attached { display: flex; gap: 8px; padding: 8px 16px 0; background: var(--bg); }
.attached__item { position: relative; }
.attached__item img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
.attached__remove { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1; cursor: pointer; }
.bubble__picture { display: block; max-width: 100%; max-height: 240px; border-radius: 10px; margin-bottom: 6px; }
