/* ══════════════════════════════════════════════════════════════
   LINHA DO TEMPO DA HUMANIDADE — estilos
   Céu noturno índigo, texto cor de pergaminho, fios coloridos.
   ══════════════════════════════════════════════════════════════ */

:root {
  --ink: #131530;
  --ink-2: #191c3b;
  --ink-3: #23274d;
  --ink-4: #2f3463;
  --rule: rgba(226, 220, 255, 0.09);
  --rule-2: rgba(226, 220, 255, 0.16);
  --paper: #eee7d7;
  --paper-2: #bcb8cf;
  --paper-3: #8b88a6;
  --brass: #e3b65c;

  --font-display: 'Cormorant Garamond', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --font-ui: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --shadow: 0 18px 50px rgba(5, 6, 18, 0.55);
  --panel-w: 420px;
  --drawer-w: 340px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--ink);
  color: var(--paper);
  font: 400 14px/1.45 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ───────── Estrutura ───────── */
.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

.top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 440px) auto;
  align-items: center;
  gap: 20px;
  padding: 12px 20px 10px;
  background: var(--ink-2);
}
.brand h1 {
  margin: 0;
  font: 600 25px/1.05 var(--font-display);
  letter-spacing: 0.005em;
  white-space: nowrap;
}
.status { margin: 3px 0 0; color: var(--paper-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.top-actions { display: flex; gap: 8px; }

/* ───────── Botões ───────── */
.btn, .btn-icon {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--rule-2);
  border-radius: var(--radius-m);
  background: var(--ink-3);
  font-weight: 500; font-size: 13px;
  transition: background-color .15s, border-color .15s;
}
.btn-icon { width: 34px; padding: 0; font-size: 18px; line-height: 1; }
.btn:hover, .btn-icon:hover { background: var(--ink-4); border-color: rgba(226, 220, 255, 0.26); }
.btn-solid { background: var(--brass); color: #1b1608; border-color: var(--brass); }
.btn-solid:hover { background: #f0c66f; border-color: #f0c66f; }
.btn-quiet { background: none; border: 0; padding: 6px 0; color: var(--paper-2); text-decoration: underline; text-underline-offset: 3px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--brass); font-size: 12px; font-weight: 500; }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--brass); color: #1b1608; font-size: 11px; font-weight: 600;
  display: inline-grid; place-items: center;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--paper-3)); flex: none; display: inline-block; }

/* ───────── Busca ───────── */
.search { position: relative; }
.search-ico {
  position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%);
  fill: none; stroke: var(--paper-3); stroke-width: 1.8; stroke-linecap: round; pointer-events: none;
}
.search input {
  width: 100%; height: 38px; padding: 0 12px 0 36px;
  border: 1px solid var(--rule-2); border-radius: var(--radius-m);
  background: var(--ink); color: var(--paper); font: inherit; font-size: 14px;
}
.search input::placeholder { color: var(--paper-3); }
.search input:focus { outline: none; border-color: var(--brass); }
.search-results {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 6px);
  margin: 0; padding: 6px; list-style: none;
  background: var(--ink-2); border: 1px solid var(--rule-2); border-radius: var(--radius-m);
  box-shadow: var(--shadow); max-height: 60vh; overflow: auto;
}
.search-results li {
  display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center;
  padding: 8px 10px; border-radius: var(--radius-s); cursor: pointer;
}
.search-results li small { grid-column: 2; color: var(--paper-3); font-size: 12px; }
.search-results li.is-cur, .search-results li:hover { background: var(--ink-3); }
.sr-name { font-weight: 500; }
.search-results .sr-empty { display: block; color: var(--paper-3); cursor: default; }

/* ───────── Categorias ───────── */
.cats {
  display: flex; gap: 8px; padding: 0 20px 12px;
  background: var(--ink-2);
  border-bottom: 1px solid var(--rule);
  overflow-x: auto; scrollbar-width: none;
}
.cats::-webkit-scrollbar { display: none; }
.cat {
  flex: none; display: inline-flex; align-items: center; gap: 8px;
  height: 30px; padding: 0 13px;
  border: 1px solid var(--rule-2); border-radius: 15px;
  background: transparent; font-size: 13px; font-weight: 500; color: var(--paper-2);
}
.cat.is-on { color: var(--paper); border-color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); }
.cat.is-soon { border-style: dashed; color: var(--paper-3); }
.cat.is-soon .dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c); }
.cat small { font-size: 11px; color: var(--paper-3); font-weight: 400; }

/* ───────── Palco da timeline ───────── */
.stage { position: relative; min-height: 0; overflow: hidden; }
.timeline { position: absolute; inset: 0; }
.tl-svg { display: block; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
.tl-svg:active { cursor: grabbing; }

.era.even { fill: rgba(255, 255, 255, 0.012); }
.era.odd { fill: rgba(255, 255, 255, 0.032); }
.compressed { fill: url(#hatch); }
.hatch-line { stroke: rgba(226, 220, 255, 0.06); stroke-width: 3; }
.grid line { stroke: rgba(226, 220, 255, 0.045); }

.axis-bg { fill: rgba(19, 21, 48, 0.94); }
.axis-rule { stroke: var(--rule-2); }
.era-labels text { font: italic 600 15px var(--font-display); fill: var(--paper-2); }
.ticks text { font: 500 11px var(--font-ui); fill: var(--paper-3); text-anchor: middle; font-variant-numeric: tabular-nums; }
.ticks line { stroke: var(--rule-2); }

.lane-bg { fill: transparent; }
.lane.is-odd .lane-bg { fill: rgba(255, 255, 255, 0.014); }
.lane.is-periods .lane-bg { fill: rgba(227, 182, 92, 0.03); }
.lane-rule { stroke: var(--rule); }
.lane-title { pointer-events: none; }
.lane-name { font: 600 16px var(--font-display); fill: var(--paper-2); paint-order: stroke; stroke: var(--ink); stroke-width: 4px; }
.lane-count { font: 500 11px var(--font-ui); fill: var(--paper-3); }

/* Itens */
.item, .work { cursor: pointer; transition: opacity .2s; }
.item .hit { fill: transparent; }
.item .bar { fill: var(--c); }
.item.approx .bar { opacity: 0.72; }
.item.t-periodo .bar { fill: color-mix(in srgb, var(--c) 30%, transparent); stroke: var(--c); stroke-opacity: .55; stroke-width: 1; }
.item .mark, .work .mark { fill: var(--c); stroke: var(--ink); stroke-width: 1.5; }
.item.t-evento .mark { fill: var(--ink); stroke: var(--c); stroke-width: 2; }
.label {
  font: 500 11.5px var(--font-ui); fill: var(--paper);
  paint-order: stroke; stroke: var(--ink); stroke-width: 3.5px; stroke-linejoin: round;
  pointer-events: none;
}
.item.t-periodo .label { font: italic 600 14px var(--font-display); fill: var(--paper-2); }
.work .label { font-size: 11px; fill: var(--paper-2); text-anchor: middle; }
.item:hover .label, .item:focus-visible .label { fill: #fff; }
.item:focus-visible, .work:focus-visible { outline: none; }
.item:focus-visible .bar, .item:focus-visible .mark, .work:focus-visible .mark { stroke: var(--brass); stroke-width: 2; }

/* Foco: o resto escurece, a vizinhança acende */
.has-focus .item:not(.is-focus):not(.is-near),
.has-focus .work:not(.is-focus):not(.is-near) { opacity: 0.16; }
.item.is-focus .label, .item.is-near .label { fill: #fff; }
.item.is-selected .bar { stroke: var(--paper); stroke-width: 1.5; }
.item.is-selected .label { font-weight: 600; }
.work.is-near .mark, .work.is-focus .mark { stroke: var(--paper); }

/* Conexões (os "fios") */
.link { fill: none; stroke-width: 1.15; opacity: 0.24; pointer-events: none; transition: opacity .2s; }
.link.dashed { stroke-dasharray: 4 4; }
.has-focus .link { opacity: 0.04; }
.has-focus .link.is-hot { opacity: 0.95; stroke-width: 1.9; filter: drop-shadow(0 0 3px currentColor); }
.has-path .link.is-hot { stroke-width: 2.6; }

/* Tooltip */
.tl-tooltip {
  position: absolute; left: 0; top: 0; z-index: 30; pointer-events: none;
  display: grid; gap: 2px; max-width: 280px;
  padding: 9px 12px; border-radius: var(--radius-s);
  background: var(--ink-2); border: 1px solid var(--rule-2); box-shadow: var(--shadow);
  font-size: 12px; color: var(--paper-2);
}
.tl-tooltip strong { font: 600 17px/1.15 var(--font-display); color: var(--paper); }
.tl-tooltip em { font-style: normal; color: var(--paper-3); }

.empty {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px;
  color: var(--paper-2); font: italic 500 22px var(--font-display);
}
.empty p { margin: 0; }

/* ───────── Rodapé: minimapa e zoom ───────── */
.bottom {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 20px calc(8px + env(safe-area-inset-bottom));
  background: var(--ink-2); border-top: 1px solid var(--rule);
}
.overview { flex: 1; height: 30px; border-radius: var(--radius-s); overflow: hidden; background: var(--ink); cursor: pointer; touch-action: none; }
.ov-svg { display: block; }
.ov-era.even { fill: rgba(255, 255, 255, 0.02); }
.ov-era.odd { fill: rgba(255, 255, 255, 0.05); }
.ov-dots line { stroke-width: 1.6; stroke-linecap: round; }
.ov-window { fill: rgba(227, 182, 92, 0.14); stroke: var(--brass); stroke-width: 1.2; }
.ov-labels text { font: 500 10px var(--font-ui); fill: var(--paper-3); pointer-events: none; }
.zoom-ctrl { display: flex; gap: 6px; }

/* ───────── Gaveta de filtros ───────── */
.drawer {
  position: absolute; z-index: 25; top: 0; left: 0; bottom: 0; width: var(--drawer-w);
  background: var(--ink-2); border-right: 1px solid var(--rule-2); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.drawer-body { overflow: auto; padding: 18px 18px 0; flex: 1; overscroll-behavior: contain; }
.drawer section { margin-bottom: 22px; }
.drawer h3 {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 0 0 9px; font: 600 13px var(--font-ui); color: var(--paper-2);
}
.seg { display: flex; padding: 3px; gap: 2px; border-radius: var(--radius-m); background: var(--ink); border: 1px solid var(--rule); }
.seg button { flex: 1; height: 30px; border: 0; border-radius: 7px; background: none; color: var(--paper-2); font-size: 12.5px; font-weight: 500; }
.seg button.is-on { background: var(--ink-4); color: var(--paper); }
.fchips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.fchip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 28px; padding: 0 10px;
  border: 1px solid var(--rule-2); border-radius: 14px; background: transparent;
  font-size: 12.5px; color: var(--paper-2);
}
.fchip small { color: var(--paper-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.fchip.is-on { color: var(--paper); background: color-mix(in srgb, var(--c, var(--paper)) 15%, transparent); border-color: var(--c, var(--paper-2)); }
.fchip:not(.is-on) .dot { opacity: 0.45; }
.fchip.is-dashed .dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c); }
.drawer-foot {
  position: sticky; bottom: 0; display: flex; gap: 8px; justify-content: space-between;
  padding: 14px 0 16px; background: linear-gradient(transparent, var(--ink-2) 30%);
}

/* ───────── Painel de detalhes ───────── */
.panel {
  position: absolute; z-index: 20; top: 0; right: 0; bottom: 0; width: var(--panel-w);
  background: var(--ink-2); border-left: 1px solid var(--rule-2); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  animation: panel-in .22s ease-out;
}
@keyframes panel-in { from { transform: translateX(24px); opacity: 0; } }
.panel-grip { display: none; }
.panel-close {
  position: absolute; z-index: 2; top: 12px; right: 12px;
  background: rgba(19, 21, 48, 0.7); backdrop-filter: blur(6px);
}
.panel-body { overflow: auto; padding: 0 24px 40px; overscroll-behavior: contain; }

.hero {
  position: relative; height: 190px; margin: 0 -24px 18px; overflow: hidden;
  background:
    radial-gradient(120% 90% at 20% 0%, color-mix(in srgb, var(--c) 38%, transparent), transparent 70%),
    var(--ink-3);
}
.hero-initials {
  position: absolute; left: 24px; bottom: 6px;
  font: 600 96px/1 var(--font-display); color: color-mix(in srgb, var(--c) 70%, var(--paper));
  opacity: 0.55;
}
.hero-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 22%; }
.hero.has-img .hero-initials { display: none; }
.hero::after { content: ''; position: absolute; inset: 0; background: linear-gradient(transparent 55%, var(--ink-2)); }

.p-head h2 { margin: 0; font: 600 36px/1.02 var(--font-display); letter-spacing: -0.005em; text-wrap: balance; }
.p-dates { margin: 8px 0 0; color: var(--paper-2); font-variant-numeric: tabular-nums; display: flex; gap: 12px; flex-wrap: wrap; }
.p-life { color: var(--paper-3); }
.p-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 0; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; height: 26px; padding: 0 10px;
  border-radius: 13px; border: 1px solid var(--rule-2); background: transparent; font-size: 12px; color: var(--paper-2);
}
.chip-facet:hover { border-color: var(--c); color: var(--paper); }
.chip-type { background: var(--ink-3); }
.p-lede { margin: 18px 0 0; font: 500 20px/1.4 var(--font-display); color: var(--paper); max-width: 34em; }

.p-sec { margin-top: 26px; }
.p-sec h3 { margin: 0 0 10px; font: 600 13px var(--font-ui); color: var(--paper-2); }
.p-ideas { margin: 0; padding-left: 18px; display: grid; gap: 6px; line-height: 1.45; }
.p-ideas li::marker { color: var(--brass); }
.p-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.p-links { display: flex; flex-wrap: wrap; gap: 6px; }
.p-muted { color: var(--paper-3); margin: 0; font-size: 13px; }
.p-extract { margin: 0; line-height: 1.62; color: var(--paper-2); font-size: 14.5px; max-width: 38em; }
.p-foot { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin: 10px 0 0; font-size: 12px; color: var(--paper-3); }
.p-ext { color: var(--brass); font-weight: 500; text-decoration: none; display: inline-block; margin-top: 10px; }
.p-foot .p-ext { margin-top: 0; }
.p-ext:hover { text-decoration: underline; text-underline-offset: 3px; }

.ent {
  display: inline-flex; align-items: center; gap: 7px; min-height: 28px; padding: 3px 11px 3px 9px;
  border: 1px solid var(--rule-2); border-radius: 14px; background: var(--ink-3);
  font-size: 13px; text-align: left;
}
.ent small { color: var(--paper-3); font-size: 11.5px; margin-left: 2px; }
.ent:hover { border-color: var(--c); background: var(--ink-4); }
.ent-missing { border-style: dashed; background: transparent; color: var(--paper-3); cursor: default; }
.p-list .ent { width: 100%; border-radius: var(--radius-s); justify-content: flex-start; }
.p-list .ent small { margin-left: auto; }

.conn-group { margin-bottom: 14px; }
.conn-group h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 7px; font-size: 12.5px; font-weight: 600; color: var(--paper); }
.conn-group h4 .n { color: var(--paper-3); font-weight: 500; }
.swatch { width: 18px; height: 3px; border-radius: 2px; background: var(--c); display: inline-block; }
.conn-group ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.conn-group li { display: grid; gap: 3px; justify-items: start; }
.conn-group .note { font-size: 12px; color: var(--paper-3); padding-left: 10px; border-left: 2px solid var(--c, var(--rule-2)); margin-left: 6px; }
.conn-group.is-pending h4 { color: var(--paper-3); }

.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.g-item, .g-skel { aspect-ratio: 1; border-radius: var(--radius-s); overflow: hidden; background: var(--ink-3); border: 0; padding: 0; }
.g-item img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.g-item:hover img { transform: scale(1.05); }
.g-skel { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }

.path-form { display: flex; gap: 8px; margin-top: 10px; }
.path-form input {
  flex: 1; min-width: 0; height: 34px; padding: 0 10px;
  border: 1px solid var(--rule-2); border-radius: var(--radius-m); background: var(--ink); color: var(--paper); font: inherit;
}
.path-form input:focus { outline: none; border-color: var(--brass); }
.path-steps { margin: 14px 0 4px; padding: 0; list-style: none; display: grid; gap: 4px; }
.path-steps li { display: grid; justify-items: start; gap: 4px; }
.via { font-size: 11.5px; color: var(--c); padding-left: 14px; position: relative; }
.via::before { content: ''; position: absolute; left: 4px; top: -4px; bottom: -4px; width: 2px; background: var(--c); border-radius: 1px; }

/* ───────── Lightbox ───────── */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  display: grid; grid-template-columns: 56px 1fr 56px; align-items: center;
  background: rgba(8, 9, 22, 0.94);
}
.lightbox figure { margin: 0; display: grid; justify-items: center; gap: 12px; min-width: 0; }
.lightbox img { max-width: 100%; max-height: 78vh; object-fit: contain; border-radius: 4px; background: var(--ink-3); }
.lightbox figcaption { display: flex; flex-wrap: wrap; gap: 4px 16px; justify-content: center; max-width: 70ch; font-size: 12.5px; color: var(--paper-2); text-align: center; }
.lightbox figcaption strong { width: 100%; font: 600 19px var(--font-display); color: var(--paper); }
.lightbox figcaption a { color: var(--brass); }
.lb-count { color: var(--paper-3); }
.lb-close { position: absolute; top: 16px; right: 16px; }
.lb-prev, .lb-next { justify-self: center; font-size: 26px; }

/* ───────── Ajuda ───────── */
.help {
  width: min(460px, calc(100vw - 32px)); padding: 26px 26px 22px;
  border: 1px solid var(--rule-2); border-radius: var(--radius-l);
  background: var(--ink-2); color: var(--paper); box-shadow: var(--shadow);
}
.help::backdrop { background: rgba(8, 9, 22, 0.7); }
.help h2 { margin: 0 0 14px; font: 600 28px var(--font-display); }
.help dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 13.5px; }
.help dt { color: var(--paper); font-weight: 600; }
.help dd { margin: 0; color: var(--paper-2); }
.help-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 18px 0; font-size: 12.5px; color: var(--paper-2); }
.help-legend span { display: inline-flex; align-items: center; gap: 7px; }
.help-legend i { display: inline-block; }
.lg-bar { width: 22px; height: 6px; border-radius: 3px; background: #5b9bf0; }
.lg-diamond { width: 9px; height: 9px; background: #f2c14e; transform: rotate(45deg); }
.lg-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid #4fc9a0; }
.lg-hatch { width: 22px; height: 12px; background: repeating-linear-gradient(45deg, rgba(226,220,255,.18) 0 2px, transparent 2px 6px); }

/* ───────── Celular ───────── */
@media (max-width: 760px) {
  .top { grid-template-columns: minmax(0, 1fr) auto; gap: 10px 10px; padding: 10px 14px 8px; }
  .brand h1 { font-size: 20px; white-space: normal; text-wrap: balance; }
  .status { display: none; }
  .search { grid-column: 1 / -1; grid-row: 2; }
  .cats { padding: 0 14px 10px; }
  .cat.is-soon { display: none; }
  .cats { gap: 6px; }
  .cat { padding: 0 10px; gap: 6px; font-size: 12.5px; }
  .bottom { padding: 8px 14px calc(8px + env(safe-area-inset-bottom)); gap: 8px; }
  #zoom-in, #zoom-out { display: none; }

  .panel {
    top: auto; left: 0; width: auto; height: 64%;
    border-left: 0; border-top: 1px solid var(--rule-2);
    border-radius: var(--radius-l) var(--radius-l) 0 0;
    animation: sheet-in .24s ease-out;
    transition: height .25s ease;
  }
  .panel.is-tall { height: calc(100% - 8px); }
  @keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
  .panel-grip {
    display: block; position: absolute; z-index: 3; top: 0; left: 50%; transform: translateX(-50%);
    width: 80px; height: 22px; border: 0; background: none;
  }
  .panel-grip::before { content: ''; position: absolute; left: 50%; top: 8px; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--rule-2); }
  .panel-body { padding: 0 18px 32px; border-radius: inherit; }
  .hero { height: 104px; margin: 0 -18px 12px; border-radius: var(--radius-l) var(--radius-l) 0 0; }
  .hero-initials { font-size: 64px; }
  .p-head h2 { font-size: 30px; }
  .p-lede { font-size: 18.5px; }

  .drawer {
    top: auto; right: 0; width: auto; height: 82%;
    border-right: 0; border-top: 1px solid var(--rule-2);
    border-radius: var(--radius-l) var(--radius-l) 0 0;
  }
  .lightbox { grid-template-columns: 1fr; grid-template-rows: 1fr auto; padding: 56px 12px 16px; }
  .lb-prev, .lb-next { position: absolute; bottom: 18px; }
  .lb-prev { left: 16px; } .lb-next { right: 16px; }
}

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