/* Leiria Concierge, piloto interno.
   Hand-written, no framework. Tokens on :root; dark mode via prefers-color-scheme.
   Palette: castle-stone ground, warm near-black ink, one river-blue accent. */

/* The hidden attribute is only enforced by the UA stylesheet's [hidden]{display:none}, which
   ANY class rule setting display beats on specificity (0,1,0 vs 0,0,1). .thinking sets
   display:flex, so "a pensar..." was visible on every page load, before a question was ever
   asked, and stayed visible afterwards -- the indicator never indicated anything. Declared
   here once so the next element given `hidden` cannot inherit the same defect. */
[hidden] { display: none !important; }

:root {
  color-scheme: light dark;
  --ground: #f4efe6;
  --surface: #fffdf9;
  --surface-2: #ece4d4;
  --ink: #221c17;
  --ink-2: #635a50;
  --line: rgba(34, 28, 23, 0.14);
  --line-strong: rgba(34, 28, 23, 0.28);
  --accent: #1f6e8c;
  --accent-ink: #165268;
  --accent-soft: #dcebf1;
  --on-accent: #fbfdfe;
  --stone-rule: #c9b594;
  --danger: #9a3f2c;
  --danger-soft: #f5e3dd;
  --radius: 18px;
  --radius-s: 10px;
  --shadow: 0 1px 2px rgba(34, 28, 23, 0.05), 0 10px 28px -18px rgba(34, 28, 23, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --measure: 720px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #17140f;
    --surface: #221d17;
    --surface-2: #2d261d;
    --ink: #ede6da;
    --ink-2: #aa9f91;
    --line: rgba(237, 230, 218, 0.14);
    --line-strong: rgba(237, 230, 218, 0.3);
    --accent: #7cbdd8;
    --accent-ink: #a9d6e8;
    --accent-soft: #1e3540;
    --on-accent: #10222b;
    --stone-rule: #7a6a4e;
    --danger: #e08a72;
    --danger-soft: #3a221b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 28px -18px rgba(0, 0, 0, 0.7);
  }
}

/* ------------------------------------------------------------ base */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent-ink); }

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
}

button, input, textarea { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

/* ------------------------------------------------------------ header */

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 0 16px;
  background: var(--ground);
  border-top: 3px solid var(--accent);
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--ink);
  text-decoration: none;
  font-weight: 650;
  font-size: 15px;
  letter-spacing: 0.005em;
  white-space: nowrap;
}

.brand-sub { color: var(--ink-2); font-weight: 400; }

.top-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.inline { display: inline; margin: 0; }

.btn-ghost, .nav-link, .period a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn-ghost:hover, .nav-link:hover, .period a:hover { border-color: var(--accent); color: var(--accent-ink); }

.nav-link.is-active, .period a.is-active { background: var(--surface-2); border-color: var(--line-strong); }

/* ------------------------------------------------------------ chat */

.chat {
  flex: 1;
  width: 100%;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 16px 16px 8px;
}

.disclosure, .flash, .note {
  background: var(--surface-2);
  border-left: 3px solid var(--stone-rule);
  border-radius: var(--radius-s);
  padding: 11px 14px;
  font-size: 14px;
  margin: 0 0 16px;
}

.disclosure p, .flash p { margin: 0; }

.flash-error { border-left-color: var(--danger); background: var(--danger-soft); }

.thread {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 92%;
}

.msg-user { align-self: flex-end; align-items: flex-end; }
.msg-assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 11px 15px;
  border-radius: var(--radius);
  overflow-wrap: anywhere;
}

.msg-user .bubble {
  background: var(--accent);
  color: var(--on-accent);
  border-bottom-right-radius: 6px;
}

.msg-user .bubble a { color: inherit; }

.msg-assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
}

.bubble-error { border-left: 3px solid var(--danger); }

.bubble p { margin: 0 0 0.65em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0.25em 0 0.65em; padding-left: 1.3em; }
.bubble ul:last-child, .bubble ol:last-child { margin-bottom: 0; }
.bubble li { margin: 0.2em 0; }
.bubble a { text-decoration-thickness: 1px; text-underline-offset: 3px; }

.msg-note {
  font-size: 13px;
  color: var(--ink-2);
  margin: 0 0 6px 6px;
}

.sources {
  margin: 8px 0 0;
  padding: 0 6px;
  font-size: 13px;
  color: var(--ink-2);
}

.sources-label {
  display: block;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.sources ul { list-style: none; margin: 3px 0 0; padding: 0; }

.sources li { position: relative; padding-left: 14px; margin: 2px 0; }

.sources li::before {
  content: "";
  position: absolute;
  left: 2px; top: 0.6em;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--stone-rule);
}

.sources a {
  color: var(--accent-ink);
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
}

.feedback {
  margin: 8px 0 0;
  padding-left: 6px;
  font-size: 13px;
  color: var(--ink-2);
}

.fb { display: inline-flex; align-items: center; gap: 6px; margin: 0; flex-wrap: wrap; }

.fb-label { margin-right: 2px; }

.fb-btn, .fb-send {
  min-height: 34px;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
}

.fb-btn:hover, .fb-send:hover { border-color: var(--accent); color: var(--accent-ink); }

.fb-comment {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.fb-comment input {
  flex: 1;
  min-width: 200px;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 14px;
}

.thanks { display: inline-block; padding: 6px 0; }

.welcome { padding: 6px 2px 14px; }

.welcome h1 {
  font-size: 24px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.012em;
  margin: 6px 0 10px;
}

.welcome p { color: var(--ink-2); font-size: 15px; margin: 0 0 16px; max-width: 56ch; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }

.chip {
  min-height: 44px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.chip:hover { border-color: var(--accent); color: var(--accent-ink); }

.thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 6px 4px;
  color: var(--ink-2);
  font-size: 14px;
}

.dots { display: inline-flex; gap: 4px; }

.dots i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.35;
  animation: pulse 1.2s infinite ease-in-out;
}

.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

@media (prefers-reduced-motion: reduce) {
  .dots i { animation: none; opacity: 0.7; }
}

/* ------------------------------------------------------------ composer */

.composer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: var(--ground);
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
}

.ask {
  max-width: var(--measure);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.ask textarea {
  flex: 1;
  min-height: 48px;
  max-height: 160px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-size: 16px;
  line-height: 1.4;
  resize: none;
}

.ask textarea:focus, .gate-card input:focus, .fb-comment input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.send, .btn-primary {
  min-height: 48px;
  min-width: 84px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}

.send:hover, .btn-primary:hover { background: var(--accent-ink); }

.send:disabled { opacity: 0.55; cursor: progress; }

.hint {
  max-width: var(--measure);
  margin: 6px auto 0;
  font-size: 12px;
  color: var(--ink-2);
  text-align: center;
}

/* ------------------------------------------------------------ gate */

.gate {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.gate-card {
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.gate-card h1 { font-size: 20px; line-height: 1.3; margin: 0 0 4px; font-weight: 600; }

.gate-card label { font-size: 14px; color: var(--ink-2); }

.gate-card input[type="password"] {
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--ground);
  font-size: 16px;
}

.form-error { margin: 0; color: var(--danger); font-size: 14px; }

.gate-foot { margin: 8px 0 0; font-size: 13px; color: var(--ink-2); }

/* ------------------------------------------------------------ admin */

.admin {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 56px;
}

.admin-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.admin h1 { font-size: 22px; margin: 0; }
.admin h2 { font-size: 16px; margin: 28px 0 10px; }

.meta, .muted { color: var(--ink-2); font-size: 13px; }

.period { display: flex; gap: 6px; flex-wrap: wrap; }

.grid-2, .grid-3 {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin-top: 16px;
}

table { border-collapse: collapse; }

table.kv, table.list {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

table.kv caption {
  caption-side: top;
  text-align: left;
  padding: 8px 12px 6px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-2);
}

table.kv th {
  text-align: left;
  font-weight: 500;
  color: var(--ink-2);
  width: 52%;
}

table.kv th, table.kv td, table.list th, table.list td {
  padding: 7px 12px;
  border-top: 1px solid var(--line);
}

table.list thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-2);
  border-top: 0;
}

table.list tbody tr:hover { background: var(--surface-2); }

.num { text-align: right; }

.table-wrap { overflow-x: auto; }

.note h2 { margin-top: 0; }
.note p { margin: 0; }

.admin-thread { list-style: none; margin: 16px 0 0; padding: 0; }

.turn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 12px 16px;
  margin-bottom: 12px;
}

.turn-user { border-left: 3px solid var(--accent); }

.turn-head { font-size: 13px; margin-bottom: 4px; }
.role { font-weight: 650; }

.turn-body p { margin: 0 0 0.6em; }
.turn-body p:last-child { margin-bottom: 0; }

dl.trace {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
  margin: 12px 0 0;
  font-size: 13px;
}

dl.trace dt { color: var(--ink-2); font-weight: 500; }
dl.trace dd { margin: 0; overflow-wrap: anywhere; }

table.stages { font-size: 12px; }
table.stages th { text-align: left; font-weight: 500; padding: 2px 10px 2px 0; }
table.stages td { padding: 2px 10px 2px 0; }

/* ------------------------------------------------------------ breakpoints */

@media (min-width: 600px) {
  .chat { padding-top: 24px; }
  .bubble { padding: 13px 18px; }
  .msg { max-width: 84%; }
  .welcome h1 { font-size: 28px; }
}

@media (max-width: 380px) {
  .top { padding: 0 12px; }
  .brand-sub { display: none; }
  .chat { padding: 12px 10px 8px; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .send { min-width: 72px; padding: 0 12px; }
  .msg { max-width: 96%; }
}

@media print {
  .composer, .top-nav, .feedback { display: none; }
}
