/* =====================================================================
   ESTILOS GENERALES Y SISTEMA DE DISEÑO - WEBAPP CALIBRACIÓN DE PESAS
   NMX-EC-17025-IMNC-2018 / OIML R 111-1
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&family=Outfit:wght@400;500;600;700;800&display=swap');

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Modo Oscuro (Por defecto - Moderno Metrológico) */
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.85);
  --bg-card-hover: rgba(31, 41, 55, 0.95);
  --bg-input: #1a2234;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #3b82f6;

  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --accent-blue: #3b82f6;
  --accent-cyan: #06b6d4;
  --accent-indigo: #6366f1;
  --accent-gradient: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%);
  --accent-glow: rgba(59, 130, 246, 0.25);

  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.15);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --info: #0284c7;
  --info-bg: rgba(2, 132, 199, 0.15);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.5);
  --glass-blur: blur(12px);
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-hover: #ffffff;
  --bg-input: #f1f5f9;
  --border-color: #e2e8f0;
  --border-focus: #2563eb;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;

  --accent-glow: rgba(37, 99, 235, 0.15);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.25s ease, color 0.25s ease;
  overflow-x: hidden;
}

/* Background aesthetic gradient grid */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 400px;
  background: radial-gradient(circle at 50% -100px, rgba(59, 130, 246, 0.18), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* Header & Navbar */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: var(--glass-blur);
  padding: 0.75rem 1.5rem;
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: var(--accent-gradient);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.brand-title h1 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 40%, var(--accent-cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="light"] .brand-title h1 {
  background: linear-gradient(135deg, #1e293b 40%, #2563eb 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.badge-norma {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-blue);
  border: 1px solid rgba(59, 130, 246, 0.3);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.7rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid transparent;
  outline: none;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 2px 10px var(--accent-glow);
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
}

.btn-icon {
  padding: 0.55rem;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* Navigation Tabs */
.tabs-nav {
  display: flex;
  gap: 0.4rem;
  max-width: 1400px;
  margin: 1rem auto 0;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  scrollbar-width: none;
}

.tab-btn {
  padding: 0.75rem 1.25rem;
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-main);
}

.tab-btn.active {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
}

/* Layout Principal */
.main-content {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1.5rem 3rem;
  position: relative;
  z-index: 1;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.3s ease;
}

.tab-pane.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Tarjetas y Contenedores */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.card:hover {
  border-color: rgba(59, 130, 246, 0.3);
}

.card-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.6rem;
}

.card-title span.icon-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

/* Formularios y Campos */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

label .unit-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.1);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  transition: all 0.2s;
  outline: none;
}

input[type="number"], .font-mono {
  font-family: var(--font-mono);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Quick Presets Bar */
.presets-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.preset-chip {
  padding: 0.3rem 0.7rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.15s;
}

.preset-chip:hover {
  color: var(--accent-blue);
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.1);
}

/* Tabla de Mediciones ABA */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  text-align: left;
}

.table th {
  background: var(--bg-input);
  padding: 0.75rem 1rem;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
}

.table td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
}

.table tbody tr:hover {
  background: var(--bg-card-hover);
}

.table input.table-input {
  padding: 0.45rem 0.65rem;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-align: right;
}

.table-summary {
  display: flex;
  justify-content: flex-end;
  gap: 2rem;
  padding: 0.85rem 1.25rem;
  background: var(--bg-input);
  border-top: 1px solid var(--border-color);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.table-summary-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.table-summary-item strong {
  color: var(--text-muted);
  font-family: var(--font-sans);
}

/* Resultados Destacados / KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.kpi-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--accent-blue);
}

.kpi-card.success::after { background: var(--success); }
.kpi-card.warning::after { background: var(--warning); }
.kpi-card.danger::after { background: var(--danger); }
.kpi-card.cyan::after { background: var(--accent-cyan); }

.kpi-title {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.4rem;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.kpi-unit {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-left: 0.25rem;
  font-weight: normal;
}

.kpi-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.4rem;
}

/* Badge de Conformidad */
.conformity-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border-radius: 9999px;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

.conformity-badge.success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.conformity-badge.warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.conformity-badge.danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.4);
}

/* Desglose de Incertidumbre y Barras */
.uncertainty-bar-container {
  display: flex;
  height: 12px;
  width: 100%;
  border-radius: 6px;
  overflow: hidden;
  margin: 1rem 0;
  background: var(--bg-input);
}

.uncertainty-bar-segment {
  height: 100%;
  transition: width 0.3s ease;
}

.color-uw { background: #3b82f6; }
.color-us { background: #10b981; }
.color-ud { background: #f59e0b; }
.color-ur { background: #ec4899; }
.color-ub { background: #06b6d4; }

.legend-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.6rem;
  font-size: 0.8rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* =====================================================================
   VISTA DE IMPRESIÓN DEL INFORME (NMX-EC-17025-IMNC-2018)
   ===================================================================== */
.report-sheet {
  background: #ffffff;
  color: #111827;
  border-radius: var(--radius-lg);
  padding: 3rem;
  box-shadow: var(--shadow-lg);
  max-width: 900px;
  margin: 0 auto;
  font-family: var(--font-sans);
  border: 1px solid #e5e7eb;
}

.report-header-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #1e3a8a;
  padding-bottom: 1.5rem;
  margin-bottom: 1.5rem;
}

.report-logo-text {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 800;
  color: #1e3a8a;
  letter-spacing: -0.03em;
}

.report-logo-sub {
  font-size: 0.85rem;
  color: #4b5563;
  margin-top: 0.2rem;
}

.report-doc-info {
  text-align: right;
  font-size: 0.85rem;
  color: #374151;
}

.report-folio {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: #1e3a8a;
}

.report-title-main {
  text-align: center;
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: #111827;
  margin-bottom: 1.5rem;
}

.report-section {
  margin-bottom: 1.25rem;
}

.report-section-title {
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #1e3a8a;
  border-bottom: 1px solid #d1d5db;
  padding-bottom: 0.25rem;
  margin-bottom: 0.6rem;
}

.report-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  font-size: 0.825rem;
}

.report-item {
  display: flex;
  gap: 0.4rem;
}

.report-item-label {
  font-weight: 600;
  color: #4b5563;
  min-width: 140px;
}

.report-item-value {
  color: #111827;
  font-weight: 500;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin: 0.75rem 0;
}

.report-table th, .report-table td {
  border: 1px solid #d1d5db;
  padding: 0.45rem 0.6rem;
  text-align: center;
}

.report-table th {
  background: #f3f4f6;
  font-weight: 700;
  color: #1f2937;
}

.report-disclaimer {
  font-size: 0.72rem;
  color: #4b5563;
  line-height: 1.4;
  border: 1px dashed #d1d5db;
  padding: 0.75rem;
  border-radius: 4px;
  background: #f9fafb;
  margin-top: 1.5rem;
}

.report-signatures {
  display: flex;
  justify-content: space-around;
  margin-top: 3rem;
  text-align: center;
}

.signature-line {
  width: 200px;
  border-top: 1px solid #111827;
  padding-top: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #111827;
}

.signature-role {
  font-size: 0.7rem;
  color: #6b7280;
  font-weight: normal;
}

/* Cloudflare Badge */
.cf-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: #f6821f;
  background: rgba(246, 130, 31, 0.1);
  border: 1px solid rgba(246, 130, 31, 0.25);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

/* Reglas de Impresión */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .app-header, .tabs-nav, .header-actions, .presets-bar, .no-print {
    display: none !important;
  }
  .main-content {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
  }
  .tab-pane {
    display: none !important;
  }
  #tab-informe {
    display: block !important;
  }
  .report-sheet {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    max-width: 100% !important;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .header-container {
    flex-direction: column;
    align-items: flex-start;
  }
  .report-grid-2 {
    grid-template-columns: 1fr;
  }
  .report-sheet {
    padding: 1.5rem;
  }
  .report-signatures {
    flex-direction: column;
    align-items: center;
    gap: 2rem;
  }
}
