/* ── Variables ── */
:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #151d2e;
  --bg-card-hover: #1a2438;
  --border: #1e2d45;
  --border-accent: #2a3f5f;
  --text-primary: #e8edf5;
  --text-secondary: #8b9cb8;
  --text-muted: #5a6d8a;
  --green: #00d084;
  --green-dim: rgba(0, 208, 132, 0.15);
  --red: #ff4757;
  --red-dim: rgba(255, 71, 87, 0.15);
  --yellow: #ffc107;
  --yellow-dim: rgba(255, 193, 7, 0.12);
  --blue: #3b82f6;
  --accent: #f59e0b;
  --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --sidebar-width: 320px;
  --header-height: 64px;
  --radius: 6px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
}

.hidden {
  display: none !important;
}

/* ── Simulation Banner ── */
.simulation-banner {
  background: var(--yellow-dim);
  border-bottom: 1px solid var(--yellow);
  color: var(--yellow);
  text-align: center;
  padding: 8px 16px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header__brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.header__logo {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--green);
  letter-spacing: 0.06em;
}

.header__byline {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.header__subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.header__meta {
  display: flex;
  align-items: center;
  gap: 32px;
}

.header__dolar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
}

.header__dolar .label {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
}

.header__dolar .value {
  font-size: 1.1rem;
  font-weight: 600;
}

.header__clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: var(--font-mono);
}

.clock {
  font-size: 1rem;
  font-weight: 500;
}

.last-update {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ── Status Badge ── */
.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid var(--border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

.status-badge--loading {
  background: rgba(59, 130, 246, 0.1);
  color: var(--blue);
  border-color: rgba(59, 130, 246, 0.3);
}
.status-badge--loading .status-dot { background: var(--blue); }

.status-badge--connected {
  background: var(--green-dim);
  color: var(--green);
  border-color: rgba(0, 208, 132, 0.3);
}
.status-badge--connected .status-dot { background: var(--green); animation: none; }

.status-badge--simulation {
  background: var(--yellow-dim);
  color: var(--yellow);
  border-color: rgba(255, 193, 7, 0.3);
}
.status-badge--simulation .status-dot { background: var(--yellow); }

.status-badge--error {
  background: var(--red-dim);
  color: var(--red);
  border-color: rgba(255, 71, 87, 0.3);
}
.status-badge--error .status-dot { background: var(--red); animation: none; }

.status-badge--offline {
  background: rgba(90, 109, 138, 0.15);
  color: var(--text-muted);
}
.status-badge--offline .status-dot { background: var(--text-muted); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Layout ── */
.layout {
  display: flex;
  align-items: flex-start;
}

.main {
  flex: 1;
  padding: 20px 24px 40px;
  min-width: 0;
}

/* ── Cards Grid ── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
  align-items: start;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s, background 0.2s;
  height: auto;
}

.card:hover {
  border-color: var(--border-accent);
  background: var(--bg-card-hover);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 0;
}

.card__title {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.card__symbol {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-primary);
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.card__body {
  padding: 12px 16px 14px;
}

.card__metric--primary {
  margin-bottom: 10px;
}

.card__metric--primary .metric-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.card__row {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
}

.card__metric {
  flex: 1;
}

.metric-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.metric-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.metric-value--sm {
  font-size: 0.95rem;
}

.variation-cell {
  display: flex;
  align-items: center;
  gap: 4px;
}

.variation-cell.up { color: var(--green); }
.variation-cell.down { color: var(--red); }
.variation-cell.neutral { color: var(--text-secondary); }

.sparkline-wrap {
  position: relative;
  height: 48px;
  width: 100%;
  margin-top: 8px;
  overflow: hidden;
}

.sparkline {
  display: block;
  width: 100% !important;
  height: 48px !important;
  max-height: 48px;
}

/* ── Charts Section ── */
.charts-section {
  margin-top: 8px;
}

.section-title {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  align-items: start;
}

.chart-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.chart-wrap {
  position: relative;
  height: 200px;
  width: 100%;
  overflow: hidden;
}

.chart-panel canvas {
  display: block;
  width: 100% !important;
  height: 200px !important;
  max-height: 200px;
}

.chart-panel__title {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  letter-spacing: 0.06em;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  padding: 24px;
  flex-shrink: 0;
  overflow-y: auto;
  transition: transform 0.3s ease;
  position: sticky;
  top: var(--header-height);
  max-height: calc(100vh - var(--header-height));
  align-self: flex-start;
}

.sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.sidebar__header h3 {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.sidebar__toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.sidebar__toggle:hover {
  color: var(--text-primary);
}

.config-form fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.config-form legend {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 8px;
}

.config-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.config-form label:last-child {
  margin-bottom: 0;
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 10px !important;
  font-size: 0.8rem !important;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin: 4px 0 12px;
}

.config-form input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.config-form input {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.2s;
}

.config-form input:focus {
  border-color: var(--accent);
}

.config-actions {
  display: flex;
  gap: 12px;
}

.btn {
  flex: 1;
  padding: 10px 16px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.2s, border-color 0.2s;
}

.btn--primary {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
}

.btn--primary:hover {
  background: #d97706;
}

.btn--secondary {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn--secondary:hover {
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.sidebar__info {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.sidebar__provider {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.sidebar__provider span {
  color: var(--text-secondary);
}

/* ── FAB ── */
.fab {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 200;
  transition: transform 0.2s;
}

.fab:hover {
  transform: scale(1.08);
}

/* ── Footer ── */
.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer__brand {
  color: var(--green);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.footer__sep {
  opacity: 0.4;
}

/* ── Variation colors in header ── */
.up { color: var(--green); }
.down { color: var(--red); }

/* ── Responsive ── */
@media (max-width: 1200px) {
  .cards-grid,
  .charts-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .cards-grid,
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .header__meta {
    gap: 16px;
  }

  .header__subtitle {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    z-index: 150;
    transform: translateX(100%);
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .fab {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .main {
    padding: 16px;
  }

  .card__metric--primary .metric-value {
    font-size: 1.6rem;
  }
}

@media (max-width: 600px) {
  .header {
    flex-direction: column;
    height: auto;
    padding: 12px 16px;
    gap: 12px;
  }

  .header__meta {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }
}
