/* Haja: tokens and layout from docs/DESIGN.md. Checked by tests/layout.e2e.mjs. */
:root {
  --bg: #0d0c0a; --surface: #161411; --raised: #211e1a; --line: #2c2823;
  --ink: #f5f0e6; --muted: #a69e91; --accent: #f5b73b; --on-accent: #1b1405;
  --on-accent-muted: #5a4310; --agent: #8fb8ff; --danger: #ff8a7a;
  --r-control: 12px; --r-bubble: 20px; --gutter: 16px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f4ee; --surface: #ffffff; --raised: #efe9df; --line: #e3dccf;
    --ink: #1a1712; --muted: #6b6457; --agent: #2e5aac; --danger: #b3261e;
    color-scheme: light;
  }
}

/* The bug in the first screenshot: CSS display beat the hidden attribute. Never again. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 400 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
h1, h2, h3, p { margin: 0; }
svg { fill: currentColor; }
.muted { color: var(--muted); font-size: 15px; }
.error { color: var(--danger); font-size: 15px; margin-top: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- controls ---------- */
.btn {
  appearance: none; border: 0; border-radius: var(--r-control); min-height: 48px; padding: 0 20px;
  font-family: inherit; font-size: 17px; font-weight: 600; line-height: 1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .12s ease-out, background .16s ease-out;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn.block { width: 100%; }
.icon-btn {
  appearance: none; border: 0; background: var(--raised); color: var(--ink); width: 44px; height: 44px; border-radius: 999px;
  display: inline-grid; place-items: center; cursor: pointer; flex: none; /* a long title must not squeeze the button under 44 px */
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.accent { background: var(--accent); color: var(--on-accent); }
.field { display: grid; gap: 8px; }
.field span { color: var(--muted); font-size: 15px; }
input, textarea {
  font-family: inherit; font-size: 17px; font-weight: 400; line-height: 1.35; color: var(--ink); background: var(--raised);
  border: 1px solid transparent; border-radius: var(--r-control); padding: 12px 14px; min-height: 48px; width: 100%;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* ---------- welcome (premium: .claude/skills/premium) ---------- */
@font-face { font-family: "Bodoni Moda"; src: url("fontes/bodoni-moda.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Bodoni Moda"; src: url("fontes/bodoni-moda-italic.woff2") format("woff2"); font-weight: 500; font-style: italic; font-display: swap; }
/* The welcome is always the dark, cinematic one, whatever the system theme: it sits on a night photo. */
.welcome {
  --ink: #f5f0e6; --muted: #c9c0b1; --raised: rgb(255 255 255 / .1); --line: rgb(255 255 255 / .18);
  position: relative; height: 100dvh; overflow: hidden; background: #0b0a08; color: var(--ink); isolation: isolate;
}
.hero { position: absolute; inset: 0; z-index: -1; }
.hero-video { width: 100%; height: 100%; object-fit: cover; object-position: 50% 28%; display: block; }
.hero-scrim { position: absolute; inset: 0; background: linear-gradient(180deg, rgb(11 10 8 / .55) 0%, rgb(11 10 8 / 0) 22%, rgb(11 10 8 / .25) 42%, rgb(11 10 8 / .92) 66%, #0b0a08 100%); }
/* Film grain, fixed, 7 %: the difference between "a photo" and "a frame". */
.welcome::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .07; z-index: 1;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.welcome-content {
  position: relative; z-index: 2; height: 100%; display: flex; flex-direction: column; gap: 22px;
  padding: calc(var(--safe-top) + 20px) var(--gutter) calc(var(--safe-bottom) + 8px); max-width: 520px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; letter-spacing: .02em; }
.mark { width: 32px; height: 32px; flex: none; }
.mark.big { width: 64px; height: 64px; }
.welcome-text { margin-top: auto; }
.eyebrow { font-size: 13px; letter-spacing: .3em; text-transform: uppercase; color: var(--accent); }
.welcome h1 {
  font-family: "Bodoni Moda", "Didot", "Bodoni 72", Georgia, serif; font-weight: 500;
  font-size: clamp(2.9rem, 13vw, 6.5rem); line-height: .98; letter-spacing: -.02em; margin-top: 12px;
}
.welcome h1 em { font-style: italic; color: var(--accent); }
.lead { color: var(--muted); margin-top: 16px; font-size: 16px; line-height: 1.5; max-width: 34em; }
.welcome-form { display: grid; gap: 10px; }
.welcome-form input { background: rgb(255 255 255 / .1); border-color: rgb(255 255 255 / .16); color: var(--ink); backdrop-filter: blur(10px); }
.btn.premium { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); min-height: 52px; letter-spacing: .04em; }
.btn.premium:hover, .btn.premium:focus-visible { background: var(--accent); color: var(--on-accent); }
.btn.quiet { background: transparent; color: var(--ink); min-height: 44px; font-weight: 500; font-size: 15px; }
.credits { display: flex; flex-wrap: wrap; justify-content: center; column-gap: 4px; margin: 0; }
.credits a { color: var(--muted); font-size: 12px; text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; padding: 0 8px; }
.credits a:hover { color: var(--ink); }
/* Phone: the whole frame first (her, the desk phone, the table), uncropped at its own 2:3; the words follow below
   and the page scrolls. Only a thin fade at the bottom touches the film: nothing covers her, the desk phone or the table. */
@media (max-width: 759px) {
  .welcome { height: auto; min-height: 100dvh; overflow: visible; }
  body:has(#welcome:not([hidden])) { overflow-y: auto; }
  .hero { position: relative; inset: auto; z-index: 0; width: 100%; aspect-ratio: 2 / 3; }
  .hero-video { object-position: 50% 50%; }
  .hero-scrim { background: linear-gradient(180deg, rgb(11 10 8 / .55) 0%, rgb(11 10 8 / 0) 12%, rgb(11 10 8 / 0) 88%, #0b0a08 100%); }
  .welcome-content { height: auto; margin-top: -24px; padding-top: 0; }
  /* The logo sits on the film: the film is 100vw x 3/2 tall and this block starts 24px before it ends. */
  .brand { position: absolute; left: var(--gutter); top: calc(24px - 100vw * 3 / 2 + var(--safe-top) + 16px); }
  .welcome-text { margin-top: 0; }
  .welcome h1 { font-size: clamp(2.6rem, 12vw, 4rem); }
  .lead { font-size: 15px; margin-top: 12px; }
  .welcome-content { gap: 18px; }
}
/* Desktop: the film on the left at its own 9:16, the words on the right. */
@media (min-width: 760px) {
  .welcome { display: grid; grid-template-columns: min(66.67vh, 46vw) 1fr; }
  .hero { position: relative; inset: auto; z-index: 0; }
  .hero-scrim { background: linear-gradient(90deg, rgb(11 10 8 / 0) 70%, #0b0a08 100%); }
  .welcome-content { margin: 0; max-width: 560px; justify-content: center; padding: 48px clamp(1.25rem, 6vw, 6rem); }
  .welcome-text { margin-top: 0; }
  .welcome h1 { font-size: clamp(3.5rem, 6.4vw, 7.5rem); }
  .credits { justify-content: flex-start; margin-left: -8px; }
}
@media (prefers-reduced-motion: reduce) { .hero-video { display: none; } .hero { background: center 28% / cover url("media/heroi-poster.jpg"); } }

/* ---------- app shell ---------- */
.app { height: 100dvh; display: grid; grid-template-columns: 1fr; }
.pane { min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: calc(var(--safe-top) + 10px) var(--gutter) 10px;
  border-bottom: 1px solid var(--line); background: var(--surface); flex: none;
}
.topbar-title { font-size: 28px; font-weight: 700; letter-spacing: -.02em; flex: 1; }
.topbar-actions { display: flex; gap: 8px; }

/* phone: one screen at a time */
@media (max-width: 759px) {
  body[data-vista="lista"] #chat { display: none; }
  body[data-vista="conversa"] #lista { display: none; }
  .chat-empty { display: none !important; }
}
/* desktop: two panes */
@media (min-width: 760px) {
  .app { grid-template-columns: 360px 1fr; }
  .lista { border-right: 1px solid var(--line); background: var(--surface); }
  .back { display: none !important; }
}

/* ---------- chat list ---------- */
.contacts { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; background: var(--surface); }
.contact {
  appearance: none; border: 0; background: transparent; color: var(--ink); width: 100%; text-align: left; cursor: pointer;
  display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center; min-height: 72px; padding: 10px var(--gutter);
  font-family: inherit;
}
.contact:hover, .contact.on { background: var(--raised); }
.contact .nome { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact .previa { color: var(--muted); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact .hora { color: var(--muted); font-size: 13px; align-self: start; padding-top: 4px; }
.contact .textos { min-width: 0; display: grid; gap: 2px; }
.avatar {
  width: 48px; height: 48px; border-radius: 999px; display: grid; place-items: center; flex: none;
  font-weight: 700; font-size: 17px; color: #fff; text-transform: uppercase; letter-spacing: .02em;
}
.chat-head .avatar { width: 40px; height: 40px; font-size: 15px; }
.empty { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 12px; padding: 32px var(--gutter); text-align: center; background: var(--surface); }
.empty h3 { font-size: 22px; }
.empty p { color: var(--muted); margin-bottom: 8px; }
.empty .btn { width: 100%; max-width: 320px; align-self: center; }

/* ---------- conversation ---------- */
.chat-empty { flex: 1; display: grid; place-content: center; justify-items: center; gap: 16px; color: var(--muted); }
.chat-head { gap: 10px; padding-left: 8px; }
.chat-title { min-width: 0; display: grid; }
.chat-title strong { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title small { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messages { list-style: none; margin: 0; padding: 16px var(--gutter) 8px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.dia { align-self: center; color: var(--muted); font-size: 13px; padding: 12px 0 8px; }
.msg { max-width: min(78%, 560px); padding: 8px 12px 6px; border-radius: var(--r-bubble); margin-top: 6px; animation: entra .16s ease-out; overflow-wrap: anywhere; }
.msg.cont { margin-top: 2px; }
.msg p { white-space: pre-wrap; font-size: 17px; }
.msg time { display: block; font-size: 12px; text-align: right; margin-top: 2px; }
.mine { align-self: flex-end; background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 6px; }
.mine.cont-next { border-bottom-right-radius: var(--r-bubble); }
.mine time { color: var(--on-accent-muted); }
.theirs { align-self: flex-start; background: var(--raised); color: var(--ink); border-bottom-left-radius: 6px; }
.theirs.cont-next { border-bottom-left-radius: var(--r-bubble); }
.theirs time { color: var(--muted); }
.pill-agente { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; color: var(--agent); margin-bottom: 2px; }
.mine .pill-agente { color: var(--on-accent); }
.pill-agente svg { width: 14px; height: 14px; }
.composer {
  display: flex; gap: 8px; align-items: flex-end; padding: 8px var(--gutter) calc(var(--safe-bottom) + 8px);
  border-top: 1px solid var(--line); background: var(--surface); flex: none;
}
.composer textarea { resize: none; max-height: 160px; border-radius: 22px; padding: 11px 16px; min-height: 44px; }
.send { appearance: none; border: 0; width: 44px; height: 44px; border-radius: 999px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; cursor: pointer; flex: none; }
.send svg { width: 20px; height: 20px; }
@keyframes entra { from { opacity: 0; transform: translateY(6px); } }

/* ---------- sheets ---------- */
.sheet {
  border: 0; padding: 20px var(--gutter) calc(var(--safe-bottom) + 16px); background: var(--surface); color: var(--ink);
  width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 20px 20px 0 0; display: none;
  max-height: 92dvh; overflow-y: auto;
}
.sheet[open] { display: grid; gap: 14px; animation: sobe .16s ease-out; }
.sheet::backdrop { background: rgb(0 0 0 / .55); }
.sheet h2 { font-size: 22px; }
.sheet form { display: grid; gap: 12px; }
.sheet .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (min-width: 760px) {
  .sheet { width: 440px; margin: auto; border-radius: 20px; }
}
@keyframes sobe { from { transform: translateY(24px); opacity: 0; } }
.qr { background: #fff; border-radius: 16px; padding: 12px; width: min(240px, 70vw); aspect-ratio: 1; justify-self: center; }
.qr svg { width: 100%; height: 100%; display: block; }
.backup summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--muted); font-size: 15px; list-style-position: inside; }
.backup[open] { display: grid; gap: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 84px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 15px; max-width: calc(100vw - 32px);
  z-index: 10;
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
