/* ============ Character Forge — tema ============ */
:root {
  --bg: #12141c;
  --bg2: #1a1d29;
  --bg3: #232738;
  --border: #31364b;
  --text: #e6e8f0;
  --muted: #9aa1b5;
  --accent: #e0a458;
  --accent2: #c4843a;
  --danger: #e05c5c;
  --ok: #62c47a;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}
:root[data-theme="light"] {
  --bg: #f2f3f7;
  --bg2: #ffffff;
  --bg3: #e8eaf1;
  --border: #d3d7e2;
  --text: #23263a;
  --muted: #6b7286;
  --accent: #b07a2e;
  --accent2: #96631f;
  --danger: #c73e3e;
  --ok: #2f9e4f;
}
:root[data-theme="light"] .gnode text,
:root[data-theme="light"] .glabel { stroke: #f2f3f7; }
:root[data-theme="light"] .graph-wrap {
  background: radial-gradient(circle at 50% 40%, #dfe3ee 0%, #f2f3f7 100%);
}
:root[data-theme="light"] #gate {
  background: radial-gradient(circle at 50% 30%, #dfe3ee 0%, #c8cde0 70%);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.5;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }

#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 230px; min-width: 230px; background: var(--bg2);
  border-right: 1px solid var(--border); padding: 18px 14px;
  display: flex; flex-direction: column; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.brand-icon { font-size: 26px; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: .3px; }
.nav-main { display: flex; flex-direction: column; gap: 4px; }
.nav-main button {
  text-align: left; background: transparent; color: var(--muted);
  border: none; padding: 9px 12px; border-radius: 8px; font-size: 14px;
}
.nav-main button:hover { background: var(--bg3); color: var(--text); }
.nav-main button.active { background: var(--bg3); color: var(--accent); font-weight: 600; }
.proj-block h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 0 0 6px; }
#btn-new-char {
  margin-top: auto; background: var(--accent); color: #201505; font-weight: 700;
  border: none; padding: 11px; border-radius: var(--radius); font-size: 14px;
}
#btn-new-char:hover { background: var(--accent2); }
.sidebar-footer { font-size: 11px; color: var(--muted); text-align: center; opacity: .7; }

/* ---------- main / views ---------- */
#main { flex: 1; overflow-y: auto; padding: 26px 32px 60px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.view-head h2 { margin: 0; font-size: 22px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 8px; font-size: 13px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #201505; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 12px; }

/* ---------- toolbar de filtros ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.toolbar input[type="search"] { max-width: 260px; }
.toolbar select { width: auto; min-width: 130px; }

/* ---------- grid de personagens ---------- */
.char-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px;
}
.char-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: transform .12s, border-color .12s;
  display: flex; flex-direction: column;
}
.char-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.char-card .photo {
  width: 100%; aspect-ratio: 3/4; object-fit: cover; background: var(--bg3); display: block;
}
.char-card .loc-photo { aspect-ratio: 16/10; }
.char-card .ph-empty {
  width: 100%; aspect-ratio: 3/4; background: linear-gradient(135deg, var(--bg3), var(--bg2));
  display: flex; align-items: center; justify-content: center; font-size: 44px; color: var(--border);
}
.char-card .info { padding: 10px 12px; }
.char-card .name { font-weight: 700; font-size: 14px; }
.char-card .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 12px 12px; }
.badge {
  font-size: 10.5px; padding: 2px 8px; border-radius: 20px;
  background: var(--bg3); color: var(--muted); border: 1px solid var(--border);
}
.badge.role-protagonista { background: #3a2e17; color: var(--accent); border-color: var(--accent2); }
.badge.role-antagonista { background: #3a1717; color: #f08c8c; border-color: #7c3a3a; }
.badge.status-morto { color: var(--danger); }
.badge.status-desaparecido { color: var(--accent); }
.badge.act-create { background: #17301f; color: #7fd69a; border-color: #2c5940; }
.badge.act-update { background: #16283a; color: #7fa8d9; border-color: #2c4a6e; }
.badge.act-delete { background: #331616; color: #ef9090; border-color: #6e2c2c; }

/* ---------- ficha (visualização) ---------- */
.sheet { max-width: 900px; }
.sheet-header {
  display: flex; gap: 24px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; margin-bottom: 22px; align-items: flex-start;
}
.sheet-photo {
  width: 170px; aspect-ratio: 3/4; object-fit: cover; border-radius: 8px; background: var(--bg3);
}
.sheet-photo-empty {
  width: 170px; aspect-ratio: 3/4; border-radius: 8px; background: var(--bg3);
  display: flex; align-items: center; justify-content: center; font-size: 52px; color: var(--border);
  flex-shrink: 0;
}
.sheet-title h3 { margin: 0 0 2px; font-size: 26px; }
.sheet-title .sub { color: var(--muted); font-size: 14px; }
.sheet-title .badges { margin-top: 10px; padding: 0; }

.sect { margin-bottom: 22px; }
.sect > h4 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--accent);
  border-bottom: 1px solid var(--border); padding-bottom: 6px; margin: 0 0 12px;
}
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 20px; }
.kv .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.kv .v { font-size: 14px; }
.prose { white-space: pre-wrap; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }

.rel-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rel-item {
  display: flex; gap: 10px; align-items: center; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px;
}
.rel-item .rel-kind {
  font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 20px;
  background: var(--bg3); border: 1px solid var(--border); white-space: nowrap;
}
.rel-kind.familia { background: #17301f; color: #7fd69a; border-color: #2c5940; }
.rel-kind.lugar { background: #17301f; color: #7fd69a; border-color: #2c5940; }
.rel-kind.amor { background: #33161f; color: #ef8fb1; border-color: #6e2c44; }
.rel-kind.rivalidade, .rel-kind.inimizade { background: #331616; color: #ef9090; border-color: #6e2c2c; }
.rel-item a { color: var(--accent); text-decoration: none; font-weight: 600; }
.rel-item a:hover { text-decoration: underline; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--border); display: grid; gap: 14px; }
.timeline li { position: relative; }
.timeline li::before {
  content: ''; position: absolute; left: -23.5px; top: 6px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--accent);
}
.tl-when { font-size: 12px; color: var(--accent); font-weight: 600; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; position: relative; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; cursor: zoom-in; }
.gallery figcaption { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---------- editor ---------- */
.editor-form { max-width: 980px; }
.form-sect {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
}
.form-sect > h4 {
  margin: -18px -18px 14px; background: var(--bg3); padding: 10px 18px; font-size: 13px;
  text-transform: uppercase; letter-spacing: 1px; color: var(--accent); border-radius: var(--radius) var(--radius) 0 0;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.row-actions { display: flex; gap: 8px; align-items: center; }
.chip-box { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 20px; padding: 3px 10px;
}
.chip button { background: none; border: none; color: var(--muted); padding: 0; font-size: 13px; line-height: 1; }
.chip button:hover { color: var(--danger); }
.inline-entry { display: flex; gap: 8px; }
.inline-entry input, .inline-entry select { width: auto; flex: 1; }

.photo-pick { display: flex; gap: 16px; align-items: center; }
.photo-preview {
  width: 110px; height: 146px; border-radius: 8px; background: var(--bg3); object-fit: cover;
  display: flex; align-items: center; justify-content: center; color: var(--border); font-size: 34px;
}
.photo-preview, .loc-photo-preview { cursor: pointer; }

/* ---------- grafo ---------- */
.graph-wrap {
  position: relative; background: radial-gradient(circle at 50% 40%, #191d2c 0%, #101220 100%);
  border: 1px solid var(--border); border-radius: var(--radius); height: calc(100vh - 210px); min-height: 480px;
  overflow: hidden;
}
#graph-svg { width: 100%; height: 100%; display: block; touch-action: none; }
.graph-toolbar { position: absolute; top: 10px; left: 10px; z-index: 5; display: flex; gap: 6px; }
.graph-legend {
  position: absolute; bottom: 10px; left: 10px; z-index: 5; background: rgba(18,20,28,.92);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; font-size: 11.5px;
  color: var(--muted); display: grid; gap: 4px; max-width: 300px;
}
.legend-row { display: flex; align-items: center; gap: 8px; }
.legend-line { width: 26px; height: 0; border-top: 2px solid; }
.gnode { cursor: pointer; }
.gnode image { pointer-events: bounding-box; }
.gnode circle.ring { fill: var(--bg2); stroke: var(--border); stroke-width: 2; }
.gnode:hover circle.ring, .gnode.sel circle.ring { stroke: var(--accent); }
.gnode text { fill: var(--text); font-size: 11.5px; font-family: var(--font); paint-order: stroke; stroke: #12141c; stroke-width: 3px; text-anchor: middle; }
.gedge { stroke-linecap: round; }
.glabel { font-size: 10px; fill: var(--muted); text-anchor: middle; paint-order: stroke; stroke: #12141c; stroke-width: 3px; font-family: var(--font); }

/* ---------- tabelas simples ---------- */
.simple-table { width: 100%; border-collapse: collapse; }
.simple-table th, .simple-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.simple-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.table-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

/* ---------- modal ---------- */
.hidden { display: none !important; }
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
#modal {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  width: 520px; max-width: 95vw; max-height: 88vh; overflow-y: auto; padding: 22px;
}
#modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--accent); color: var(--text);
  padding: 11px 22px; border-radius: 30px; font-size: 13.5px; z-index: 200; box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
#toast.err { border-color: var(--danger); }

.empty-state { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty-state .big { font-size: 42px; margin-bottom: 10px; }

/* lightbox */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 300;
  display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 30px;
}
.lightbox img { max-width: 95vw; max-height: 92vh; border-radius: 8px; }

/* ---------- busca global ---------- */
.search-block { position: relative; }
#global-search {
  background: var(--bg3); border-color: transparent; font-size: 13px;
}
#global-search:focus { border-color: var(--accent); }
#search-results {
  position: absolute; top: 100%; left: 0; right: -60px; z-index: 50;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  margin-top: 6px; max-height: 420px; overflow-y: auto; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.sr-group {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent);
  padding: 8px 12px 3px; border-bottom: 1px solid var(--border);
}
.sr-item {
  display: flex; align-items: baseline; gap: 7px; padding: 8px 12px; cursor: pointer; font-size: 13.5px;
}
.sr-item:hover { background: var(--bg3); }
.sr-item small { margin-left: auto; color: var(--muted); font-size: 11px; }
.sr-item.muted { color: var(--muted); cursor: default; }

/* ---------- gate (login/setup) ---------- */
#gate {
  position: fixed; inset: 0; z-index: 500;
  background: radial-gradient(circle at 50% 30%, #1c2033 0%, #101220 70%);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.gate-card {
  width: 380px; max-width: 94vw; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 30px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

/* ---------- eventos ---------- */
.event-list { display: grid; gap: 12px; max-width: 900px; }
.event-card {
  display: flex; gap: 16px; align-items: flex-start;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; cursor: pointer; transition: border-color .12s, transform .12s;
}
.event-card:hover { border-color: var(--accent); transform: translateX(3px); }
.event-order {
  width: 34px; height: 34px; min-width: 34px; border-radius: 50%; background: var(--bg3);
  border: 1px solid var(--accent2); color: var(--accent); font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- mobile ---------- */
.sidebar-head { display: none; }
#nav-burger { display: none; }

@media (max-width: 860px) {
  #app { display: block; height: auto; overflow: visible; }
  .sidebar-head {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 10px 12px; border-bottom: 1px solid var(--border);
  }
  #nav-burger { display: none; }
  #sidebar {
    width: 100%; min-width: 0; max-height: none; overflow: visible;
    flex-direction: column; padding: 10px 14px 14px; border-right: none;
    border-bottom: 1px solid var(--border); gap: 8px;
  }
  .brand h1 { font-size: 15px; }
  #theme-toggle { margin-left: auto; }
  .nav-main { flex-direction: row; flex-wrap: wrap; }
  .nav-main button { padding: 8px 10px; font-size: 13px; flex: 1 1 44%; text-align: left; }
  .proj-block, .search-block { padding: 0 4px; }
  #btn-new-char { margin-top: 4px; }
  #user-box { padding-bottom: 8px; }

  #main { padding: 14px; overflow: visible; }
  .view-head { flex-wrap: wrap; gap: 10px; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; }
  .toolbar input[type="search"] { max-width: 100%; width: 100%; }
  .char-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .kv-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .sheet-header { flex-direction: column; align-items: stretch; }
  .sheet-photo, .sheet-photo-empty { width: 100%; aspect-ratio: 4/3; }
  .table-card { overflow-x: auto; }
  .simple-table { min-width: 520px; }
  .inline-entry { flex-wrap: wrap; }
  .inline-entry select, .inline-entry input { flex: 1 1 100%; max-width: 100% !important; }
  #modal { width: 100vw; max-width: 100vw; max-height: 100dvh; border-radius: 0; }
  .graph-wrap { height: calc(100dvh - 260px); min-height: 340px; }
  .graph-legend { max-width: 90%; font-size: 10.5px; }
  .event-card { flex-wrap: wrap; }
  .map-wrap { height: 52dvh; }
  .mic-bar { flex-wrap: wrap; }
  .audio-item { flex-wrap: wrap; }
}

/* ---------- impressão da ficha ---------- */
/* ---------- fallback de imagens ---------- */
img { max-width: 100%; }

/* ---------- novos componentes ---------- */
.mic-bar { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.mic-hint { cursor: help; }
.audio-item {
  display: flex; gap: 10px; align-items: center; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px;
}
.audio-item .inline-entry { flex: 1; min-width: 200px; }
.global-tl { margin-top: 10px; }
.global-tl li { margin-bottom: 10px; }
.wiki-link { color: var(--accent); text-decoration: underline dotted; }
.prose.md h4, .prose.md h5, .prose.md h6 { margin: 12px 0 4px; }
.prose.md ul, .prose.md ol { margin: 6px 0 6px 20px; }
.prose.md blockquote { border-left: 3px solid var(--accent); padding-left: 10px; color: var(--muted); }
.prose.md code { background: var(--bg3); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.map-wrap {
  position: relative; background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; height: 60vh; min-height: 340px;
}
.map-wrap img { width: 100%; height: 100%; object-fit: contain; display: block; }
#map-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: all; }
.pin-toolbar {
  position: absolute; top: 10px; left: 10px; right: 10px; z-index: 6;
  display: flex; gap: 8px; flex-wrap: wrap; background: rgba(18,20,28,.9);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px;
}
:root[data-theme="light"] .pin-toolbar { background: rgba(255,255,255,.95); }
.map-legend { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

@media print {
  #sidebar, .head-actions, #toast { display: none !important; }
  body, :root { --bg: #fff; --bg2: #fafafa; --text: #111; }
  #main { overflow: visible; padding: 0; }
  .sheet-header, .sect .prose, .rel-item { border-color: #ccc; background: #fff; }
  .kv .k, .sheet-title .sub { color: #555; }
  a { color: #111; text-decoration: none; }
}
