:root {
  --bg: #0e121c;
  --bg-soft: #141a28;
  --ink: #eef0f6;
  --ink-muted: #9aa3b8;
  --gold: #dfc889;
  --gold-soft: #c8b378;
  --line: rgba(238, 240, 246, 0.14);
  --danger: #e5707a;
  --ok: #7fd1a0;
  --radius: 12px;
  --font-sans: "DM Sans", system-ui, sans-serif;
  --font-serif: "Playfair Display", Georgia, serif;
  --font-mono: "DM Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--gold);
  text-decoration: none;
}

/* ---------- marca ---------- */
.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.brand-mark {
  color: var(--gold);
  font-size: 0.9em;
}

.brand-accent {
  color: var(--gold);
}

.brand-sub {
  display: block;
  margin-top: 0.2rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* ---------- login ---------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(60rem 30rem at 80% -10%, rgba(223, 200, 137, 0.08), transparent 60%),
    var(--bg);
}

.login-card {
  width: min(360px, 100%);
  padding: 2.2rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.login-card h1 {
  margin: 1.6rem 0 0.3rem;
  font-size: 1.25rem;
  font-weight: 700;
}

.login-muted {
  margin: 0 0 1.6rem;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field span {
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.field input,
.filter input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

.field input:focus,
.filter input:focus,
.filter select:focus {
  outline: none;
  border-color: var(--gold-soft);
  box-shadow: 0 0 0 3px rgba(223, 200, 137, 0.18);
}

.login-error {
  margin: 0 0 1rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid rgba(229, 112, 122, 0.4);
  border-radius: 8px;
  background: rgba(229, 112, 122, 0.12);
  color: var(--danger);
  font-size: 0.85rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  width: 100%;
  margin-top: 0.4rem;
  background: var(--gold);
  color: #1c1608;
}

.btn-primary:hover:not(:disabled) {
  background: var(--gold-soft);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
  border-color: var(--line);
}

.btn-ghost:hover {
  color: var(--ink);
  border-color: var(--ink-muted);
}

/* ---------- shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 236px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  padding: 1.4rem 1rem;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
}

.sidebar .brand {
  padding: 0 0.5rem;
}

.sidebar-nav {
  display: grid;
  gap: 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover {
  color: var(--ink);
  background: rgba(238, 240, 246, 0.06);
}

.nav-item.is-active {
  color: var(--ink);
  background: rgba(238, 240, 246, 0.06);
  box-shadow: inset 2px 0 0 var(--gold);
  font-weight: 700;
}

.nav-ico {
  width: 1.1rem;
  color: var(--gold);
  text-align: center;
}

.sidebar-foot {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 0.8rem;
}

/* ---------- main ---------- */
.app-main {
  padding: 2rem 2.4rem;
  min-width: 0;
}

.panel {
  max-width: 1000px;
}

.panel h2 {
  margin: 0 0 0.2rem;
  font-size: 1.4rem;
  font-weight: 700;
}

.panel-sub {
  margin: 0 0 1.4rem;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

/* cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.6rem;
}

.card {
  padding: 1rem 1.1rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.card-label {
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.card-value {
  margin-top: 0.3rem;
  font-size: 1.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.card-value .unit {
  font-size: 0.95rem;
  color: var(--ink-muted);
}

/* tabelas */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th {
  text-align: left;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  white-space: nowrap;
}

.table td {
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid rgba(238, 240, 246, 0.07);
  vertical-align: middle;
}

.table tr:last-child td {
  border-bottom: 0;
}

.table .mono {
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.tag {
  display: inline-block;
  padding: 0.14rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.tag-ok {
  color: var(--ok);
  border-color: rgba(127, 209, 160, 0.4);
  background: rgba(127, 209, 160, 0.1);
}

.tag-muted {
  color: var(--ink-muted);
}

.chip {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  padding: 0.14rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.badge {
  display: inline-block;
  padding: 0.12rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  font-size: 0.75rem;
  text-transform: capitalize;
}

.badge-info {
  color: var(--ink-muted);
}

.badge-warn {
  color: var(--gold);
  border-color: rgba(223, 200, 137, 0.4);
}

.badge-error {
  color: var(--danger);
  border-color: rgba(229, 112, 122, 0.4);
}

.badge-source {
  display: inline-block;
  max-width: 16ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0.1rem 0.5rem;
  border-radius: 6px;
  border: 1px solid rgba(133, 167, 205, 0.35);
  color: var(--ice, #9cc0e8);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.72rem;
}

.none {
  color: var(--ink-muted);
  font-style: italic;
}

/* filtros de erros */
.filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: end;
  margin-bottom: 1.2rem;
}

.filter label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.filter select {
  padding: 0.6rem 0.6rem;
  background: var(--bg-soft);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

.filter .btn {
  white-space: nowrap;
}

/* grade de personagens por foto */
.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.9rem;
}

.character-card {
  overflow: hidden;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.15s ease;
}

.character-card:hover {
  border-color: rgba(223, 200, 137, 0.5);
}

.character-photo {
  position: relative;
  aspect-ratio: 3 / 4;
  background: var(--bg);
  display: grid;
  place-items: center;
}

.character-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.character-photo.is-missing {
  background:
    linear-gradient(160deg, rgba(223, 200, 137, 0.08), transparent 55%),
    var(--bg);
}

.character-photo-fallback {
  font-size: 2.2rem;
  color: var(--gold-soft);
}

.character-info {
  padding: 0.8rem 0.9rem 0.95rem;
}

.character-name {
  margin: 0 0 0.15rem;
  font-size: 1rem;
  font-weight: 700;
}

.character-info .mono {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-bottom: 0.5rem;
}

.character-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.5rem 0 0.3rem;
}

.character-extra {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

/* gráfico simples de novos usuários */
.bars {
  display: flex;
  align-items: end;
  gap: 3px;
  height: 112px;
  padding: 0.8rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
}

.day {
  flex: 1 0 12px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

.bar {
  width: 100%;
  background: var(--gold);
  opacity: 0.85;
  border-radius: 2px 2px 0 0;
}

.bar.is-zero {
  background: var(--line);
}

.bar-label {
  margin-top: 0.15rem;
  font-size: 0.6rem;
  color: var(--ink-muted);
  text-align: center;
}

/* aviso de erros (retorno fetch/5xx) */
.banner {
  position: fixed;
  top: 0.8rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(560px, calc(100vw - 2rem));
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  font-size: 0.85rem;
}

.banner-err {
  color: var(--danger);
  border-color: rgba(229, 112, 122, 0.5);
}

.banner-ok {
  color: var(--ok);
  border-color: rgba(127, 209, 160, 0.5);
}

.skeleton {
  color: var(--ink-muted);
  font-style: italic;
}

details.raw {
  margin-top: 0.4rem;
}

details.raw summary {
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--ink-muted);
}

details.raw pre {
  margin: 0.4rem 0 0;
  padding: 0.6rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--line);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.spacer {
  flex: 1;
}

/* ---------- responsivo ---------- */
@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: column;
    gap: 0.8rem;
    padding: 1rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .app-main {
    padding: 1.2rem;
  }

  .sidebar-foot {
    margin-top: 0;
  }
}