/* =============================================================
 * TechPulse — estilos
 * ============================================================= */

:root {
  --bg: #0b1020;
  --bg-soft: #121a30;
  --surface: #16203a;
  --surface-2: #1c2745;
  --border: #263255;
  --text: #e8ecf6;
  --text-dim: #9aa6c4;
  --muted: #7683a6;
  --accent: #4f8cff;
  --accent-2: #7c5cff;
  --green: #22c98b;
  --red: #ff5d6c;
  --amber: #ffb020;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

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

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(124, 92, 255, 0.14), transparent 60%),
    radial-gradient(1000px 500px at -10% 0%, rgba(79, 140, 255, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

/* ---------------- Header ---------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--border);
  background: rgba(11, 16, 32, 0.7);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  font-size: 24px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px rgba(79, 140, 255, 0.35);
}
.brand-text h1 { font-size: 1.35rem; font-weight: 800; }
.brand-text p { color: var(--text-dim); font-size: 0.85rem; }

.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.source-badge {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 0.78rem; color: var(--text-dim);
  padding: 6px 11px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
}
.source-badge .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
}
.source-badge.live .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(34, 201, 139, 0.18); }
.source-badge.sample .dot { background: var(--amber); box-shadow: 0 0 0 3px rgba(255, 176, 32, 0.18); }
.source-badge.error { border-color: rgba(255, 93, 108, 0.4); color: #ff9aa4; }
.source-badge.error .dot { background: var(--red); box-shadow: 0 0 0 3px rgba(255, 93, 108, 0.18); }

/* ---------------- Buttons ---------------- */
.btn {
  font: inherit; font-weight: 600; font-size: 0.86rem;
  border-radius: 10px; padding: 9px 14px;
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer; transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #fff;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.girando { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Tabs ---------------- */
.tabs {
  display: flex; gap: 6px;
  padding: 12px clamp(16px, 4vw, 40px) 0;
  overflow-x: auto;
}
.tab {
  font: inherit; font-weight: 600; font-size: 0.9rem;
  color: var(--text-dim);
  background: transparent; border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px; cursor: pointer;
  white-space: nowrap; transition: all 0.15s ease;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------------- Layout ---------------- */
.content { padding: 22px clamp(16px, 4vw, 40px) 40px; }
.panel { display: none; animation: fade 0.25s ease; }
.panel.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 16px; flex-wrap: wrap;
}
.panel-head h2 { font-size: 1.3rem; }
.panel-head .muted { font-size: 0.9rem; margin-top: 2px; }

.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px;
}
.input {
  font: inherit; font-size: 0.88rem;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 12px; min-width: 0;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,140,255,0.15); }
.input::placeholder { color: var(--muted); }
#insight-busca, #noticia-busca { flex: 1 1 240px; }

/* ---------------- Grids ---------------- */
.grid { display: grid; gap: 16px; }
.grid-insights { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid-mercado { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* ---------------- Cards base ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex; flex-direction: column;
}

.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  font-size: 0.72rem; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-dim);
  white-space: nowrap;
}
.badge-tipo { color: #cdd7f5; }
.badge-prio-Alta { background: rgba(255, 93, 108, 0.14); color: #ff9aa4; border-color: rgba(255,93,108,0.3); }
.badge-prio-Média, .badge-prio-Media { background: rgba(255, 176, 32, 0.14); color: #ffce7a; border-color: rgba(255,176,32,0.3); }
.badge-on { background: rgba(34, 201, 139, 0.14); color: #7fe3bd; border-color: rgba(34,201,139,0.3); }
.badge-off { background: rgba(118, 131, 166, 0.16); color: #aeb8d6; }
.badge-admin { background: rgba(124, 92, 255, 0.16); color: #c3b4ff; border-color: rgba(124,92,255,0.35); }
.badge-lang { text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------------- Insight card ---------------- */
.insight { padding: 16px; gap: 12px; }
.insight-head { display: flex; gap: 12px; align-items: flex-start; }
.insight-head .insight-title { flex: 1; min-width: 0; }
.insight-thumb {
  flex: 0 0 auto;
  width: 104px; height: 72px;
  object-fit: contain;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.insight-title { font-size: 1.02rem; font-weight: 700; }
.insight-text {
  font-family: "Inter", sans-serif;
  font-size: 0.86rem; line-height: 1.55;
  color: var(--text-dim);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  white-space: pre-wrap;
  max-height: 220px; overflow-y: auto;
}
.insight-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.8rem; color: var(--muted); }
.insight-meta .var-up { color: var(--green); font-weight: 700; }
.insight-meta .var-down { color: var(--red); font-weight: 700; }
.insight-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 2px; }
.insight-actions .spacer { flex: 1; }
.status-select {
  font: inherit; font-size: 0.8rem; padding: 6px 8px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
}

/* ---------------- Notícia card ---------------- */

.noticia-img {
  width: 100%; height: 150px; object-fit: contain;
  background: var(--surface-2); display: block;
}
.noticia-img.placeholder {
  display: grid; place-items: center; font-size: 34px; color: var(--muted);
}
.noticia-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 9px; }
.noticia-title { font-size: 0.98rem; font-weight: 700; line-height: 1.35; }
.noticia-desc { font-size: 0.84rem; color: var(--text-dim); }
.noticia-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.link { color: var(--accent); text-decoration: none; font-weight: 600; }
.link:hover { text-decoration: underline; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { font-size: 0.72rem; color: var(--text-dim); background: var(--surface-2); border: 1px solid var(--border); padding: 2px 8px; border-radius: 6px; }

/* ---------------- Mercado card ---------------- */
.ativo { padding: 16px; gap: 10px; }
.ativo-top { display: flex; align-items: center; justify-content: space-between; }
.ativo-name { font-weight: 700; text-transform: capitalize; font-size: 1.02rem; }
.ativo-tik { font-size: 0.74rem; color: var(--muted); text-transform: uppercase; }
.ativo-price { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.ativo-brl { font-size: 0.86rem; color: var(--text-dim); }
.ativo-var { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; font-size: 0.92rem; padding: 4px 10px; border-radius: 999px; width: max-content; }
.var-up-bg { background: rgba(34,201,139,0.14); color: var(--green); }
.var-down-bg { background: rgba(255,93,108,0.14); color: var(--red); }
.var-flat-bg { background: var(--surface-2); color: var(--text-dim); }
.ativo-stats { display: flex; flex-direction: column; gap: 4px; font-size: 0.78rem; color: var(--muted); border-top: 1px solid var(--border); padding-top: 10px; }
.ativo-stats .row { display: flex; justify-content: space-between; }

/* ---------------- Config ---------------- */
.config-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; max-width: 720px; box-shadow: var(--shadow); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > span { font-size: 0.85rem; font-weight: 600; color: var(--text-dim); }
.field-row { display: flex; gap: 16px; flex-wrap: wrap; }
.field-row .field { flex: 1 1 200px; }
.toggle-line { display: flex; align-items: center; gap: 10px; }
.config-meta { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.read-value { font-size: 0.92rem; color: var(--text); background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 12px; min-height: 20px; }
.read-value .tags { gap: 6px; }
.config-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 0.85rem; margin-bottom: 18px; border: 1px solid var(--border); }
.notice-warn { background: rgba(255,176,32,0.1); border-color: rgba(255,176,32,0.3); color: #ffce7a; }
.notice-info { background: rgba(79,140,255,0.1); border-color: rgba(79,140,255,0.3); color: #a8c4ff; }

/* ---------------- States ---------------- */
.state { text-align: center; padding: 60px 20px; color: var(--muted); grid-column: 1 / -1; }
.state .emoji { font-size: 42px; display: block; margin-bottom: 12px; }
.skeleton { height: 210px; border-radius: var(--radius); background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------------- Footer ---------------- */
.app-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
  padding: 20px clamp(16px, 4vw, 40px);
  border-top: 1px solid var(--border);
  color: var(--text-dim); font-size: 0.82rem;
  margin-top: 20px;
}

/* ---------------- Modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 8, 18, 0.7); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(460px, 100%);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow);
}
.modal h3 { margin-bottom: 6px; }
.modal .sep { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.modal-actions .spacer { flex: 1; }

/* Erro inline de validação de campo */
.campo-erro { border-color: var(--red) !important; box-shadow: 0 0 0 3px rgba(255, 93, 108, 0.15) !important; }
.msg-erro-campo { display: block; color: var(--red); font-size: 0.76rem; margin-top: 5px; }

/* Chips de sugestão de termo */
.chip-suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.chip-suggest-label { font-size: 0.76rem; color: var(--muted); margin-right: 2px; }
.chip-s {
  font: inherit; font-size: 0.76rem; font-weight: 500;
  color: var(--text-dim); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 10px; cursor: pointer; transition: all 0.14s ease;
}
.chip-s:hover { border-color: var(--accent); color: var(--text); }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 18px; font-size: 0.88rem; font-weight: 500;
  box-shadow: var(--shadow); z-index: 60;
  animation: toastIn 0.2s ease;
}
.toast[hidden] { display: none; }
.toast.ok { border-color: rgba(34,201,139,0.5); }
.toast.err { border-color: rgba(255,93,108,0.5); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 560px) {
  .brand-text p { display: none; }
  .panel-head h2 { font-size: 1.15rem; }
}
