/* ============================================================
   Medidor de Decibeles RNG — Hoja de estilos principal
   Paleta corporativa RNG:
     navy oscuro  #0B1A2E   (fondo)
     navy         #003B7A   (acentos / paneles)
     oro          #C9A227   (aguja / resaltes)
   Tipografía:
     Oswald       (títulos)
     Roboto Mono  (números)
   ============================================================ */

:root {
  --navy-dark:  #0B1A2E;
  --navy:       #003B7A;
  --navy-soft:  #13365f;
  --gold:       #C9A227;
  --gold-light: #E5C64A;
  --green:      #2ECC71;
  --amber:      #F39C12;
  --red:        #E74C3C;
  --text:       #E8EDF5;
  --text-dim:   #93A4BE;
  --panel-bg:   #0f2541;
  --border:     #1b3358;
  --radius:     14px;
  --safe-area-top:    env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Roboto', 'Segoe UI', system-ui, sans-serif;
  background: var(--navy-dark);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
  padding: calc(var(--safe-area-top) + 8px) 12px calc(var(--safe-area-bottom) + 16px);
  max-width: 560px;
  margin: 0 auto;
  -webkit-tap-highlight-color: transparent;
}

.nowrap { white-space: nowrap; }

/* ==================== ENCABEZADO ==================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-logo {
  border-radius: 8px;
  background: var(--navy);
  padding: 2px;
}

.brand-text h1 {
  font-family: 'Oswald', sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  line-height: 1.1;
  color: var(--text);
}
.brand-sub {
  font-size: 0.72rem;
  color: var(--gold);
  font-weight: 500;
  letter-spacing: 0.4px;
}

.calib-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  background: rgba(231,76,60,0.15);
  color: var(--red);
  border: 1px solid rgba(231,76,60,0.4);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.calib-badge.calibrated {
  background: rgba(46,204,113,0.15);
  color: var(--green);
  border-color: rgba(46,204,113,0.4);
}
.calib-badge i { font-size: 0.8rem; }


/* ==================== MEDIDOR ANALÓGICO ==================== */
.meter-section {
  margin-top: 14px;
  text-align: center;
}

.meter-wrap {
  position: relative;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

.analog-meter {
  width: 100%;
  height: auto;
  display: block;
}

.big-number {
  position: absolute;
  left: 50%;
  bottom: 2%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}
.big-number .number {
  display: block;
  font-family: 'Roboto Mono', monospace;
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-dim);
  transition: color 0.3s;
}
.big-number .number.zone-green { color: var(--green); }
.big-number .number.zone-amber { color: var(--amber); }
.big-number .number.zone-red   { color: var(--red); }
.big-number .unit {
  font-family: 'Oswald', sans-serif;
  font-size: 0.85rem;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.status-label {
  font-family: 'Oswald', sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.5px;
  margin-top: -8px;
  color: var(--text-dim);
  transition: color 0.3s;
}
.status-label.zone-green { color: var(--green); }
.status-label.zone-amber { color: var(--amber); }
.status-label.zone-red   { color: var(--red); font-weight: 600; }

/* ==================== MÉTRICAS ==================== */
.metrics-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 16px;
}
.metric {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 4px;
  text-align: center;
}
.metric-label {
  display: block;
  font-family: 'Oswald', sans-serif;
  font-size: 0.68rem;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.metric-value {
  display: block;
  font-family: 'Roboto Mono', monospace;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--gold);
  margin-top: 2px;
}

/* ==================== GRÁFICA ==================== */
.chart-section { margin-top: 18px; }
.section-title {
  font-family: 'Oswald', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.chart-wrap {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
#historyChart { width: 100%; height: 100%; display: block; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-top: 8px;
  font-size: 0.7rem;
  color: var(--text-dim);
}
.leg-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 3px;
}
.leg-green { background: var(--green); }
.leg-amber { background: var(--amber); }
.leg-red   { background: var(--red); }
.leg-line {
  display: inline-block;
  width: 18px; height: 0;
  border-top: 2px dashed var(--red);
  vertical-align: middle;
  margin-right: 3px;
}

/* ==================== CONTROL PRINCIPAL ==================== */
.control-section { margin-top: 20px; }

.btn-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 18px;
  font-family: 'Oswald', sans-serif;
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #fff;
  background: var(--navy);
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  min-height: 64px;
}
.btn-toggle:active { transform: scale(0.98); }
.btn-toggle.running {
  background: var(--red);
  border-color: var(--red);
}
.btn-toggle i { font-size: 1.1rem; }

/* Botón de modo (micrófono / demo) */
.mode-row { margin-top: 10px; display: flex; justify-content: center; }
.btn-mode {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-family: 'Oswald', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.3px;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-mode:hover, .btn-mode:focus-visible { color: var(--text); border-color: var(--navy-soft); }
.btn-mode.demo {
  color: var(--gold);
  border-color: var(--gold);
}
.btn-mode i { font-size: 0.85rem; }

/* ==================== PANELES ==================== */
.panels { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  font-family: 'Oswald', sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.3px;
  list-style: none;
  user-select: none;
}
.panel-summary::-webkit-details-marker { display: none; }
.panel-summary::after {
  content: '\f078'; /* fa-chevron-down */
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--text-dim);
  transition: transform 0.2s;
}
.panel[open] .panel-summary::after { transform: rotate(180deg); }
.panel-summary i:first-child { color: var(--gold); width: 18px; text-align: center; }
.panel-count {
  margin-left: auto;
  margin-right: 8px;
  font-family: 'Roboto Mono', monospace;
  font-size: 0.75rem;
  background: var(--navy);
  color: var(--gold);
  padding: 1px 8px;
  border-radius: 10px;
}

.panel-body {
  padding: 0 16px 16px;
  font-size: 0.85rem;
}
.panel-hint {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-bottom: 8px;
}
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* Offset row */
.offset-row {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
}
.btn-step {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  font-family: 'Roboto Mono', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gold);
  background: var(--navy);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-step:active { background: var(--navy-soft); }
.offset-display {
  flex: 1;
  text-align: center;
}
.offset-label {
  display: block;
  font-size: 0.68rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.offset-value {
  display: block;
  font-family: 'Roboto Mono', monospace;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold);
}

/* Calibración por referencia */
.calib-steps {
  margin: 4px 0 12px 18px;
  color: var(--text-dim);
  font-size: 0.8rem;
  line-height: 1.6;
}
.ref-row {
  display: flex;
  gap: 8px;
}
.ref-input {
  flex: 1;
  padding: 10px 12px;
  font-family: 'Roboto Mono', monospace;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--navy-dark);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.ref-input::placeholder { color: #5a6f8e; font-family: 'Roboto', sans-serif; font-size: 0.78rem; }

/* Campos de texto */
.field {
  display: block;
  margin-bottom: 12px;
}
.field span {
  display: block;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.text-input {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--navy-dark);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.text-input::placeholder { color: #5a6f8e; }

/* Botones de acción */
.btn-action {
  flex: 0 0 auto;
  padding: 10px 18px;
  font-family: 'Oswald', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.5px;
  color: var(--navy-dark);
  background: var(--gold);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-action:active { background: var(--gold-light); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  font-family: 'Oswald', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  background: var(--navy);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:active { background: var(--navy-soft); }
.btn-secondary i { color: var(--gold); }

/* Historial */
.history-list {
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 12px;
}
.empty-state {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.82rem;
  padding: 16px 0;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--navy-dark);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
}
.history-item .hi-icon {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Roboto Mono', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
}
.history-item .hi-body { flex: 1; min-width: 0; }
.history-item .hi-title {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item .hi-meta {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-family: 'Roboto Mono', monospace;
}
.history-item .hi-del {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1rem;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: color 0.15s;
}
.history-item .hi-del:hover, .history-item .hi-del:focus-visible { color: var(--red); }

.export-row {
  display: flex;
  gap: 8px;
}
.export-row .btn-secondary { flex: 1; justify-content: center; }

/* ==================== AVISO INFERIOR ==================== */
.bottom-notice { margin-top: 16px; }
.bottom-notice-card {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  background: var(--navy);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.82rem;
}
.bottom-notice-card i { color: var(--gold); font-size: 1.1rem; }

/* ==================== PIE ==================== */
.app-footer {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-dim);
}
.footer-legal { color: #5a6f8e; font-size: 0.68rem; margin-top: 2px; }

/* ==================== TOAST ==================== */
.toast {
  position: fixed;
  bottom: calc(var(--safe-area-bottom) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy);
  color: var(--text);
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 0.85rem;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==================== PRINT (PDF) ==================== */
.print-only { display: none; }

@media print {
  body * { visibility: hidden !important; }
  #printArea, #printArea * { visibility: visible !important; }
  #printArea {
    display: block !important;
    position: absolute;
    left: 0; top: 0;
    width: 100%;
    padding: 0;
    background: #fff;
    color: #000;
    max-width: none;
  }
  @page { margin: 18mm 16mm; size: portrait; }
}

/* ==================== ACCESIBILIDAD ==================== */
:focus-visible {
  outline: 3px solid var(--gold-light);
  outline-offset: 2px;
  border-radius: 4px;
}
button { -webkit-appearance: none; appearance: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Alto contraste del sistema */
@media (prefers-contrast: more) {
  :root {
    --text-dim: #c8d4ea;
    --border:   #2a4a7a;
    --panel-bg: #0a1f3a;
  }
  .footer-legal { color: #9ab0d0; }
}

/* ==================== TABLET / DESKTOP ==================== */
@media (min-width: 600px) {
  body { padding-left: 20px; padding-right: 20px; }
  .big-number .number { font-size: 3.4rem; }
  .btn-toggle { font-size: 1.4rem; }
}
