/* ============================================================
   ER&R Fans Hub — Design System
   Identidade: "Entre Ruínas e Reinos" — fantasia épica.
   Carvão quente + dourado/bronze + roxo arcano. Espada & moeda.
   Títulos editoriais em Fraunces, UI em DM Sans.
   ============================================================ */

:root {
  /* Fundos (carvão quente, do mais escuro ao elevado) */
  --bg:          #0E0B0A;
  --bg-1:        #15110D;
  --surface:     #1B1510;
  --surface-2:   #231A12;
  --elev:        #2A1F15;

  /* Dourado / bronze (acento primário) */
  --gold:        #C9A24B;
  --gold-bright: #E4C271;
  --gold-deep:   #9A7A33;
  --bronze:      #8A5A2B;

  /* Roxo arcano (secundário) e brasa (alertas/destaques quentes) */
  --arcane:      #6B4E8F;
  --arcane-dim:  #3B2A52;
  --ember:       #C2410C;
  --blood:       #8E2B2B;

  /* Texto (pergaminho quente) */
  --text:        #F2E9DC;
  --text-dim:    #C2B4A0;
  --text-mute:   #8C7E69;

  /* Bordas / linhas (dourado translúcido) */
  --line:        rgba(201, 162, 75, 0.18);
  --line-soft:   rgba(201, 162, 75, 0.10);
  --line-strong: rgba(201, 162, 75, 0.38);

  /* Estados */
  --ok:          #5FA873;
  --warn:        #D8A24B;
  --danger:      #C0533F;

  --radius:      14px;
  --radius-sm:   9px;
  --shadow:      0 14px 40px rgba(0, 0, 0, 0.45);
  --shadow-gold: 0 8px 28px rgba(201, 162, 75, 0.16);

  --font-ui:     'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-title:  'Fraunces', Georgia, 'Times New Roman', serif;

  --maxw:        1120px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Textura de fundo: brilho dourado sutil no topo + vinheta */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(1100px 520px at 50% -10%, rgba(201, 162, 75, 0.10), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(107, 78, 143, 0.08), transparent 55%),
    var(--bg);
}

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

h1, h2, h3, h4 { font-family: var(--font-title); font-weight: 600; line-height: 1.15; margin: 0; }

::selection { background: rgba(201, 162, 75, 0.30); color: #fff; }

/* ---------- Tipografia utilitária ---------- */
.eyebrow {
  font-size: 11px; letter-spacing: 0.24em; text-transform: uppercase;
  color: var(--gold); font-weight: 600;
}
.muted { color: var(--text-mute); }
.dim { color: var(--text-dim); }
.serif { font-family: var(--font-title); }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-ui); font-size: 15px; font-weight: 600;
  padding: 11px 22px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer;
  transition: transform .08s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #1A130A; box-shadow: var(--shadow-gold);
}
.btn-primary:hover { color: #1A130A; filter: brightness(1.05); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; filter: grayscale(.3); }
.btn-ghost {
  background: transparent; color: var(--text); border-color: var(--line-strong);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--gold-bright); }
.btn-block { width: 100%; }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field label { font-size: 13px; color: var(--text-dim); font-weight: 500; }
.input {
  width: 100%; padding: 12px 14px; font-family: var(--font-ui); font-size: 15px;
  color: var(--text); background: var(--bg-1);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .2s ease, box-shadow .2s ease;
}
.input::placeholder { color: var(--text-mute); }
.input:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 162, 75, 0.14);
}

/* ---------- Cartões ---------- */
.card {
  background: linear-gradient(180deg, var(--surface), var(--bg-1));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Divisor de moeda (motivo do site oficial) ---------- */
.coin-rule {
  display: flex; align-items: center; gap: 14px; color: var(--gold-deep);
  margin: 22px 0;
}
.coin-rule::before, .coin-rule::after {
  content: ""; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, var(--line-strong), transparent);
}
.coin-rule .coin {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid var(--gold); position: relative; flex: none;
}
.coin-rule .coin::after {
  content: ""; position: absolute; inset: 3px; border-radius: 50%;
  border: 1px solid var(--gold-deep);
}

/* ============================================================
   Tela de acesso (login por magic link)
   ============================================================ */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 420px; padding: 40px 34px;
  background: linear-gradient(180deg, var(--surface), var(--bg-1));
  border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  text-align: center;
}
.auth-crest {
  width: 64px; height: 64px; margin: 0 auto 18px;
}
.auth-card h1 { font-size: 26px; margin-bottom: 6px; }
.auth-card .sub { color: var(--text-dim); font-size: 15px; margin: 0 0 26px; }
.auth-card form { text-align: left; }
.auth-note { font-size: 13px; color: var(--text-mute); margin-top: 16px; line-height: 1.5; }
.auth-ok {
  background: rgba(95, 168, 115, 0.10); border: 1px solid rgba(95, 168, 115, 0.35);
  color: #B8E0C2; border-radius: var(--radius-sm); padding: 14px 16px; font-size: 14px;
  line-height: 1.5; text-align: left;
}
.auth-err {
  background: rgba(192, 83, 63, 0.12); border: 1px solid rgba(192, 83, 63, 0.4);
  color: #ECB6AC; border-radius: var(--radius-sm); padding: 12px 14px; font-size: 14px;
  margin-bottom: 14px; text-align: left;
}

/* ============================================================
   Shell autenticado (sidebar + conteúdo)
   ============================================================ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 256px; flex: none; padding: 26px 18px;
  border-right: 1px solid var(--line); background: rgba(14, 11, 10, 0.6);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 4px; }
.brand .mark { width: 34px; height: 34px; flex: none; }
.brand .name { font-family: var(--font-title); font-size: 17px; font-weight: 600; line-height: 1.1; }
.brand .name small { display: block; font-family: var(--font-ui); font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold); margin-top: 2px; }

.nav { margin-top: 22px; display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  border-radius: var(--radius-sm); color: var(--text-dim); cursor: pointer;
  font-size: 14.5px; font-weight: 500; border: 1px solid transparent;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(201,162,75,0.14), rgba(201,162,75,0.04));
  color: var(--gold-bright); border-color: var(--line);
}
.nav-item .ico { font-family: var(--font-title); font-size: 18px; width: 20px; text-align: center; }
.nav-section { font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--text-mute); padding: 18px 14px 6px; }

.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--gold), var(--bronze));
  display: flex; align-items: center; justify-content: center;
  color: #1A130A; font-weight: 700; font-size: 14px;
}
.user-chip .who { font-size: 13px; line-height: 1.2; overflow: hidden; }
.user-chip .who b { font-weight: 600; }
.user-chip .who span { display: block; color: var(--text-mute); font-size: 11px; }

.content { flex: 1; min-width: 0; }
.content-inner { max-width: var(--maxw); margin: 0 auto; padding: 38px 40px 80px; }

.page-head { margin-bottom: 26px; }
.page-head h1 { font-size: 34px; margin-bottom: 6px; }
.page-head p { color: var(--text-dim); margin: 0; max-width: 60ch; }

/* Estado vazio / "em construção" das seções (Fases 2-6) */
.soon {
  border: 1px dashed var(--line-strong); border-radius: var(--radius);
  padding: 48px 32px; text-align: center; color: var(--text-dim);
  background: rgba(27, 21, 16, 0.4);
}
.soon .ico { font-size: 40px; color: var(--gold-deep); }
.soon h3 { font-size: 20px; margin: 14px 0 6px; color: var(--text); }
.badge {
  display: inline-block; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--gold); border: 1px solid var(--line-strong); border-radius: 20px;
  padding: 3px 10px; margin-top: 14px;
}

/* Topbar mobile */
.topbar { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .content-inner { padding: 22px 18px 64px; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0;
    background: rgba(14, 11, 10, 0.92); backdrop-filter: blur(8px); z-index: 20;
  }
  .page-head h1 { font-size: 27px; }
}

/* Spinner */
.spin {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(242, 233, 220, 0.25); border-top-color: var(--gold);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; }

/* ============================================================
   A Taverna — chat
   ============================================================ */
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-mute); flex: none; box-shadow: 0 0 0 0 rgba(95,168,115,0.5); }
.live-dot.on { background: var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(95,168,115,0.45); } 70% { box-shadow: 0 0 0 7px rgba(95,168,115,0); } 100% { box-shadow: 0 0 0 0 rgba(95,168,115,0); } }

.tag-filter {
  display: flex; align-items: center; gap: 8px; margin-bottom: 14px;
  padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 14px; color: var(--text-dim);
}

.chat { display: flex; flex-direction: column; height: calc(100vh - 230px); min-height: 420px; overflow: hidden; }
.chat-list { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; }
.chat-empty { margin: auto; text-align: center; padding: 40px; }
.load-more { text-align: center; padding: 4px 0 14px; }

/* Fundo do chat (sutil, no tema carvão) */
.chat-list.wa-bg {
  gap: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(201,162,75,0.045), transparent 42%),
    radial-gradient(circle at 82% 85%, rgba(107,78,143,0.06), transparent 42%),
    var(--bg);
}

/* Separador de data */
.day-sep { display: flex; justify-content: center; margin: 16px 0 10px; }
.day-sep span {
  font-size: 11px; letter-spacing: 0.06em; color: var(--text-dim);
  background: rgba(27,21,16,0.92); border: 1px solid var(--line-soft);
  padding: 4px 12px; border-radius: 14px;
}

/* Linha do balão */
.brow { display: flex; gap: 8px; align-items: flex-end; margin-top: 2px; position: relative; }
.brow.gstart { margin-top: 10px; }
.brow.has-reacts { margin-bottom: 12px; }
.brow.mine { flex-direction: row-reverse; }
.brow-avatar { width: 30px; flex: none; }
.avatar.sm {
  width: 30px; height: 30px; border-radius: 50%; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--arcane), var(--arcane-dim)); color: #F2E9DC; font-weight: 700;
}
.brow-main { display: flex; align-items: flex-end; gap: 6px; max-width: 78%; }
.brow.mine .brow-main { flex-direction: row-reverse; }

/* Balão */
.bubble {
  position: relative; padding: 7px 11px 6px; border-radius: 12px; min-width: 64px;
  background: var(--surface-2); color: var(--text-dim); font-size: 15px; line-height: 1.45;
  border: 1px solid var(--line-soft);
}
.brow.mine .bubble {
  background: linear-gradient(180deg, rgba(201,162,75,0.20), rgba(201,162,75,0.12));
  border-color: var(--line); color: var(--text);
}
.brow.other.gstart .bubble { border-top-left-radius: 4px; }
.brow.mine.gstart .bubble { border-top-right-radius: 4px; }
.brow.hidden .bubble { opacity: 0.72; border-style: dashed; }
.bubble-name { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.bubble-body { word-break: break-word; }
.bubble-time { display: block; text-align: right; font-size: 10.5px; color: var(--text-mute); margin-top: 3px; user-select: none; }
.brow.mine .bubble-time { color: rgba(26,19,10,0.55); }

/* Pílula de reação colada no balão */
.react-pill {
  position: absolute; bottom: -11px; display: inline-flex; align-items: center; gap: 1px;
  background: var(--elev); border: 1px solid var(--line); border-radius: 12px;
  padding: 1px 6px; font-size: 12px; cursor: pointer; line-height: 1.5;
  box-shadow: 0 2px 6px rgba(0,0,0,0.32);
}
.brow.other .react-pill { left: 8px; }
.brow.mine .react-pill { right: 8px; }
.react-pill b { font-size: 11px; color: var(--text); margin-left: 2px; font-weight: 700; }
.react-pill span.mine { filter: drop-shadow(0 0 3px var(--gold)); }

/* Ações ao passar o mouse (reagir / remover) */
.brow-actions { display: flex; flex-direction: column; gap: 4px; opacity: 0; transition: opacity .12s; align-self: center; }
.brow:hover .brow-actions { opacity: 1; }
.brow-act {
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--text-dim); cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.brow-act:hover { color: var(--gold-bright); border-color: var(--line-strong); }

/* Popover de reações (6 emojis) */
.react-backdrop { position: fixed; inset: 0; z-index: 30; }
.react-popover {
  position: absolute; bottom: 100%; margin-bottom: 6px; z-index: 31;
  display: flex; gap: 2px; padding: 5px; background: var(--elev);
  border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow);
}
.brow.other .react-popover { left: 38px; }
.brow.mine .react-popover { right: 38px; }
.react-popover button { background: none; border: none; cursor: pointer; font-size: 21px; padding: 3px 5px; border-radius: 50%; transition: transform .1s, background .1s; }
.react-popover button:hover { transform: scale(1.25); }
.react-popover button.active { background: rgba(201,162,75,0.22); }

.role-badge {
  font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700;
  color: #1A130A; background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  padding: 1px 7px; border-radius: 10px;
}
.hidden-badge { font-size: 11px; color: var(--warn); border: 1px solid var(--line); border-radius: 10px; padding: 1px 8px; display: inline-block; }

/* Composer estilo WhatsApp */
.composer { border-top: 1px solid var(--line); padding: 10px 14px; background: var(--bg-1); }
.composer-toolbar { display: flex; gap: 3px; margin-bottom: 8px; }
.composer-toolbar button {
  width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--line-soft);
  background: var(--surface); color: var(--text-dim); cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center; transition: all .12s;
}
.composer-toolbar button:hover, .composer-toolbar button.active { color: var(--gold-bright); border-color: var(--line-strong); background: var(--surface-2); }
.emoji-grid {
  display: grid; grid-template-columns: repeat(12, 1fr); gap: 2px; margin-bottom: 8px;
  padding: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.emoji-grid button { background: none; border: none; cursor: pointer; font-size: 19px; padding: 4px; border-radius: 6px; }
.emoji-grid button:hover { background: var(--surface-2); }
.composer-bar { display: flex; align-items: flex-end; gap: 8px; }
.composer-icon {
  width: 40px; height: 40px; flex: none; border-radius: 50%; border: 1px solid var(--line-soft);
  background: var(--surface); color: var(--text-dim); cursor: pointer; font-size: 15px;
  display: flex; align-items: center; justify-content: center; transition: all .12s;
}
.composer-icon:hover, .composer-icon.active { color: var(--gold-bright); border-color: var(--line-strong); background: var(--surface-2); }
.composer-input {
  flex: 1; resize: none; max-height: 140px; min-height: 40px; line-height: 1.5;
  padding: 9px 16px; font-family: var(--font-ui); font-size: 15px; color: var(--text);
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 20px; outline: none;
}
.composer-input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,162,75,0.12); }
.composer-input::placeholder { color: var(--text-mute); }
.composer-send {
  width: 44px; height: 44px; flex: none; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold)); color: #1A130A;
  font-size: 17px; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-gold); transition: filter .12s;
}
.composer-send:hover { filter: brightness(1.06); }
.composer-send:disabled { opacity: .5; cursor: not-allowed; filter: grayscale(.3); }

@media (max-width: 540px) {
  .emoji-grid { grid-template-columns: repeat(8, 1fr); }
  .brow-main { max-width: 86%; }
  .brow-actions { opacity: 1; }
}

/* Hashtag inline */
.hashtag { color: var(--gold-bright); font-weight: 600; cursor: pointer; }
.hashtag:hover { text-decoration: underline; }

/* Markdown leve (corpo das mensagens) */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md-p { margin: 2px 0; }
.md-h1 { font-family: var(--font-title); font-size: 18px; color: var(--text); margin: 6px 0 2px; }
.md-h2 { font-family: var(--font-title); font-size: 15.5px; color: var(--gold-bright); margin: 5px 0 2px; font-weight: 600; }
.md-ul, .md-ol { margin: 3px 0; padding-left: 22px; }
.md-ul li, .md-ol li { margin: 1px 0; }
.md strong { color: var(--text); font-weight: 700; }
.md em { font-style: italic; }

/* ============================================================
   Admin — toggle (kill-switch)
   ============================================================ */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.toggle {
  width: 52px; height: 30px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--bg-1); cursor: pointer; position: relative; flex: none;
  transition: background .18s ease, border-color .18s ease; padding: 0;
}
.toggle.on { background: linear-gradient(180deg, var(--gold-bright), var(--gold)); border-color: var(--gold-deep); }
.toggle:disabled { opacity: .6; cursor: wait; }
.toggle-knob {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--text-mute); transition: transform .18s ease, background .18s ease;
  display: flex; align-items: center; justify-content: center;
}
.toggle.on .toggle-knob { transform: translateX(22px); background: #1A130A; }

.status-pill {
  font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 700;
  padding: 3px 10px; border-radius: 20px; border: 1px solid var(--line);
}
.status-pill.on { color: var(--ok); border-color: rgba(95,168,115,0.4); background: rgba(95,168,115,0.10); }
.status-pill.off { color: var(--text-mute); }

.admin-tabs { display: flex; gap: 6px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.admin-tabs button {
  background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer;
  color: var(--text-dim); font-family: var(--font-ui); font-size: 14.5px; font-weight: 600;
  padding: 10px 14px; margin-bottom: -1px; transition: color .15s, border-color .15s;
}
.admin-tabs button:hover { color: var(--text); }
.admin-tabs button.active { color: var(--gold-bright); border-bottom-color: var(--gold); }
