/* Logos — Minha Jornada Bíblica
 * Identidade visual: verde-oliva (#344d3b), dourado (#a88953), papel creme e títulos em Georgia. */

:root {
  --bg: #f6f4ed;
  --paper: #fffdf8;
  --ink: #29352d;
  --muted: #777d72;
  --accent: #344d3b;
  --gold: #a88953;
  --line: #e0dfd4;
  --soft: #e8ede3;
  --danger: #a13c38;
  --brand: #344d3b;
  --brand-gold: #e4c78b;
  --header-h: 76px;
  --side-w: 218px;
  color-scheme: light;
}
body.dark {
  --bg: #171e19;
  --paper: #222b24;
  --ink: #e6eae0;
  --muted: #a9b1a5;
  --accent: #afc5a6;
  --gold: #d7b77b;
  --line: #39463b;
  --soft: #303f32;
  --danger: #ff9f9b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Cabeçalho ---------- */
header {
  height: calc(var(--header-h) + env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 12px max(24px, env(safe-area-inset-left));
}
.brand { display: flex; gap: 12px; align-items: center; cursor: pointer; min-width: 0; }
.brand strong { display: block; font: bold 29px Georgia, serif; line-height: 1; }
.brand small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; }
.logo {
  background: var(--brand);
  color: var(--brand-gold);
  border-radius: 14px;
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 24px;
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.save-state { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.save-state::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #6f9a72; }
.save-state[data-state='saving']::before { background: var(--gold); }
.save-state[data-state='error'] { color: var(--danger); font-weight: 600; }
.save-state[data-state='error']::before { background: var(--danger); }
.install-btn { background: var(--soft); color: var(--accent); border-color: transparent; font-weight: 600; }

/* ---------- Navegação ---------- */
aside#nav {
  position: fixed;
  top: calc(var(--header-h) + env(safe-area-inset-top));
  bottom: 0;
  width: var(--side-w);
  padding: 22px 13px;
  border-right: 1px solid var(--line);
  background: var(--paper);
  overflow: auto;
}
aside#nav button {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  margin: 2px 0;
  background: none;
  border: 0;
  color: var(--ink);
  padding: 10px 12px;
  min-height: 40px;
}
aside#nav button span { width: 18px; text-align: center; color: var(--muted); }
aside#nav button.active, nav#mobile button.active { background: var(--soft); color: var(--accent); font-weight: 700; }
aside#nav button.active span { color: var(--accent); }
.nav-sep { margin: 18px 12px 6px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
nav#mobile { display: none; }

main {
  margin-left: var(--side-w);
  max-width: 1200px;
  padding: 32px 36px 90px;
  outline: none;
}

/* ---------- Tipografia ---------- */
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 12px; }
h1 { font: 36px/1.15 Georgia, serif; }
h2 { font-size: 21px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; margin-top: 16px; }
p { margin: 8px 0 16px; }
.muted, small { color: var(--muted); }
.lead { margin-top: -4px; }
.eyebrow { font-size: 13px; color: var(--muted); margin: 0 0 6px; display: flex; align-items: center; gap: 6px; }
.hint { font-size: 13px; color: var(--muted); margin: 4px 0 10px; }
.count { font: 600 13px system-ui, sans-serif; color: var(--muted); background: var(--soft); border-radius: 20px; padding: 2px 8px; vertical-align: middle; }
.spacer { height: 16px; }

/* ---------- Controles ---------- */
button, input, select, textarea { font: inherit; }
button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 42px;
}
button:hover { border-color: var(--gold); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [role='button']:focus-visible, .node:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
body.dark button.primary { background: #4b6a53; border-color: #4b6a53; }
button.danger { color: var(--danger); }
button.small { min-height: 34px; padding: 6px 10px; font-size: 14px; }
button.mini { min-height: 30px; min-width: 30px; padding: 2px 8px; border-radius: 8px; line-height: 1; }
button.link {
  border: 0;
  background: none;
  color: var(--accent);
  padding: 3px 0;
  min-height: 0;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
}
button.ref-btn { background: var(--soft); border-color: transparent; color: var(--accent); font-weight: 600; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px;
  background: var(--paper);
  color: var(--ink);
}
input:disabled, select:disabled { opacity: .55; }
textarea { min-height: 130px; resize: vertical; line-height: 1.65; }
select.listbox { min-height: 180px; padding: 6px; }
select.listbox option { padding: 6px; border-radius: 6px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
.label-strong { font-size: 15px; color: var(--ink); font-weight: 600; margin-top: 0; }
label.check { display: flex; gap: 10px; align-items: flex-start; color: var(--ink); font-size: 15px; cursor: pointer; }
label.check input { width: auto; margin-top: 4px; }
label.check.inline { align-items: center; margin-top: 30px; font-size: 14px; }
fieldset.loc { border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px 12px; margin: 12px 0 0; }
fieldset.loc legend { font-size: 13px; color: var(--accent); font-weight: 600; padding: 0 6px; }
.loc-row { display: grid; grid-template-columns: 2fr 1fr 1.2fr; gap: 10px; }

/* ---------- Estrutura ---------- */
section, .card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 19px;
  margin-bottom: 14px;
}
.hero { background: var(--brand); color: #fff; padding: 24px; border-radius: 18px; margin: 20px 0; }
.hero small { color: #d7e0d2; letter-spacing: .06em; }
.hero button { background: #f4e5bf; color: var(--brand); border: 0; font-weight: 600; }
.hero button.ghost { background: transparent; color: #f4e5bf; border: 1px solid #f4e5bf66; font-weight: 400; }
.hero-title { font: 30px/1.2 Georgia, serif; margin: 10px 0 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.stat { text-align: left; margin: 0; }
.stat strong { font-size: 30px; display: block; color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.between { justify-content: space-between; }
.stack { display: grid; gap: 10px; }
.actions { margin: 0 0 14px; }
.notice {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  border: 1px solid var(--gold);
  background: color-mix(in srgb, var(--gold) 10%, var(--paper));
  border-radius: 15px;
  padding: 14px 16px;
  margin: 16px 0;
}

/* ---------- Itens e listas ---------- */
.item {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px;
  margin: 8px 0;
  overflow-wrap: anywhere;
  background: var(--paper);
}
.item[role='button'] { cursor: pointer; transition: border-color .15s, background .15s; }
.item[role='button']:hover { border-color: var(--gold); background: color-mix(in srgb, var(--soft) 35%, var(--paper)); }
.item p { white-space: pre-wrap; margin: 6px 0; }
.item .meta { display: block; margin-top: 4px; font-size: 12px; }
.item .ref { color: var(--accent); font-weight: 600; }
.pills { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  font-size: 12px;
  background: var(--soft);
  border-radius: 20px;
  padding: 4px 9px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.pill.high { background: color-mix(in srgb, var(--danger) 15%, var(--paper)); color: var(--danger); }
.pill.status-0 { background: color-mix(in srgb, var(--gold) 22%, var(--paper)); }
.pill.status-3 { background: color-mix(in srgb, #6f9a72 25%, var(--paper)); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; margin-right: 4px; vertical-align: middle; }
.reason { color: var(--muted); font-style: italic; margin: 6px 0 0; }
.empty { color: var(--muted); padding: 12px 0; }
.save { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.hist { margin: 4px 0; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.content .body { white-space: pre-wrap; line-height: 1.7; font-size: 17px; }
.content .meta { margin: 16px 0 0; }
.results { margin-top: 12px; }

.ref-group { margin-bottom: 18px; }
.group-title { font: 22px Georgia, serif; border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-top: 22px; }
.chapter-title { margin: 14px 0 4px; font-size: 15px; }
.verse-group { border-left: 3px solid var(--soft); padding-left: 12px; margin: 14px 0; }
.verse-head { display: flex; align-items: center; gap: 8px; }
.verse-tag { font-size: 13px; font-weight: 700; color: var(--accent); letter-spacing: .02em; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 12px; }
.toolbar { max-width: 360px; margin-bottom: 14px; }
.toolbar label { margin-top: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 4px; }
.chip {
  border-radius: 20px;
  min-height: 36px;
  padding: 6px 12px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}
.chip b { font-weight: 600; color: var(--muted); }
.chip.on { background: var(--soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
label.chip.check { font-size: 14px; align-items: center; }
label.chip.check input { margin: 0; accent-color: var(--brand); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-top: 12px; }
.seg button { border: 0; border-radius: 0; min-height: 38px; font-size: 14px; }
.seg button.on { background: var(--soft); color: var(--accent); font-weight: 700; }
.testament { margin-top: 22px; }
.book { text-align: left; display: block; }
.book strong { display: block; }
.ref-hit { border-color: var(--gold); }
.more-item { text-align: left; display: flex; gap: 12px; align-items: center; min-height: 52px; }
.more-item span { width: 22px; text-align: center; color: var(--accent); }
.more-item b { margin-left: auto; color: var(--muted); font-weight: 400; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }

/* ---------- Capítulos ---------- */
.chapter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 7px; }
.chapter-grid.wide { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.chapter-grid button { position: relative; padding: 8px 4px; }
.chapter-grid button.done { background: var(--soft); border-color: var(--accent); font-weight: 700; }
.chapter-grid button.doing { border-color: var(--gold); }
.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--gold);
  color: #fff;
  font: 700 11px/18px system-ui, sans-serif;
  font-style: normal;
  padding: 0 4px;
}
.badge.static { position: static; display: inline-block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sq { width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--line); display: inline-block; }
.sq.done { background: var(--soft); border-color: var(--accent); }
.sq.doing { border-color: var(--gold); }
.progress { height: 7px; background: var(--soft); border-radius: 9px; overflow: hidden; margin: 10px 0; }
.progress i { display: block; height: 100%; background: var(--gold); }

/* ---------- Mapa de conhecimento ---------- */
.map-filters { margin-bottom: 12px; }
.map-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 14px; align-items: start; }
.graph-box { position: relative; }
.graph {
  height: min(66vh, 640px);
  min-height: 340px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background:
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--line) 80%, transparent) 1px, transparent 0) 0 0 / 22px 22px,
    var(--paper);
  overflow: hidden;
  touch-action: none;
  user-select: none;
}
.map-svg { width: 100%; height: 100%; display: block; cursor: grab; }
.map-svg.grabbing { cursor: grabbing; }
.edge { stroke: #9caa94; stroke-width: 2; transition: opacity .2s; }
.edge.parent { stroke-dasharray: 5 4; stroke-width: 1.3; opacity: .75; }
.edge.hl { stroke: var(--gold); stroke-width: 3; opacity: 1; }
.edge.dim { opacity: .12; }
.node { cursor: pointer; transition: opacity .2s; outline: none; }
.node circle { stroke: var(--paper); stroke-width: 2.5; }
.node text {
  fill: var(--ink);
  font-size: 11.5px;
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--paper);
  stroke-width: 3.5px;
  stroke-linejoin: round;
}
.node.selected circle { stroke: var(--gold); stroke-width: 4; }
.node.selected text { font-weight: 700; }
.node.match circle { stroke: var(--danger); stroke-width: 3; }
.node.dim { opacity: .2; }
.map-svg.far .node:not(.selected):not(.near):not(.match) text { display: none; }
.map-controls { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 6px; }
.map-controls button { width: 40px; height: 40px; min-height: 40px; padding: 0; font-size: 18px; box-shadow: 0 1px 3px #0002; }
.map-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 16px;
  max-height: min(66vh, 640px);
  overflow: auto;
}
.map-panel h3 { font: 20px/1.25 Georgia, serif; }
.map-panel .near { padding: 8px 0; border-top: 1px solid var(--line); }
.map-panel .near small { display: block; }
.legend-row { margin: 4px 0; display: flex; align-items: center; gap: 4px; }
.map-empty { height: 100%; display: grid; place-content: center; text-align: center; padding: 20px; color: var(--muted); }

/* ---------- Diálogo e avisos ---------- */
dialog {
  max-width: 600px;
  width: calc(100% - 24px);
  max-height: 90dvh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  padding: 22px;
}
dialog::backdrop { background: #0008; }
.dialog-actions { margin-top: 18px; position: sticky; bottom: -22px; background: var(--paper); padding: 10px 0 4px; }
#toast {
  position: fixed;
  bottom: 85px;
  right: 16px;
  z-index: 20;
  background: var(--brand);
  color: #fff;
  border-radius: 10px;
  padding: 10px 15px;
  display: none;
  align-items: center;
  gap: 12px;
  max-width: 90vw;
  box-shadow: 0 6px 20px #0003;
}
#toast.show { display: flex; }
#toast button { background: #f4e5bf; color: var(--brand); border: 0; min-height: 34px; padding: 6px 12px; font-weight: 700; }

/* ---------- Celular ---------- */
@media (max-width: 900px) {
  .map-wrap { grid-template-columns: 1fr; }
  .map-panel { max-height: none; }
}
@media (max-width: 720px) {
  :root { --header-h: 66px; }
  header { padding: calc(10px + env(safe-area-inset-top)) 15px 10px; }
  .brand strong { font-size: 25px; }
  .brand small { font-size: 11px; }
  .logo { width: 40px; height: 40px; border-radius: 12px; font-size: 21px; }
  aside#nav { display: none; }
  main { margin: 0; padding: 22px 14px calc(110px + env(safe-area-inset-bottom)); }
  h1 { font-size: 30px; }
  nav#mobile {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 5;
    background: var(--paper);
    border-top: 1px solid var(--line);
    padding: 5px 3px calc(5px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  nav#mobile button { border: 0; background: none; font-size: 10px; flex: 1; padding: 5px 2px; min-width: 0; border-radius: 10px; }
  nav#mobile span { display: block; font-size: 19px; line-height: 1.3; }
  section, .card { padding: 15px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two { grid-template-columns: 1fr; gap: 0; }
  .hero { padding: 19px; }
  .hero-title { font-size: 26px; }
  input, select, textarea { font-size: 16px; }
  .loc-row { grid-template-columns: 1fr 1fr; }
  .loc-row .loc-book { grid-column: 1 / -1; }
  label.check.inline { margin-top: 12px; }
  .graph { height: 58vh; }
  #toast { left: 12px; right: 12px; bottom: calc(78px + env(safe-area-inset-bottom)); max-width: none; justify-content: space-between; }
  dialog { padding: 18px; max-height: 92dvh; }
  .dialog-actions { bottom: -18px; }
}
@media (max-width: 380px) {
  .save-state { font-size: 0; gap: 0; }
  .brand small { display: none; }
}
@media (display-mode: standalone) {
  .install-btn { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
@media print {
  header, aside#nav, nav#mobile, #toast, button:not(.link) { display: none !important; }
  main { margin: 0; padding: 0; }
  section, .item { break-inside: avoid; border-color: #ccc; }
}
