:root {
  --ink: #14213d;
  --paper: #f7f8fa;
  --slate: #5c6b7a;
  --cobalt: #1f4fd8;
  --cobalt-deep: #173ea8;
  --mist: #e8eefc;
  --line: #d7dce3;
  --surface: #ffffff;
  --danger: #b42318;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eef2f8;
    --paper: #0f1728;
    --slate: #a3afbf;
    --cobalt: #7ea2ff;
    --cobalt-deep: #a9c0ff;
    --mist: #1c2a47;
    --line: #2b3a55;
    --surface: #17223a;
    --danger: #ff9a8f;
  }
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

a { color: var(--cobalt); }

:focus-visible {
  outline: 3px solid var(--cobalt);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 1.25rem;
  padding-top: calc(0.9rem + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 2;
}

.bar-name { font-weight: 800; letter-spacing: -0.01em; }

.tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--mist);
  color: var(--cobalt-deep);
}

.link-button {
  margin-left: auto;
  background: none;
  border: 0;
  padding: 0.25rem 0;
  font: inherit;
  font-size: 0.9rem;
  color: var(--slate);
  text-decoration: underline;
  cursor: pointer;
}

.wrap {
  width: 100%;
  max-width: 34rem;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 1.25rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.title {
  font-size: clamp(2rem, 8.5vw, 2.9rem);
  line-height: 1.04;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0.5rem 0 0.9rem;
}

.lede {
  margin: 0 0 1.6rem;
  color: var(--slate);
  max-width: 30rem;
}

.field { margin-bottom: 1rem; }

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

input, textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 0.6rem;
  padding: 0.8rem 0.9rem;
}

input::placeholder, textarea::placeholder { color: var(--slate); opacity: 0.8; }

input:focus, textarea:focus { border-color: var(--cobalt); outline: none; box-shadow: 0 0 0 3px var(--mist); }

.trap { position: absolute; left: -9999px; height: 0; overflow: hidden; }

.check {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  margin: 0.2rem 0 1rem;
}

.check input {
  width: 1.25rem;
  height: 1.25rem;
  margin: 0.15rem 0 0;
  padding: 0;
  flex: none;
  accent-color: var(--cobalt);
}

.check label {
  font-weight: 400;
  font-size: 0.9rem;
  color: var(--slate);
  margin: 0;
}

.primary {
  font: inherit;
  font-weight: 800;
  color: #ffffff;
  background: var(--cobalt);
  border: 0;
  border-radius: 0.6rem;
  padding: 0.9rem 1.2rem;
  cursor: pointer;
}

@media (prefers-color-scheme: dark) {
  .primary { color: #0f1728; }
}

.primary:hover { background: var(--cobalt-deep); }
.primary:disabled { opacity: 0.6; cursor: default; }

#start { width: 100%; margin-top: 0.4rem; }

.fine {
  font-size: 0.875rem;
  color: var(--slate);
  margin: 0.9rem 0 0;
}

.error {
  color: var(--danger);
  font-weight: 600;
  margin: 0 0 0.8rem;
}

#chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#chat[hidden], #intro[hidden] { display: none; }

.log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding-bottom: 1rem;
}

.msg {
  max-width: 88%;
  padding: 0.75rem 0.95rem;
  border-radius: 1rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--mist);
  border-bottom-left-radius: 0.3rem;
}

.msg.user {
  align-self: flex-end;
  background: var(--cobalt);
  color: #ffffff;
  border-bottom-right-radius: 0.3rem;
}

@media (prefers-color-scheme: dark) {
  .msg.user { color: #0f1728; }
}

.msg.waiting { color: var(--slate); font-style: italic; }

.checkout {
  display: inline-block;
  margin: 0.5rem 0 0.2rem;
  padding: 0.65rem 1rem;
  border-radius: 0.6rem;
  background: var(--cobalt);
  color: #ffffff;
  font-weight: 800;
  text-decoration: none;
}

@media (prefers-color-scheme: dark) {
  .checkout { color: #0f1728; }
}

.composer {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  position: sticky;
  bottom: 0;
  padding: 0.75rem 0 calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: var(--paper);
  border-top: 1px solid var(--line);
}

.composer textarea { resize: none; max-height: 9rem; }

/* Admin */
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.admin-table th, .admin-table td { text-align: left; padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin-table tr.flag td:first-child { border-left: 4px solid var(--danger); }
.admin-scroll { overflow-x: auto; }
.row-button { background: none; border: 0; padding: 0; font: inherit; color: var(--cobalt); text-decoration: underline; cursor: pointer; text-align: left; }
.section-title { font-size: 1.25rem; font-weight: 800; margin: 1.5rem 0 0.6rem; }

@media (prefers-reduced-motion: no-preference) {
  .msg { animation: rise 160ms ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
