@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&display=swap');

:root {
  --bg: #020617;
  --bg-elevated: #0f172a;
  --card: #0b1220;
  --card-hover: #16213a;
  --border: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #22c55e;
  --accent-soft: rgba(34, 197, 94, 0.14);
  --accent-glow: rgba(34, 197, 94, 0.35);
  --up: #22c55e;
  --up-soft: rgba(34, 197, 94, 0.12);
  --down: #ef4444;
  --down-soft: rgba(239, 68, 68, 0.12);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.12);
  --blue: #3b82f6;
  --blue-soft: rgba(59, 130, 246, 0.12);
  --radius-sm: 10px;
  --radius: 18px;
  --radius-lg: 26px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 15% 0%, #0c1a2e 0%, var(--bg) 45%);
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a, button, [role="button"], input[type="submit"], .nav-link, thead th[data-sort] {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  vertical-align: -4px;
}
.btn .icon { width: 18px; height: 18px; vertical-align: -3px; margin-right: 2px; }
.nav-link .icon { width: 18px; height: 18px; vertical-align: -4px; }
.badge .icon { width: 14px; height: 14px; vertical-align: -2px; }
.alert-item .icon { width: 16px; height: 16px; vertical-align: -3px; }

h1, h2, h3, h4, .brand, .num {
  font-family: 'IBM Plex Sans', sans-serif;
}

a { color: inherit; text-decoration: none; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-size: 1.3rem;
  font-weight: 700;
  padding: 0 10px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent-glow);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--card-hover); color: var(--text); }
.nav-link.active {
  background: var(--accent-soft);
  color: #4ade80;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.logout-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.85rem;
}
.logout-btn:hover { border-color: var(--accent); color: var(--text); }

/* Main content */
.main {
  flex: 1;
  padding: 32px 40px 60px;
  max-width: 1400px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 { font-size: 1.6rem; margin: 0 0 4px; }
.page-header p { margin: 0; color: var(--text-muted); font-size: 0.92rem; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
}

.grid {
  display: grid;
  gap: 18px;
}
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 2fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .grid-4 { grid-template-columns: 1fr; }
}

.stat-card { display: flex; flex-direction: column; gap: 8px; }
.stat-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-value { font-size: 1.7rem; font-weight: 700; }
.stat-sub { font-size: 0.85rem; font-weight: 500; }

.up { color: var(--up); }
.down { color: var(--down); }
.warn { color: var(--warn); }
.neutral { color: var(--text-muted); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.pill-up { background: var(--up-soft); color: var(--up); }
.pill-down { background: var(--down-soft); color: var(--down); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-neutral { background: rgba(148, 148, 163, 0.12); color: var(--text-muted); }
.pill-blue { background: var(--blue-soft); color: var(--blue); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #15803d);
  color: #052e16;
  box-shadow: 0 6px 20px var(--accent-glow);
}
.btn-primary:hover { box-shadow: 0 8px 26px var(--accent-glow); }
.btn-secondary {
  background: var(--card-hover);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 13px 16px; text-align: left; white-space: nowrap; }
thead th {
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
}
tbody tr { border-top: 1px solid var(--border); transition: background 0.12s; }
tbody tr:hover { background: var(--card-hover); }
.ticker-cell { font-family: 'IBM Plex Sans', sans-serif; font-weight: 600; }

/* Forms */
.field { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
label { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }
input, select, textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.92rem;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* Login */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  box-shadow: var(--shadow);
}
.login-card .brand { justify-content: center; padding-bottom: 30px; font-size: 1.5rem; }
.error-msg {
  background: var(--down-soft);
  color: var(--down);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
}

/* Badges por sinal */
.badge-compra { background: var(--up-soft); color: var(--up); }
.badge-atencao { background: var(--down-soft); color: var(--down); }
.badge-manter, .badge-neutro { background: var(--warn-soft); color: var(--warn); }
.badge-dados_insuficientes { background: rgba(148,148,163,0.12); color: var(--text-muted); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}

/* Analysis markdown */
.markdown-body { line-height: 1.7; font-size: 0.95rem; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { font-family: 'IBM Plex Sans', sans-serif; margin-top: 1.4em; }
.markdown-body ul { padding-left: 1.2em; }
.markdown-body code { background: var(--bg-elevated); padding: 2px 6px; border-radius: 6px; }

.disclaimer {
  margin-top: 20px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.78rem;
  line-height: 1.5;
}

.progress-track {
  width: 100%;
  height: 14px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #ff5f8f);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state h3 { color: var(--text); margin-bottom: 8px; }

.topbar-mobile { display: none; }
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar { position: relative; height: auto; width: 100%; flex-direction: row; overflow-x: auto; padding: 14px; }
  .sidebar-footer { display: none; }
  .brand { display: none; }
  .main { padding: 20px; }
}

.section-title { font-size: 1.05rem; font-weight: 600; margin: 0 0 16px; font-family: 'IBM Plex Sans', sans-serif; }

.alert-item {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  margin-bottom: 10px;
  align-items: flex-start;
}
.alert-item.unread { border-left: 3px solid var(--accent); }
.alert-time { font-size: 0.75rem; color: var(--text-dim); }

.bell-badge {
  background: var(--accent);
  color: white;
  border-radius: 999px;
  font-size: 0.65rem;
  padding: 1px 6px;
  margin-left: auto;
}

.mapping-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: center; }

.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-gap { display: flex; gap: 10px; align-items: center; }
.muted { color: var(--text-muted); }
.small { font-size: 0.82rem; }
