:root {
  --bg: #ffffff;
  --text: #1a1d21;
  --muted: #5d6670;
  --line: #e3e6ea;
  --soft: #f4f6f8;
  --accent: #0f766e;
  --accent-dark: #0b5952;
  --accent-soft: #e6f4f2;
  --danger: #b42318;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
button { font: inherit; cursor: pointer; }
a { color: var(--accent); }

/* ---------- Start screen ---------- */
.start {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  padding: 32px 20px calc(32px + env(safe-area-inset-bottom));
}
.start-inner { width: 100%; max-width: 520px; margin: 0 auto; }
.eyebrow {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
}
.start h1 {
  margin: 0 0 16px;
  font-size: 36px;
  line-height: 1.15;
  letter-spacing: -0.02em;
}
.lede { margin: 0 0 32px; font-size: 20px; color: var(--muted); }
#start-form label { display: block; font-weight: 600; margin-bottom: 8px; }
#start-form input {
  width: 100%;
  font: inherit;
  font-size: 18px;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  margin-bottom: 20px;
}
#start-form input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.btn-primary {
  width: 100%;
  min-height: 56px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.form-error { color: var(--danger); margin: 16px 0 0; }

/* ---------- Chat screen ---------- */
.chat {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
}
.chat-header {
  flex: none;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.link-row { display: flex; align-items: center; gap: 10px; }
.share-link {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}
.btn-small {
  flex: none;
  min-height: 40px;
  padding: 0 14px;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
}
.btn-small:hover { background: var(--accent-soft); }
.link-note {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
  font-size: 14px;
  color: var(--muted);
}
.start-over { color: var(--muted); padding: 4px 0; }

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg { max-width: 92%; }
.msg-user { align-self: flex-end; }
.msg-assistant { align-self: flex-start; }
.bubble {
  padding: 12px 16px;
  border-radius: 18px;
  overflow-wrap: anywhere;
}
.msg-user .bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
}
.msg-assistant .bubble {
  background: var(--soft);
  border-bottom-left-radius: 6px;
}
.bubble p { margin: 0 0 10px; }
.bubble p:last-child, .bubble ul:last-child, .bubble ol:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  margin: 14px 0 6px;
  line-height: 1.25;
}
.bubble h1 { font-size: 24px; }
.bubble h2 { font-size: 21px; }
.bubble h3, .bubble h4 { font-size: 19px; }
.bubble > :first-child { margin-top: 0; }
.bubble ul, .bubble ol { margin: 0 0 10px; padding-left: 22px; }
.bubble hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

.msg-actions { margin-top: 8px; }
.btn-copy-page {
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
}
.btn-copy-page:hover { background: var(--accent-dark); }

.typing { display: inline-flex; gap: 6px; padding: 16px 18px; }
.typing span {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted);
  opacity: 0.35;
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 0.9; } }

.notice {
  align-self: center;
  max-width: 92%;
  text-align: center;
  font-size: 16px;
  color: var(--danger);
  background: #fdf0ef;
  border-radius: 12px;
  padding: 10px 14px;
}

.btn-retry {
  display: block;
  margin: 10px auto 0;
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.composer {
  flex: none;
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  font: inherit;
  font-size: 18px;
  line-height: 1.4;
  padding: 12px 16px;
  min-height: 52px;
  max-height: 40dvh;
  border: 1.5px solid var(--line);
  border-radius: 26px;
  background: #fff;
  color: var(--text);
}
.btn-send {
  flex: none;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
}
.btn-send:disabled { opacity: 0.4; cursor: default; }
.char-count { font-size: 14px; color: var(--muted); text-align: right; margin: 4px 8px 0; }
.char-count.over { color: var(--danger); }
.limit-note {
  font-size: 16px;
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 16px;
  z-index: 10;
}

@media (min-width: 700px) {
  .start h1 { font-size: 48px; }
  .messages { padding: 28px 24px 16px; }
  .msg { max-width: 80%; }
}

/* ---------- Admin ---------- */
.admin { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; font-size: 16px; }
.admin h1 { font-size: 24px; margin: 0; }
.admin-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  min-height: 40px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-dark); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.login { max-width: 380px; margin: 12vh auto 0; }
.login h1 { margin-bottom: 20px; }
.login input, .filters input, .filters select {
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
.login input { width: 100%; margin-bottom: 12px; }
.login .btn-primary { font-size: 18px; min-height: 48px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 20px; }
.panel h2 { font-size: 16px; margin: 0 0 10px; }
.source-list { display: flex; flex-wrap: wrap; gap: 10px; }
.source-chip { background: var(--soft); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.source-chip strong { font-size: 15px; }
.source-chip .status { color: var(--muted); }
.source-chip.bad .status { color: var(--danger); }
.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input { flex: 1; min-width: 200px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--soft); font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--accent-soft); }
tbody tr:last-child td { border-bottom: 0; }
.yes { color: var(--accent); font-weight: 600; }
.flag { color: var(--danger); font-weight: 600; }
.muted { color: var(--muted); }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.detail-meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 12px 0 20px; }
.detail-meta dt { color: var(--muted); }
.detail-meta dd { margin: 0; overflow-wrap: anywhere; }
.detail-grid { display: grid; gap: 20px; }
@media (min-width: 960px) { .detail-grid { grid-template-columns: 1fr 1fr; align-items: start; } }
.final-page { white-space: pre-wrap; background: var(--soft); border-radius: var(--radius); padding: 16px; overflow-wrap: anywhere; }
.transcript .msg { max-width: 100%; margin-bottom: 10px; }
.transcript .bubble { white-space: pre-wrap; font-size: 15px; }
.transcript .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.confirm-row { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
