/* =====================================================
   style.css — Dashboard Admin BCV Hablador Digital
   Dark Mode Premium + Light Mode + Mobile-First
   ===================================================== */

/* ---- GOOGLE FONTS ---- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&family=Outfit:wght@400;500;600;700;800&display=swap');

/* ---- CSS VARIABLES — Modo Oscuro (Obsidiana Noche & Oro BCV) ---- */
:root,
[data-theme="dark"] {
  --font-display:    'Outfit', 'Inter', -apple-system, sans-serif;
  --font-body:       'Inter', -apple-system, sans-serif;
  --font-mono:       'JetBrains Mono', monospace;

  --bg-primary:      #080B11;
  --bg-secondary:    #0F1522;
  --bg-card:         #141C2E;
  --bg-card-hover:   #1B263E;
  --border:          rgba(255, 255, 255, 0.08);
  --border-light:    rgba(255, 255, 255, 0.05);
  --navbar-bg:       rgba(8, 11, 17, 0.94);

  --accent-emerald:  #059669;
  --accent-emerald-glow: rgba(5, 150, 105, 0.25);
  --accent-blue:     #2563EB;
  --accent-blue-glow:rgba(37, 99, 235, 0.25);
  --accent-green:    #10B981;
  --accent-green-glow: rgba(16, 185, 129, 0.22);
  --accent-yellow:   #D97706;
  --accent-yellow-light: #F59E0B;
  --accent-red:      #DC2626;
  --accent-red-glow: rgba(220, 38, 38, 0.2);
  --accent-orange:   #EA580C;
  --accent-purple:   #9333EA;

  --text-primary:    #F8FAFC;
  --text-secondary:  #94A3B8;
  --text-muted:      #64748B;
  --text-link:       #38BDF8;

  --gold:            #F59E0B;
  --gold-dark:       #B45309;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 14px rgba(0,0,0,0.5);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.6);
  --shadow-xl:  0 16px 48px rgba(0,0,0,0.7);

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  20px;

  --transition-fast:   0.15s cubic-bezier(0.23, 1, 0.32, 1);
  --transition-normal: 0.25s cubic-bezier(0.23, 1, 0.32, 1);
  --transition-slow:   0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

/* ---- CSS VARIABLES — Modo Claro (Marfil Fiduciario & Oro/Azul) ---- */
[data-theme="light"] {
  --font-display:    'Outfit', 'Inter', -apple-system, sans-serif;
  --font-body:       'Inter', -apple-system, sans-serif;
  --font-mono:       'JetBrains Mono', monospace;

  --bg-primary:      #F8FAFC;
  --bg-secondary:    #FFFFFF;
  --bg-card:         #FFFFFF;
  --bg-card-hover:   #F1F5F9;
  --border:          #E2E8F0;
  --border-light:    #F1F5F9;
  --navbar-bg:       rgba(255, 255, 255, 0.95);

  --accent-emerald:  #047857;
  --accent-emerald-glow: rgba(4, 120, 87, 0.15);
  --accent-blue:     #1D4ED8;
  --accent-blue-glow:rgba(29, 78, 216, 0.15);
  --accent-green:    #059669;
  --accent-green-glow: rgba(5, 150, 105, 0.15);
  --accent-yellow:   #B45309;
  --accent-yellow-light: #D97706;
  --accent-red:      #B91C1C;
  --accent-red-glow: rgba(185, 28, 28, 0.15);
  --accent-orange:   #C2410C;
  --accent-purple:   #6B21A8;

  --text-primary:    #0F172A;
  --text-secondary:  #475569;
  --text-muted:      #64748B;
  --text-link:       #1D4ED8;

  --gold:            #D97706;
  --gold-dark:       #92400E;

  --shadow-sm:  0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md:  0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg:  0 8px 24px rgba(15, 23, 42, 0.1);
  --shadow-xl:  0 16px 48px rgba(15, 23, 42, 0.12);
}

/* ---- MEJORAS DE RELIEVE Y TEXTURA PARA MODO CLARO ---- */
[data-theme="light"] body {
  background-color: #F1F5F9;
  background-image: 
    radial-gradient(at 0% 0%, rgba(217, 119, 6, 0.06) 0px, transparent 40%),
    radial-gradient(at 100% 0%, rgba(29, 78, 216, 0.06) 0px, transparent 40%),
    radial-gradient(at 50% 100%, rgba(4, 120, 87, 0.05) 0px, transparent 50%);
  background-attachment: fixed;
}

[data-theme="light"] .card,
[data-theme="light"] .scrape-status-card,
[data-theme="light"] .chart-card {
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  box-shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.05), 0 2px 4px -2px rgba(15, 23, 42, 0.03);
}

[data-theme="light"] .card-header {
  background: linear-gradient(180deg, #F8FAFC 0%, #F1F5F9 100%);
  border-bottom: 1px solid #CBD5E1;
}

[data-theme="light"] .stat-card {
  border: 1px solid #CBD5E1;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.05);
}

[data-theme="light"] .stat-card.gold {
  background: linear-gradient(180deg, #FFFBEB 0%, #FFFFFF 70%);
  border-color: #FCD34D;
}

[data-theme="light"] .stat-card.cyan {
  background: linear-gradient(180deg, #F0F9FF 0%, #FFFFFF 70%);
  border-color: #7DD3FC;
}

[data-theme="light"] .stat-card.blue {
  background: linear-gradient(180deg, #EFF6FF 0%, #FFFFFF 70%);
  border-color: #93C5FD;
}

[data-theme="light"] .stat-card.green {
  background: linear-gradient(180deg, #ECFDF5 0%, #FFFFFF 70%);
  border-color: #6EE7B7;
}

[data-theme="light"] .btn-secondary {
  background: linear-gradient(180deg, #FFFFFF 0%, #F1F5F9 100%);
  border-color: #CBD5E1;
  color: #0F172A;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

[data-theme="light"] .btn-secondary:hover:not(:disabled) {
  background: #E2E8F0;
  border-color: #94A3B8;
}

[data-theme="light"] .search-bar,
[data-theme="light"] .form-input,
[data-theme="light"] .form-select {
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05);
}

[data-theme="light"] .devices-table th {
  background: #F1F5F9;
  color: #334155;
  border-bottom: 2px solid #CBD5E1;
}

[data-theme="light"] .devices-table tr:hover {
  background: #F8FAFC;
}

/* Bordes y relieve de alto contraste para las cajas de tasa del Monitor BCV en Modo Claro */
[data-theme="light"] .scrape-rate-box.usd {
  background: linear-gradient(180deg, #FFFBEB 0%, #FFFFFF 100%);
  border: 1px solid #FCD34D !important;
  border-top: 3px solid #D97706 !important;
  box-shadow: 0 3px 8px rgba(217, 119, 6, 0.1);
}

[data-theme="light"] .scrape-rate-box.eur {
  background: linear-gradient(180deg, #F0F9FF 0%, #FFFFFF 100%);
  border: 1px solid #7DD3FC !important;
  border-top: 3px solid #0284C7 !important;
  box-shadow: 0 3px 8px rgba(2, 132, 199, 0.1);
}

/* ---- RESET Y BASE ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  background-color: var(--bg-primary);
  width: 100%;
  height: 100%;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow-x: auto;
  -webkit-font-smoothing: antialiased;
  /* Transición suave al cambiar de tema */
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Helper de Accesibilidad para Screen Readers */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Focus visible de accesibilidad */
:focus-visible {
  outline: 2px solid var(--accent-blue) !important;
  outline-offset: 2px !important;
}

/* =====================================================
   NAVBAR / HEADER
   ===================================================== */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
  box-sizing: border-box;
  background: var(--navbar-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 0 16px var(--accent-blue-glow);
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.brand-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
  display: block;
  margin-top: -2px;
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Indicador de estado del scraper en navbar */
.scraper-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 6px 14px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.scraper-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.scraper-dot.online  { background: var(--accent-green); animation: pulse-green 2s infinite; }
.scraper-dot.warning { background: var(--accent-yellow); animation: pulse-yellow 2s infinite; }
.scraper-dot.error   { background: var(--accent-red); animation: pulse-red 2s infinite; }

/* =====================================================
   BOTONES
   ===================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-blue);
  color: white;
  border-color: var(--accent-blue);
}
.btn-primary:hover:not(:disabled) {
  background: #388bfd;
  box-shadow: 0 0 16px var(--accent-blue-glow);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.btn-danger {
  background: transparent;
  color: var(--accent-red);
  border-color: var(--accent-red);
}
.btn-danger:hover:not(:disabled) {
  background: var(--accent-red-glow);
}

.btn-success {
  background: var(--accent-green);
  color: #0D1117;
  font-weight: 600;
}
.btn-success:hover:not(:disabled) {
  background: #46d55e;
  box-shadow: 0 0 16px var(--accent-green-glow);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.78rem;
}

.btn-icon {
  padding: 8px;
  width: 36px;
  height: 36px;
  justify-content: center;
}

.btn.loading .btn-text { display: none; }
.btn.loading::after {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* =====================================================
   LAYOUT PRINCIPAL
   ===================================================== */
.main-content {
  width: 100%;
  max-width: 100%;
  padding: 24px 32px;
  box-sizing: border-box;
}

/* =====================================================
   STATS BAR — Tarjetas auto-fluidadas
   ===================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
  width: 100%;
  box-sizing: border-box;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  cursor: default;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--card-accent, var(--accent-blue)), transparent);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.stat-card.gold   { --card-accent: var(--gold); }
.stat-card.blue   { --card-accent: var(--accent-blue); }
.stat-card.green  { --card-accent: var(--accent-green); }
.stat-card.purple { --card-accent: var(--accent-purple); }

.stat-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  letter-spacing: 0.04em;
  background: var(--accent-emerald-glow);
  color: var(--accent-emerald);
  border: 1px solid rgba(5, 150, 105, 0.3);
}

.stat-badge.info {
  background: var(--accent-blue-glow);
  color: var(--accent-blue);
  border-color: rgba(37, 99, 235, 0.3);
}

.stat-badge.success {
  background: var(--accent-green-glow);
  color: var(--accent-green);
  border-color: rgba(16, 185, 129, 0.3);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.stat-card.gold .stat-value { color: var(--gold); }
.stat-card.blue .stat-value { color: var(--accent-blue); }
.stat-card.green .stat-value { color: var(--accent-green); }
.stat-card.purple .stat-value { color: var(--accent-purple); }

.stat-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}
.stat-delta.up   { color: var(--accent-green); background: var(--accent-green-glow); }
.stat-delta.down { color: var(--accent-red); background: var(--accent-red-glow); }

/* Skeleton loader */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s infinite;
  border-radius: 4px;
  color: transparent !important;
  user-select: none;
  min-height: 1em;
}

/* =====================================================
   PANEL PRINCIPAL: 2 COLUMNAS
   ===================================================== */
.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 65fr) minmax(0, 35fr);
  gap: 20px;
  align-items: start;
  width: 100%;
  box-sizing: border-box;
}

/* =====================================================
   CARDS GENÉRICAS
   ===================================================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body {
  padding: 20px;
}

/* =====================================================
   TABLA DE DISPOSITIVOS
   ===================================================== */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  flex: 1;
  max-width: 280px;
}

.search-bar input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  width: 100%;
}

.search-bar input::placeholder { color: var(--text-muted); }
.search-icon { color: var(--text-muted); font-size: 14px; }

.devices-table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.devices-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.devices-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.devices-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
  vertical-align: middle;
}

.devices-table tr:last-child td { border-bottom: none; }

.devices-table tbody tr {
  transition: background var(--transition-fast);
}
.devices-table tbody tr:hover td {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* Celda de nombre del negocio */
.device-name-cell strong {
  display: block;
  color: var(--text-primary);
  font-weight: 500;
  font-size: 0.875rem;
}
.device-name-cell span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Celda MAC */
.mac-badge {
  font-family: 'Courier New', monospace;
  font-size: 0.78rem;
  color: var(--text-link);
  background: rgba(88, 166, 255, 0.08);
  padding: 2px 8px;
  border-radius: 4px;
}

/* Celda de estado */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 99px;
  white-space: nowrap;
}
.status-badge.online  { color: var(--accent-green); background: var(--accent-green-glow); }
.status-badge.idle    { color: var(--accent-yellow); background: rgba(210, 153, 34, 0.15); }
.status-badge.offline { color: var(--text-muted); background: rgba(72, 79, 88, 0.3); }

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.online  { background: var(--accent-green); animation: pulse-green 2s infinite; }
.status-dot.idle    { background: var(--accent-yellow); }
.status-dot.offline { background: var(--text-muted); }

/* Celda de última conexión */
.last-seen-cell {
  font-size: 0.78rem;
  white-space: nowrap;
}

/* Botones de acción en tabla */
.action-cell {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Paginación */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border-light);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.page-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: all var(--transition-fast);
}
.page-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.page-btn.active { background: var(--accent-blue); border-color: var(--accent-blue); color: white; }

/* Estado vacío */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 12px; display: block; }
.empty-state p { font-size: 0.875rem; }

/* =====================================================
   PANEL DERECHO: SCRAPING MONITOR
   ===================================================== */
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Card de estado del scraper */
.scrape-status-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.scrape-rate-display {
  text-align: center;
  padding: 16px 0 12px;
}

.scrape-rate-display-dual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 14px 0 10px;
}

.scrape-rate-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  text-align: center;
  transition: transform var(--transition-fast);
}
.scrape-rate-box:hover {
  transform: translateY(-2px);
}

.scrape-rate-box.usd {
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-top: 3px solid var(--gold);
}
.scrape-rate-box.usd .scrape-rate-value {
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 215, 0, 0.25);
}

.scrape-rate-box.eur {
  border: 1px solid rgba(0, 210, 255, 0.35);
  border-top: 3px solid #00D2FF;
}
.scrape-rate-box.eur .scrape-rate-value {
  color: #00D2FF;
  text-shadow: 0 0 12px rgba(0, 210, 255, 0.25);
}

.scrape-rate-amount {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  margin-top: 4px;
}

.scrape-rate-box .scrape-rate-value {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.scrape-rate-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.scrape-rate-value {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: -0.02em;
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

.scrape-rate-unit {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Selector de periodo de gráfico (1D, 7D, 1M, 1Y) */
.chart-period-selector {
  display: inline-flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.period-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.period-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}
.period-btn.active {
  background: var(--accent-blue);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.scrape-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.scrape-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
}

.scrape-meta-row .label { color: var(--text-muted); }
.scrape-meta-row .value { color: var(--text-secondary); font-weight: 500; }
.scrape-meta-row .value.ok { color: var(--accent-green); }
.scrape-meta-row .value.error { color: var(--accent-red); }

/* Gráfico de historial */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.chart-container {
  padding: 16px;
  position: relative;
  height: 200px;
}

/* Log de scraping */
.scrape-log {
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.log-entry {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.77rem;
}

.log-entry:last-child { border-bottom: none; }

.log-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  flex-shrink: 0;
  margin-top: 1px;
}
.log-icon.success { background: var(--accent-green-glow); color: var(--accent-green); }
.log-icon.error   { background: var(--accent-red-glow); color: var(--accent-red); }

.log-content { flex: 1; }
.log-rate    { font-weight: 600; color: var(--text-primary); }
.log-source  { color: var(--text-muted); font-size: 0.7rem; }
.log-time    { color: var(--text-muted); font-size: 0.7rem; white-space: nowrap; margin-left: auto; }

/* =====================================================
   MODAL DE EDICIÓN
   ===================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  transform: translateY(20px) scale(0.97);
  transition: transform var(--transition-normal);
}

.modal-overlay.active .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all var(--transition-fast);
}
.modal-close:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Formulario del modal */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group.full-width { grid-column: 1 / -1; }

.form-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

.form-input,
.form-select,
.form-textarea {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  width: 100%;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-glow);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
}

.form-select option {
  background: var(--bg-card);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.mac-display {
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  color: var(--text-link);
  background: rgba(88, 166, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  margin-bottom: 16px;
}

/* =====================================================
   TOAST NOTIFICATIONS
   ===================================================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow-xl);
  font-size: 0.875rem;
  font-weight: 500;
  min-width: 260px;
  max-width: 380px;
  pointer-events: all;
  animation: toast-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast.hiding {
  animation: toast-out 0.25s ease forwards;
}

.toast-icon { font-size: 18px; flex-shrink: 0; }

.toast.success { border-color: rgba(63, 185, 80, 0.4); }
.toast.success .toast-icon { color: var(--accent-green); }

.toast.error { border-color: rgba(218, 54, 51, 0.4); }
.toast.error .toast-icon { color: var(--accent-red); }

.toast.info { border-color: rgba(31, 111, 235, 0.4); }
.toast.info .toast-icon { color: var(--accent-blue); }

.toast.warning { border-color: rgba(210, 153, 34, 0.4); }
.toast.warning .toast-icon { color: var(--accent-yellow); }

/* =====================================================
   INDICADOR DE REFRESH EN NAVBAR
   ===================================================== */
.refresh-btn {
  position: relative;
}

.refresh-btn.spinning svg {
  animation: spin 0.8s linear infinite;
}

/* =====================================================
   ANIMACIONES KEYFRAMES
   ===================================================== */
@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 0 rgba(63, 185, 80, 0.4); }
  50%       { box-shadow: 0 0 0 5px rgba(63, 185, 80, 0); }
}

@keyframes pulse-yellow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(210, 153, 34, 0.4); }
  50%       { box-shadow: 0 0 0 5px rgba(210, 153, 34, 0); }
}

@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(218, 54, 51, 0.4); }
  50%       { box-shadow: 0 0 0 5px rgba(218, 54, 51, 0); }
}

@keyframes skeleton-pulse {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

@keyframes toast-out {
  from { transform: translateX(0); opacity: 1; }
  to   { transform: translateX(100%); opacity: 0; }
}

@keyframes count-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =====================================================
   MISCELÁNEA
   ===================================================== */

/* Divider */
.divider {
  height: 1px;
  background: var(--border-light);
  margin: 12px 0;
}

/* Badge genérico */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 600;
}

/* Icono de pantalla (screen size) */
.screen-badge {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Uptime formateado */
.uptime-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Scrollbar personalizado */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* =====================================================
   TEMA — TOGGLE BUTTON
   ===================================================== */
.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.theme-toggle:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--accent-blue);
  transform: rotate(20deg);
}
/* Icono sol en modo oscuro, luna en modo claro */
.theme-toggle .icon-dark { display: inline; }
.theme-toggle .icon-light { display: none; }
[data-theme="light"] .theme-toggle .icon-dark { display: none; }
[data-theme="light"] .theme-toggle .icon-light { display: inline; }

/* Transición para tarjetas y elementos al cambiar tema */
.stat-card, .card, .chart-card, .scrape-status-card,
.modal, .scraper-indicator, .btn, input, select, textarea {
  transition: background-color 0.3s ease, border-color 0.3s ease,
              color 0.3s ease, box-shadow 0.3s ease;
}

/* =====================================================
   DISPOSITIVOS EN TARJETA (móvil) — reemplaza tabla
   ===================================================== */
.device-card-mobile {
  display: none; /* se activa en móvil */
  flex-direction: column;
  gap: 12px;
  padding: 16px;
}
.device-card-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: box-shadow var(--transition-fast);
}
.device-card-item:active { box-shadow: var(--shadow-md); }
.device-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.device-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}
.device-card-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.device-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  word-break: break-all;
}
.device-card-meta .mac-badge { font-size: 0.72rem; }
.device-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}
.device-card-actions .btn { flex: 1; justify-content: center; }

/* =====================================================
   RESPONSIVE — PANTALLAS MEDIANAS Y MÓVILES (≤ 768px)
   ===================================================== */
@media (max-width: 768px) {
  /* Prevenir desbordamiento del body en móviles */
  html, body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
  }

  /* 1. NAVBAR MÓVIL SLIM Y ELEGANTE */
  .navbar {
    padding: 0 10px;
    height: 56px;
    gap: 6px;
  }
  .brand-subtitle { display: none !important; }
  .brand-name {
    font-size: 0.95rem;
    font-weight: 700;
    white-space: nowrap;
  }
  .brand-icon {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .navbar-actions {
    gap: 6px;
  }

  /* Ocultar textos secundarios en botones de la navbar */
  .scraper-indicator span:last-child { display: none !important; }
  .scraper-indicator { padding: 4px 8px; font-size: 0.72rem; }

  #btn-currency-converter .btn-text,
  #btn-preview-esp32 .btn-text,
  #btn-force-scrape .btn-text {
    display: none !important;
  }

  #btn-currency-converter::before { content: '🧮'; }
  #btn-preview-esp32::before { content: '📺'; }

  .theme-toggle,
  #btn-open-settings,
  #btn-logout,
  #btn-force-scrape,
  #btn-currency-converter,
  #btn-preview-esp32 {
    min-width: 38px !important;
    min-height: 38px !important;
    padding: 6px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem !important;
  }

  /* 2. CONTENEDOR Y TARJETAS SUPERIORES EN 2x2 */
  .main-content {
    padding: 12px 10px !important;
    width: 100% !important;
    box-sizing: border-box;
  }

  .stats-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    margin-bottom: 16px !important;
  }

  .stat-card {
    padding: 12px !important;
  }
  .stat-label {
    font-size: 0.65rem !important;
    margin-bottom: 6px !important;
  }
  .stat-value {
    font-size: 1.35rem !important;
    margin-bottom: 4px !important;
  }
  .stat-sub {
    font-size: 0.7rem !important;
  }

  /* 3. PANEL PRINCIPAL EN 1 COLUMNA */
  .panel-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .right-panel {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }

  /* 4. SECCIÓN DE DISPOSITIVOS: OCULTAR TABLA Y MOSTRAR TARJETAS MÓVILES */
  .devices-table-wrapper {
    display: none !important;
  }

  .device-card-mobile {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    padding: 12px !important;
  }

  .device-card-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .card-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    padding: 12px !important;
  }

  .card-header > div {
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
  }

  #branch-filter {
    max-width: 100% !important;
    width: 100% !important;
  }

  .search-bar {
    max-width: 100% !important;
    width: 100% !important;
  }

  #btn-add-device {
    width: 100% !important;
    justify-content: center !important;
  }

  /* 5. PREVENCIÓN DE AUTO-ZOOM EN iOS */
  .form-input,
  .search-bar input,
  .converter-input,
  select.form-select {
    font-size: 16px !important;
  }

  /* 6. CONVERSOR POPOVER CENTRADO ABAJO DE NAVBAR EN MÓVIL */
  .converter-popover {
    position: fixed !important;
    top: 64px !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translateX(-50%) !important;
    width: 92% !important;
    max-width: 340px !important;
    max-height: calc(100vh - 80px) !important;
    overflow-y: auto !important;
    z-index: 9999 !important;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.85) !important;
    border-radius: var(--radius-xl) !important;
  }

  /* 7. PESTAÑAS Y MODAL */
  .settings-tabs {
    display: flex !important;
    overflow-x: auto !important;
    white-space: nowrap !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    gap: 6px;
    scrollbar-width: thin;
  }
  .settings-tabs::-webkit-scrollbar { height: 3px; }
  .settings-tabs::-webkit-scrollbar-track { background: transparent; }
  .settings-tabs::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); border-radius: 3px; }

  .chart-container {
    height: 180px !important;
  }

  .toast-container {
    bottom: 12px;
    left: 10px;
    right: 10px;
    width: auto;
  }
  .toast {
    width: 100%;
    box-sizing: border-box;
  }
}

@media (min-width: 1400px) {
  .main-content {
    width: 100%;
    max-width: 100%;
    padding: 28px 40px;
    box-sizing: border-box;
  }
  .stats-grid { gap: 20px; }
}

/* =====================================================
   ESTILOS — PANTALLA DE LOGIN
   ===================================================== */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.login-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  display: none !important;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 420px;
  padding: 32px 28px;
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeIn 0.4s ease;
}

.login-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.login-icon {
  font-size: 42px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-primary);
}
.login-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.password-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.password-input-wrapper .form-input {
  padding-right: 44px;
  width: 100%;
}
.password-toggle-btn {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 8px;
  font-size: 14px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}
.password-toggle-btn:hover { color: var(--text-primary); }

.login-error-msg {
  background: var(--accent-red-glow);
  border: 1px solid var(--accent-red);
  color: var(--accent-red);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  text-align: center;
}

.btn-block {
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: 0.95rem;
}

.login-footer {
  text-align: center;
  border-top: 1px solid var(--border-light);
  padding-top: 14px;
}

/* =====================================================
   ESTILOS — SIMULACIÓN HARDWARE ESP32 3.5" TFT
   ===================================================== */
.preview-modal-content {
  width: 100%;
  max-width: 540px;
  box-sizing: border-box;
}

.esp32-device-frame {
  background: #111419;
  border: 4px solid #282C34;
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: 0 12px 36px rgba(0,0,0,0.6), inset 0 1px 1px rgba(255,255,255,0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.esp32-header-bezel {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.hardware-label {
  font-family: monospace;
  font-size: 0.65rem;
  color: #61AFEF;
  letter-spacing: 0.5px;
}
.hardware-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.power-led { background: #98C379; box-shadow: 0 0 8px #98C379; }
.status-led { background: #E5C07B; animation: pulse 2s infinite; }

.esp32-footer-bezel {
  margin-top: 6px;
  padding-top: 4px;
  color: #5C6370;
  font-family: monospace;
  font-size: 0.6rem;
  text-align: center;
}

/* LA PANTALLA TFT PROPIAMENTE DICHA (ILI9486 / ILI9341 3.5" HORIZONTAL LANDSCAPE 480x320) */
.tft-screen-display {
  background: #000000;
  color: #FFFFFF;
  font-family: 'Inter', monospace, sans-serif;
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  border-radius: 8px;
  border: 2px solid #333333;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.9);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  user-select: none;
  container-type: inline-size;
}

/* =====================================================
   ESTILOS — DISTRIBUCIÓN EN 3 FILAS PANTALLA TFT 3.5" (40% USD, 40% EUR, 20% FECHA)
   ===================================================== */
.tft-3row-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: #080C14;
  height: 100%;
  box-sizing: border-box;
}

.tft-row {
  background: #0F1623;
  border: 1px solid #1E2A3E;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.tft-row-usd {
  flex: 38;
  border-color: rgba(255, 215, 0, 0.45);
  background: linear-gradient(180deg, rgba(255, 215, 0, 0.12) 0%, rgba(15, 22, 35, 1) 100%);
}
.tft-row-eur {
  flex: 38;
  border-color: rgba(0, 210, 255, 0.45);
  background: linear-gradient(180deg, rgba(0, 210, 255, 0.12) 0%, rgba(15, 22, 35, 1) 100%);
}

.tft-row-rate {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tft-row-value {
  font-size: clamp(3.2rem, 14.5cqi, 5.8rem) !important;
  font-weight: 900 !important;
  line-height: 0.9 !important;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}
.tft-row-usd .tft-row-value { color: #FFD700 !important; text-shadow: 0 0 20px rgba(255, 215, 0, 0.7); }
.tft-row-eur .tft-row-value { color: #50E3C2 !important; text-shadow: 0 0 20px rgba(80, 227, 194, 0.7); }

.tft-row-info {
  flex: 24;
  background: #0A0E18;
  border-color: #1A2436;
  padding: 0 10px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  box-sizing: border-box;
  overflow: hidden;
}

.tft-info-details {
  font-size: clamp(2.0rem, 9cqi, 3.8rem) !important;
  font-weight: 900 !important;
  color: #FFFFFF !important;
  letter-spacing: 1.5px;
  font-family: 'JetBrains Mono', monospace, sans-serif;
  text-align: center;
  width: 100%;
  line-height: 0.9 !important;
  font-variant-numeric: tabular-nums;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.tft-status-pill {
  position: absolute;
  right: 6px;
  bottom: 3px;
  font-size: clamp(0.45rem, 1cqi, 0.6rem) !important;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 3px;
  color: #00E676;
  text-transform: lowercase;
  opacity: 0.85;
}

.tft-status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #00E676;
  box-shadow: 0 0 5px rgba(0, 230, 118, 0.8);
  display: inline-block;
}

.tft-status-pill.stale {
  color: #FF5252;
}

.tft-status-pill.stale .tft-status-dot {
  background: #FF5252;
  box-shadow: 0 0 5px rgba(255, 82, 82, 0.8);
}

/* =====================================================
   WIDGET CONVERSOR DE DIVISAS (NAVBAR POPOVER)
   ===================================================== */
.converter-dropdown-container {
  position: relative;
}

.converter-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 320px;
  max-width: calc(100vw - 24px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  z-index: 1000;
  overflow: hidden;
  animation: fadeInDown 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.converter-header {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.converter-header h4 {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.popover-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s;
}
.popover-close:hover {
  color: var(--text-primary);
}

.converter-body {
  padding: 16px;
}

.converter-input-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.converter-input-wrapper {
  display: flex;
  gap: 8px;
}

.converter-input-wrapper input {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
}

.currency-select {
  width: 95px;
  font-weight: 600;
}

.converter-rates-ref {
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-align: center;
}

.converter-presets {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  justify-content: space-between;
}

.preset-btn {
  flex: 1;
  padding: 4px 0;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.preset-btn:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  background: var(--accent-blue-glow);
}

.converter-results {
  margin-top: 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.converter-result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  padding: 4px 0;
}

.converter-result-row.highlight {
  border-top: 1px dashed var(--border);
  margin-top: 4px;
  padding-top: 8px;
}

.converter-result-row .res-flag {
  color: var(--text-secondary);
}

.converter-result-row .res-value {
  font-weight: 700;
  font-family: 'Inter', monospace;
  color: var(--text-primary);
}

.converter-result-row.highlight .res-value {
  color: var(--accent-green);
  font-size: 0.95rem;
}

/* =====================================================
   SUCURSAL BADGE Y FILTRO
   ===================================================== */
.branch-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent-purple);
  background: rgba(137, 87, 229, 0.12);
  border: 1px solid rgba(137, 87, 229, 0.25);
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
}

/* =====================================================
   MODAL DE AJUSTES Y PESTAÑAS (TABS)
   ===================================================== */
.settings-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 16px;
}

.settings-tab-btn {
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.settings-tab-btn:hover {
  color: var(--text-primary);
}

.settings-tab-btn.active {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
/* =====================================================
   AFICHE HÍBRIDO SUNDDE / BCV (OPCIÓN 1)
   ===================================================== */
.sundde-poster-frame {
  width: 100%;
  max-width: 440px;
  background: #FFFFFF;
  color: #1A1A1A;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  border: 3px solid #1B365D;
  padding: 16px;
  font-family: system-ui, -apple-system, sans-serif;
  box-sizing: border-box;
}

.sundde-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.sundde-brand {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sundde-star {
  font-size: 1.6rem;
  color: #D32F2F;
}

.sundde-title {
  font-size: 1.4rem;
  font-weight: 900;
  color: #1B365D;
  letter-spacing: 0.05em;
}

.bcv-seal {
  background: #1B365D;
  color: #FFFFFF;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.8rem;
  border: 2px solid #D32F2F;
}

.sundde-legal-quote {
  font-size: 0.72rem;
  line-height: 1.25;
  color: #1B365D;
  font-weight: 600;
  text-align: center;
  background: #F5F7FA;
  padding: 8px 10px;
  border-radius: 6px;
  border-left: 3px solid #D32F2F;
  margin-bottom: 12px;
}

.sundde-middle-grid {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 12px;
  align-items: stretch;
  margin-bottom: 12px;
}

.sundde-qr-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #FFFFFF;
  border: 2px solid #1B365D;
  border-radius: 8px;
  padding: 8px;
}

.sundde-qr-box {
  color: #1B365D;
  display: flex;
  justify-content: center;
  align-items: center;
}

.sundde-qr-label {
  font-size: 0.62rem;
  color: #1B365D;
  text-align: center;
  margin-top: 6px;
  line-height: 1.1;
}

.sundde-cutout-window {
  background: #0B111E;
  border: 2px dashed #00D2FF;
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.8);
}

.cutout-header-label {
  font-size: 0.6rem;
  font-weight: 700;
  color: #00D2FF;
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.sundde-footer-banner {
  background: linear-gradient(135deg, #1B365D 0%, #0D1B2A 100%);
  color: #FFFFFF;
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}

.sundde-slogan {
  font-size: 1.1rem;
  font-weight: 900;
  color: #FFD700;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.sundde-flag-strip {
  color: #FFFFFF;
  font-size: 0.75rem;
  margin-bottom: 4px;
  letter-spacing: 0.2em;
}

.sundde-ministry-label {
  font-size: 0.62rem;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 500;
}

/* =====================================================
   MEJORAS DE ADAPTABILIDAD MÓVIL Y ACCESIBILIDAD TÁCTIL (≤ 768px)
   ===================================================== */
@media (max-width: 768px) {
  /* 1. Botones de navbar con área táctil WCAG (44x44px min) */
  .theme-toggle,
  #btn-open-settings,
  #btn-logout,
  #btn-force-scrape {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* 2. Prevención de Auto-Zoom en iOS / Safari */
  .form-input,
  .search-bar input,
  .converter-input,
  select.form-select {
    font-size: 16px !important;
  }

  /* 3. Pestañas de Ajustes con scroll horizontal táctil */
  .settings-tabs {
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    gap: 6px;
    scrollbar-width: thin;
  }
  .settings-tabs::-webkit-scrollbar { height: 3px; }
  .settings-tabs::-webkit-scrollbar-track { background: transparent; }
  .settings-tabs::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); border-radius: 3px; }
  .settings-tab-btn {
    flex: 0 0 auto;
    padding: 10px 16px;
    min-height: 44px;
  }

  /* 4. Botones de acción táctiles */
  .device-card-actions .btn,
  .action-cell .btn {
    min-height: 44px;
    padding: 8px 14px;
  }
}

/* ---- ACCESIBILIDAD (WCAG 2.1 AA) ---- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Área táctil mínima WCAG 2.5.5 */
.btn-sm,
.btn-icon {
  position: relative;
}

.btn-sm::after,
.btn-icon::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: 44px;
  min-height: 44px;
}

/* =====================================================
   PWA — Banner de Instalación (Android / Windows)
   ===================================================== */

.pwa-install-banner {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  width: calc(100% - 32px);
  max-width: 520px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  animation: pwa-slide-up 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.pwa-install-banner.hidden {
  display: none !important;
}

.pwa-install-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pwa-install-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.pwa-install-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.pwa-install-text strong {
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--text-primary);
}

.pwa-install-text span {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.pwa-install-btn {
  flex-shrink: 0;
  padding: 8px 18px !important;
  font-size: 0.85rem !important;
  border-radius: 10px !important;
}

.pwa-install-dismiss {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.2s;
}

.pwa-install-dismiss:hover {
  color: var(--text-primary);
}

@keyframes pwa-slide-up {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Ajustes para modo standalone (cuando está instalada como app) */
@media (display-mode: standalone) {
  /* Ocultar el banner de instalación en modo app */
  .pwa-install-banner {
    display: none !important;
  }

  /* Ajustar padding superior del body para status bar en móviles */
  body {
    padding-top: env(safe-area-inset-top, 0px);
  }
}



