:root {
  --paper: #EFEBE2;
  --paper-2: #F7F4EE;
  --card: #FBF9F5;
  --ink: #1A1A1A;
  --ink-2: #4A4741;
  --muted: #8A857B;
  --line: #D9D3C7;
  --line-2: #E6E1D6;
  --coral: #FF7956;
  --coral-ink: #C8472A;
  --coral-soft: #FFE3D9;
  --ok: #2F7A4B;
  --ok-soft: #DDEFE2;
  --radius: 14px;
  --font: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--font); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--coral); outline-offset: 2px; }

.topstripe { height: 6px; background: var(--coral); position: sticky; top: 0; z-index: 30; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 6px; z-index: 25;
  display: flex; align-items: center; gap: 12px;
  padding: 10px clamp(16px, 4vw, 32px);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.brand { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-decoration: none; white-space: nowrap; }
.brand span { color: var(--muted); }
.topbar .spacer { flex: 1; }
.save-status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.save-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.save-status.saving .dot { background: var(--coral); animation: pulse 1s infinite; }
.save-status.offline .dot { background: #B98A1F; }
.save-status.idle { visibility: hidden; }
@keyframes pulse { 50% { opacity: .3; } }
.menu { position: relative; }
.menu-btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 6px 12px 6px 6px; display: flex; align-items: center; gap: 8px; font-size: 14px;
}
.avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: var(--paper);
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(26,26,26,.12); padding: 6px; display: none;
}
.menu.open .menu-pop { display: block; }
.menu-pop .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line-2); margin-bottom: 4px; font-size: 13px; }
.menu-pop .who small { display: block; color: var(--muted); }
.menu-pop a { display: block; padding: 9px 10px; border-radius: 8px; text-decoration: none; font-size: 14px; }
.menu-pop a:hover { background: var(--paper); }

/* ---------- Layout ---------- */
.app { min-height: calc(100vh - 60px); }
.wrap { max-width: 1080px; margin: 0 auto; padding: clamp(20px, 5vw, 48px) clamp(16px, 4vw, 32px) 80px; }
.narrow { max-width: 560px; }
.kicker { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.kicker.muted { color: var(--muted); }
h1 { font-size: clamp(34px, 6vw, 56px); line-height: 1.02; letter-spacing: -.02em; margin: 10px 0 8px; }
h2 { font-size: clamp(26px, 4vw, 34px); line-height: 1.1; letter-spacing: -.015em; margin: 6px 0 18px; }
h3 { font-size: 17px; margin: 0 0 4px; }
.lead { font-size: clamp(18px, 2.4vw, 22px); font-weight: 700; color: var(--ink-2); margin: 0 0 28px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.center-msg { text-align: center; padding: 80px 20px; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--ink); background: var(--ink); color: var(--paper);
  padding: 11px 18px; border-radius: 999px; font-weight: 700; font-size: 15px;
  text-decoration: none; transition: transform .08s ease, background .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { border-color: var(--ink); }
.btn.coral { background: var(--coral); border-color: var(--coral); color: var(--ink); }
.btn.small { padding: 7px 13px; font-size: 13px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); padding-left: 8px; padding-right: 8px; }
.btn.ghost:hover { color: var(--ink); }
.btn.danger { background: transparent; color: var(--coral-ink); border-color: transparent; }
.link-btn { background: none; border: 0; padding: 0; text-decoration: underline; text-underline-offset: 3px; color: inherit; font-size: inherit; }

/* ---------- Session list / doc cards ---------- */
.grid { display: grid; gap: 16px; }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.tile {
  display: flex; flex-direction: column; gap: 10px; text-decoration: none;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; min-height: 210px; transition: border-color .15s, transform .15s, box-shadow .15s;
}
a.tile:hover { border-color: var(--ink); transform: translateY(-2px); box-shadow: 0 10px 24px rgba(26,26,26,.06); }
.tile .tile-title { font-size: 24px; font-weight: 700; letter-spacing: -.01em; line-height: 1.1; }
.tile .tile-desc { color: var(--ink-2); font-size: 15px; flex: 1; }
.tile.locked { opacity: .6; }
.tile-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); }
.tile-cta { font-weight: 700; color: var(--ink); font-size: 14px; }
.progress { height: 6px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--coral); border-radius: 99px; transition: width .3s ease; }
.progress.done > i { background: var(--ok); }
.session-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; align-items: center; }

/* ---------- Document view ---------- */
.doc { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 32px; max-width: 1180px; margin: 0 auto; padding: 24px clamp(16px, 4vw, 32px) 96px; }
.doc-nav { position: sticky; top: 76px; align-self: start; max-height: calc(100vh - 96px); overflow: auto; padding-bottom: 12px; }
.doc-nav .back { font-size: 13px; color: var(--muted); text-decoration: none; display: inline-block; margin-bottom: 14px; }
.doc-nav .back:hover { color: var(--ink); }
.doc-nav .doc-title { font-size: 22px; font-weight: 700; line-height: 1.1; margin: 4px 0 12px; }
.doc-nav .count { font-size: 12px; color: var(--muted); margin: 8px 0 14px; }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list a {
  display: grid; grid-template-columns: 26px 1fr 18px; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 10px; text-decoration: none; font-size: 14px; color: var(--ink-2);
}
.nav-list a:hover { background: var(--paper-2); color: var(--ink); }
.nav-list a.active { background: var(--card); color: var(--ink); font-weight: 700; box-shadow: inset 0 0 0 1px var(--line); }
.nav-list .num { font-size: 11px; color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.state { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center; }
.state.started { border-color: var(--coral); background: linear-gradient(90deg, var(--coral) 50%, transparent 50%); }
.state.done { border-color: var(--ok); background: var(--ok); }
.state.done::after { content: ""; width: 6px; height: 3px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.state.reading { border-style: dashed; }

.mobile-nav { display: none; }
.item-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: clamp(22px, 4vw, 44px); min-height: 50vh;
}
.item-card > .kicker { color: var(--ink); }
.block { margin: 0 0 22px; }
.block h3 { font-size: 15px; }
.block p { color: var(--ink-2); }
.block ul.flow { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.block ul.flow li { background: var(--paper); border: 1px solid var(--line-2); border-radius: 99px; padding: 4px 11px; font-size: 13px; }
.block ul.flow li + li::before { content: none; }
.block ul.list { padding-left: 18px; margin: 6px 0 0; color: var(--ink-2); }
.block ul.list li { margin: 3px 0; }
.note { background: var(--paper); border-radius: 10px; padding: 10px 14px; font-size: 14px; color: var(--ink-2); margin-bottom: 20px; }
.divider { height: 1px; background: var(--line); margin: 28px 0 22px; border: 0; }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; }
.pager .btn { min-width: 0; }
.pager .next-label { max-width: 32ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Fields ---------- */
.field { margin: 0 0 20px; }
.field > label, .field > .label { display: block; font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.field .hint { font-size: 14px; color: var(--muted); margin: 0 0 8px; }
.field > label + .control, .field > .label + .control { margin-top: 8px; }
.field textarea, .field input[type=text], .field input[type=date], .field select, .input {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 11px 13px; font-size: 16px; line-height: 1.5; transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: none; overflow: hidden; min-height: 48px; display: block; }
.field textarea:focus, .field input:focus, .field select:focus, .input:focus {
  outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(255,121,86,.25);
}
.field select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.field.optional > label::after { content: " · opcional"; font-weight: 400; color: var(--muted); font-size: 13px; }
.group-title { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--coral-ink); margin: 30px 0 12px; padding-top: 18px; border-top: 1px solid var(--line); }
.group-title:first-child { margin-top: 0; padding-top: 0; border-top: 0; }

.check {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; cursor: pointer; font-weight: 400 !important; margin: 0 !important;
}
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--ok); flex: none; }
.check:has(input:checked) { border-color: var(--ok); background: var(--ok-soft); }
.field.checkfield { margin-bottom: 10px; }
.field > label.check { display: flex; }

.score { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 14px; }
.score input[type=range] { width: 100%; accent-color: var(--coral); }
.score output { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 62px; text-align: right; }
.score output small { color: var(--muted); font-weight: 400; }
.total {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  background: var(--ink); color: var(--paper); border-radius: 12px; padding: 14px 18px; margin: 4px 0 24px;
}
.total strong { font-size: 30px; font-variant-numeric: tabular-nums; }
.total .goal { font-size: 13px; opacity: .75; }
.total.ok strong { color: #9BE3B2; }

.suggest {
  display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left;
  background: var(--coral-soft); border: 1px dashed var(--coral); color: var(--ink);
  border-radius: 10px; padding: 9px 12px; margin: 0 0 8px; font-size: 14px;
}
.suggest b { white-space: nowrap; }
.suggest span { color: var(--ink-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ---------- Prompts ---------- */
.prompt-box {
  background: var(--ink); color: #EDE8DE; border-radius: 14px; padding: 20px 22px;
  font-size: 15px; line-height: 1.65; white-space: pre-wrap; word-break: break-word;
}
.prompt-box .var { background: rgba(255,121,86,.18); color: #FFB59F; border-radius: 4px; padding: 0 3px; }
.prompt-box .var.filled { background: rgba(255,255,255,.1); color: #fff; }
.prompt-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 26px; }
.section-label { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; }
.from-tag { font-size: 12px; color: var(--ok); font-weight: 400; margin-left: 6px; }
.copy-block { position: relative; }
.copy-block .prompt-box { padding-bottom: 56px; }
.copy-block .btn { position: absolute; right: 12px; bottom: 12px; }

/* ---------- Repeater ---------- */
.entries { display: grid; gap: 12px; margin: 8px 0 14px; }
.entry { border: 1px solid var(--line); border-radius: 14px; background: #fff; overflow: hidden; }
.entry-head {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  background: none; border: 0; text-align: left;
}
.entry-head .code { font-family: var(--mono); font-size: 12px; background: var(--paper); border-radius: 6px; padding: 2px 7px; flex: none; }
.entry-head .t { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-head .t.placeholder { color: var(--muted); font-weight: 400; }
.entry-head .chev { transition: transform .2s; color: var(--muted); }
.entry.open .entry-head .chev { transform: rotate(180deg); }
.entry-body { display: none; padding: 4px 16px 10px; border-top: 1px solid var(--line-2); }
.entry.open .entry-body { display: block; padding-top: 18px; }
.entry-foot { display: flex; justify-content: flex-end; gap: 8px; align-items: center; padding-bottom: 6px; font-size: 14px; }
.add-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.min-hint { font-size: 13px; color: var(--muted); }

/* ---------- Share / feedback ---------- */
.panel { border: 1px solid var(--line); border-radius: 14px; padding: 20px; background: var(--paper-2); margin-top: 28px; }
.panel h3 { font-size: 18px; margin-bottom: 6px; }
.linkbox { display: flex; gap: 8px; margin: 12px 0 4px; }
.linkbox input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 13px; }
.fb { border-top: 1px solid var(--line); padding: 14px 0 4px; }
.fb .meta { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 99px; padding: 2px 9px; background: var(--coral-soft); color: var(--coral-ink); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }

/* ---------- Read-only / print ---------- */
.ro-doc { margin: 0 0 40px; }
.ro-doc > .kicker { color: var(--coral-ink); }
.ro-item { break-inside: avoid; padding: 18px 0; border-top: 1px solid var(--line); }
.ro-item h3 { font-size: 18px; margin-bottom: 10px; }
.ro-item h4 { font-size: 14px; margin: 14px 0 6px; }
.ro-item dl { margin: 0; display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 6px 18px; }
.ro-item dt { font-size: 13px; color: var(--muted); }
.ro-item dd { margin: 0; white-space: pre-wrap; font-size: 15px; }
.ro-item dd.empty { color: var(--line); }
.ro-group { grid-column: 1 / -1; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--coral-ink); margin-top: 8px; }
.print-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin-bottom: 30px; }

/* ---------- Admin ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
tr:last-child td { border-bottom: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--paper-2); }
.mini { display: flex; align-items: center; gap: 8px; }
.mini .progress { width: 70px; }
.stats { margin-top: 24px !important; display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 0 0 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat b { display: block; font-size: 26px; }
.stat span { font-size: 13px; color: var(--muted); }

/* ---------- Onboarding ---------- */
.onboard .field input { font-size: 18px; padding: 14px 16px; }
.form-actions { margin-top: 26px; display: flex; gap: 10px; }
.err { color: var(--coral-ink); font-size: 14px; margin-top: 10px; min-height: 1em; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: var(--paper); padding: 11px 18px; border-radius: 999px; font-size: 14px;
  transition: all .25s ease; pointer-events: none; z-index: 60; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .doc { grid-template-columns: 1fr; gap: 0; padding-top: 12px; }
  .doc-nav {
    position: fixed; inset: 0; z-index: 50; max-height: none; background: var(--paper);
    padding: 24px 20px 40px; transform: translateY(100%); transition: transform .28s ease; visibility: hidden;
  }
  .doc-nav.open { transform: none; visibility: visible; }
  .doc-nav .close-nav { display: inline-flex !important; float: right; }
  .mobile-nav {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px;
  }
  .mobile-nav .back { font-size: 14px; color: var(--muted); text-decoration: none; }
  .mobile-nav button {
    flex: 1; display: flex; justify-content: space-between; align-items: center; gap: 8px;
    border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 14px; font-size: 14px; text-align: left; min-width: 0;
  }
  .mobile-nav button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .item-card { border-radius: 16px; padding: 22px 18px 26px; }
  .pager { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--paper) 30%); padding: 18px 0 calc(10px + env(safe-area-inset-bottom)); margin-top: 4px; }
  .pager .btn { flex: 1; }
  .pager .next-name { display: none; }
  .toast { bottom: 96px; }
  .ro-item dl { grid-template-columns: 1fr; gap: 2px; }
  .ro-item dd { margin-bottom: 8px; }
  .menu-btn .name { display: none; }
  .menu-btn { padding: 4px; }
}
.close-nav { display: none !important; }

@media print {
  @page { margin: 16mm; }
  body { background: #fff; font-size: 11pt; }
  .topstripe, .topbar, .no-print, .toast { display: none !important; }
  .wrap { padding: 0; max-width: none; }
  .ro-doc { break-before: page; }
  .ro-doc:first-of-type { break-before: auto; }
  .ro-item dd.empty { color: #bbb; }
}
