/* DarkFarm — tema escuro "sala de radar". */
:root {
  --bg: #0b0f0d;
  --bg-2: #111714;
  --panel: #151c18;
  --panel-2: #1b2420;
  --line: #26322c;
  --line-2: #344239;
  --text: #e4e9e2;
  --muted: #9aa79e;       /* 7:1 sobre --bg */
  --accent: #f2b33d;      /* âmbar de painel */
  --accent-ink: #1a1203;
  --signal: #6fd39a;      /* fósforo */
  --danger: #ff7a6b;
  --focus: #ffd27a;
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
.h2 { font-size: 1.05rem; margin-bottom: .75rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1:focus { outline: none; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 8px 12px; z-index: 50; border-radius: 6px; }
.skip:focus { left: 8px; }

/* ── marca + radar ── */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; font-size: .95rem; }
.brand-lg { font-size: 1.3rem; }
.radar {
  width: 26px; height: 26px; border-radius: 50%; flex: none; position: relative;
  border: 1.5px solid var(--accent);
  background:
    radial-gradient(circle, transparent 40%, rgba(242,179,61,.25) 41% 43%, transparent 44%),
    conic-gradient(from 0deg, rgba(242,179,61,.85), transparent 25%);
  animation: sweep 4s linear infinite;
}
.brand-lg .radar { width: 34px; height: 34px; }
@keyframes sweep { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .radar, .spinner { animation: none !important; } }

/* ── botões / campos ── */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: .6rem 1rem;
  border: 1px solid transparent; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  text-decoration: none; min-height: 40px;
}
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: #ffc457; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line-2); }
.btn-ghost:hover:not(:disabled) { background: var(--panel-2); }
.btn-danger { background: var(--danger); color: #2a0804; }
.btn-sm { padding: .35rem .7rem; min-height: 34px; font-size: .85rem; }
.btn-block { width: 100%; }

label, .label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; text-transform: uppercase; letter-spacing: .05em; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg-2); border: 1px solid var(--line-2);
  border-radius: 8px; padding: .55rem .7rem; width: 100%; min-height: 40px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; }
textarea { resize: vertical; line-height: 1.55; }
input[type=range] { padding: 0; accent-color: var(--accent); border: 0; background: none; }
input[type=checkbox] { width: auto; min-height: 0; accent-color: var(--accent); }
.form-error { color: var(--danger); margin: .5rem 0; min-height: 1em; }
.form-error:empty { margin: 0; min-height: 0; }

/* ── login ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 0%, #17211b, var(--bg) 70%); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; }
.login-card form { margin-top: 1.25rem; display: grid; gap: .25rem; }
.login-card input { margin-bottom: .75rem; }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .8rem; margin: 1.25rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
#google-btn { display: flex; justify-content: center; min-height: 44px; }

/* ── shell ── */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 1.5rem;
  padding: 20px 14px; background: var(--bg-2); border-right: 1px solid var(--line);
}
.nav { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 600;
}
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a[aria-current] { background: var(--panel-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.side-foot { margin-top: auto; display: grid; gap: .5rem; word-break: break-all; }
.main { padding: 28px clamp(16px, 3vw, 36px) 48px; min-width: 0; }
.main:focus { outline: none; }

.view-head { margin-bottom: 1.25rem; display: grid; gap: .25rem; }
.back { font-size: .9rem; text-decoration: none; width: fit-content; }

/* ── abas por tier ── */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 1rem; scrollbar-width: thin; }
.tabs [role=tab] {
  font: inherit; font-size: .88rem; font-weight: 600; white-space: nowrap; cursor: pointer;
  background: var(--panel); color: var(--muted); border: 1px solid var(--line); border-radius: 999px;
  padding: .4rem .85rem; display: inline-flex; gap: .45rem; align-items: center; min-height: 36px;
}
.tabs [role=tab]:hover { color: var(--text); }
.tabs [aria-selected=true] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.badge { font-family: var(--mono); font-size: .75rem; background: rgba(255,255,255,.07); padding: 0 .4rem; border-radius: 999px; }
.tabs [aria-selected=true] .badge { background: rgba(0,0,0,.15); }

/* ── filtros ── */
.filters {
  display: grid; grid-template-columns: minmax(200px, 2fr) minmax(150px, 1fr) minmax(150px, 1fr) auto;
  gap: 12px; align-items: end; margin-bottom: 1.25rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.filters label, .filters .label { margin-bottom: .3rem; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.multi { position: relative; }
.multi summary, .ranges summary {
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 8px; padding: .55rem .7rem; min-height: 40px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.multi summary::after, .ranges summary::after { content: " ▾"; color: var(--muted); }
.multi fieldset {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 100%; max-height: 280px; overflow: auto;
  margin: 0; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px;
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
}
.check { display: flex; align-items: center; gap: .5rem; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text); font-size: .9rem; padding: 4px; margin: 0; cursor: pointer; white-space: nowrap; }
.check .small { margin-left: auto; font-family: var(--mono); }
.ranges { grid-column: 1 / -1; }
.ranges summary { width: fit-content; }
.range-grid { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-top: 12px; }
.range-grid fieldset { border: 0; padding: 0; margin: 0; display: flex; align-items: center; gap: 6px; }
.range-grid legend { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .3rem; padding: 0; }
.range-grid input { width: 120px; }

/* ── grade de cards ── */
.count { margin: 0 0 .6rem; font-family: var(--mono); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; gap: 12px; min-width: 0;
}
.card:hover { border-color: var(--line-2); }
.card-head { display: flex; gap: 10px; align-items: flex-start; }
.thumb {
  width: 48px; height: 48px; border-radius: 50%; flex: none; overflow: hidden; position: relative;
  background: var(--panel-2); display: grid; place-items: center; font-weight: 700; color: var(--muted);
  border: 1px solid var(--line-2);
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card-title { flex: 1; min-width: 0; }
.card-title h3 { font-size: 1rem; overflow-wrap: anywhere; }
.card-title h3 a { color: var(--text); text-decoration: none; }
.card-title h3 a:hover { color: var(--accent); text-decoration: underline; }
.card-title p { margin: 2px 0 0; }
.card-actions { display: flex; gap: 2px; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; cursor: pointer;
  background: transparent; border: 1px solid transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.star[aria-pressed=true] { color: var(--accent); }
.star[aria-pressed=true] svg { fill: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 6px; margin: 0; }
.stats div { background: var(--bg-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; min-width: 0; }
.stats dt { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats dd { white-space: nowrap; margin: 0; font-family: var(--mono); font-size: .92rem; font-weight: 600; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; }
.tags:empty { display: none; }
.tag, .tier { font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--muted); }
.tier { color: var(--signal); border-color: rgba(111,211,154,.35); background: rgba(111,211,154,.08); }
.tier-exploding { color: #ff9a6b; border-color: rgba(255,154,107,.4); background: rgba(255,154,107,.1); }
.tier-rising_fast, .tier-high_traction { color: var(--accent); border-color: rgba(242,179,61,.4); background: rgba(242,179,61,.1); }
.tier-outlier { color: #b9a6ff; border-color: rgba(185,166,255,.4); background: rgba(185,166,255,.1); }

.card h4 { margin-bottom: -6px; text-transform: uppercase; letter-spacing: .05em; font-size: .7rem; }
.top-videos { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; counter-reset: v; }
.top-videos li { counter-increment: v; }
.top-videos a {
  display: grid; grid-template-columns: 1.4em 1fr; column-gap: 4px; padding: 5px 6px; border-radius: 6px;
  color: var(--text); text-decoration: none; font-size: .87rem;
}
.top-videos a::before { content: counter(v); grid-row: span 2; font-family: var(--mono); color: var(--muted); }
.top-videos a:hover { background: var(--panel-2); }
.top-videos a:hover .v-title { text-decoration: underline; }
.v-title { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.v-meta { font-size: .75rem; color: var(--muted); font-family: var(--mono); }

.more-wrap { display: flex; justify-content: center; padding: 20px 0; }

/* ── categorias ── */
.cat-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 12px; }
.cat {
  display: grid; gap: 6px; padding: 14px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line);
  color: var(--text); text-decoration: none; height: 100%;
}
.cat:hover { border-color: var(--accent); }
.cat-name { font-weight: 700; }
.cat-meta { font-size: .85rem; color: var(--muted); }
.cat-meta strong { color: var(--text); font-family: var(--mono); }
.bar { height: 4px; background: var(--bg-2); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--signal); }

/* ── narração ── */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; max-width: 860px; }
.tts { display: grid; gap: .5rem; }
.tts-row { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 12px; }
.tts-row output { font-family: var(--mono); color: var(--text); text-transform: none; }
.tts-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
#t-count { font-family: var(--mono); }
#t-count.warn { color: var(--accent); }
#t-result { display: grid; gap: 12px; justify-items: start; }
#t-result audio { width: 100%; }

/* ── estados ── */
.state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 48px 16px; color: var(--muted); text-align: center; border: 1px dashed var(--line-2); border-radius: var(--radius); }
.state p { margin: 0; }
.state-error { color: var(--danger); border-color: rgba(255,122,107,.4); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: sweep .8s linear infinite; }

/* ── diálogo + toast ── */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 14px;
  padding: 22px; width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0,0,0,.65); }
dialog h2 { font-size: 1.15rem; }
dialog p { color: var(--muted); overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 1rem; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 16px;
  transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── mobile: bottom bar ── */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 30; flex-direction: row;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); gap: 0;
  }
  .side > .brand { display: none; }
  .nav { grid-auto-flow: column; grid-auto-columns: 1fr; flex: 1; }
  .nav a { flex-direction: column; gap: 2px; font-size: .7rem; padding: 6px 2px; text-align: center; }
  .nav a[aria-current] { box-shadow: inset 0 2px 0 var(--accent); }
  .side-foot { margin: 0; display: flex; align-items: center; }
  .side-foot #user-email { display: none; }
  .side-foot .btn { font-size: .7rem; padding: 6px 8px; min-height: 44px; border: 0; color: var(--muted); }
  .main { padding: 20px 16px 96px; }
  .toast { bottom: 84px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .f-search { grid-column: 1 / -1; }
  .tts-row { grid-template-columns: 1fr; }
  h1 { font-size: 1.35rem; }
}
@media (max-width: 420px) {
  .filters { grid-template-columns: 1fr; }
  .range-grid fieldset { width: 100%; }
  .range-grid input { width: auto; flex: 1; min-width: 0; }
}
