/* ============================================================
   AFEMA LAB WEB2 — Estilos globales
   ============================================================ */

:root {
  --sidebar-w:     220px;
  --topbar-h:      52px;
  --color-primary: #1a3a5c;
  --color-accent:  #2e6da4;
  --color-gold:    #f0a500;
  --color-bg:      #f4f6f9;
  --color-card:    #fff;
  --color-border:  #dee2e6;
  --color-text:    #212529;
  --color-muted:   #6c757d;
  --radius:        8px;
  --shadow:        0 1px 6px rgba(0,0,0,.08);
}

/* ── Reset / Base ── */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: .9rem;
  background: var(--color-bg);
  color: var(--color-text);
}

/* ── Topbar ── */
.afema-topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
  color: #fff;
  display: flex; align-items: center;
  padding: 0 1rem;
  z-index: 1100;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.afema-topbar .brand {
  font-size: 1.2rem; font-weight: 800; letter-spacing: 1px;
}
.afema-topbar .brand span { color: var(--color-gold); }
.btn-logout {
  color: rgba(255,255,255,.85); text-decoration: none;
  font-size: .85rem; padding: .25rem .5rem;
  border-radius: 4px; transition: background .15s;
}
.btn-logout:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ── Sidebar ── */
.afema-sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--color-primary);
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;      /* evita que el scroll "contagie" a la página de fondo */
  -webkit-overflow-scrolling: touch; /* scroll suave en iOS */
  z-index: 1050;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
  transition: transform .25s ease;
}
.afema-sidebar::-webkit-scrollbar { width: 4px; }
.afema-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

.sidebar-section {
  padding: .6rem 1rem .25rem;
  font-size: .65rem; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(255,255,255,.4);
}
.sidebar-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem 1rem .5rem 1.1rem;
  color: rgba(255,255,255,.78);
  text-decoration: none;
  font-size: .85rem;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-item .icon { flex-shrink: 0; width: 18px; text-align: center; font-size: 1rem; }
.sidebar-item:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}
.sidebar-item.active {
  background: rgba(255,255,255,.12);
  color: #fff;
  border-left-color: var(--color-gold);
  font-weight: 600;
}

/* ── Main content ── */
.afema-main {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  padding: 1.5rem;
  min-height: calc(100vh - var(--topbar-h));
}

/* ── Cards ── */
.card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--color-card);
}
.card-header {
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
  font-size: .9rem;
  padding: .65rem 1rem;
  border-radius: var(--radius) var(--radius) 0 0;
  display: flex; align-items: center; gap: .4rem;
}
.card-header.secondary { background: #495057; }
.card-header.accent    { background: #0d6efd; }
.card-header.success   { background: #198754; }
.card-header.warning   { background: #dc6c00; }
.card-header.danger    { background: #b02020; }

/* ── Stat cards ── */
.stat-card {
  display: flex; align-items: center; gap: .75rem;
  padding: 1rem; border-radius: var(--radius);
  color: #fff; text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,.15); }
.stat-card .stat-icon { font-size: 1.8rem; opacity: .85; flex-shrink: 0; }
.stat-card .stat-val  { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.stat-card .stat-lbl  { font-size: .72rem; opacity: .88; margin-top: .15rem; }

.stat-card.blue    { background: linear-gradient(135deg, #1a3a5c, #2e6da4); }
.stat-card.teal    { background: linear-gradient(135deg, #0d7377, #14a085); }
.stat-card.green   { background: linear-gradient(135deg, #1a6b34, #28a745); }
.stat-card.orange  { background: linear-gradient(135deg, #a34c00, #f0a500); }
.stat-card.purple  { background: linear-gradient(135deg, #4a1a7a, #8b5cf6); }
.stat-card.red     { background: linear-gradient(135deg, #7b0000, #dc3545); }
.stat-card.brown   { background: linear-gradient(135deg, #5c3317, #a0522d); }
.stat-card.indigo  { background: linear-gradient(135deg, #1e3a6e, #3b5998); }

/* ── Tables ── */
.table-afema thead th {
  background: #e9ecef;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 2px solid #dee2e6;
  white-space: nowrap;
}
.table-afema tbody tr:hover { background: #f0f4ff; }
.table-afema td { vertical-align: middle; }

/* ── Buttons ── */
.btn-afema-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.btn-afema-primary:hover {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
}

/* ── Formularios ── */
.form-section-title {
  font-size: .75rem; font-weight: 700; letter-spacing: .8px;
  text-transform: uppercase; color: var(--color-muted);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: .35rem; margin-bottom: 1rem; margin-top: 1.5rem;
}
.form-label { font-weight: 600; font-size: .85rem; }

/* ── Badge estado ── */
.badge-pendiente  { background: #ffc107; color: #212529; }
.badge-aprobado   { background: #198754; color: #fff; }
.badge-rechazado  { background: #dc3545; color: #fff; }

/* ── Muestra info box (widget búsqueda) ── */
.muestra-info-box {
  background: #e8f4fd;
  border: 1px solid #b8d9f0;
  border-radius: 6px;
  padding: .65rem .9rem;
  font-size: .85rem;
  display: none;
}
.muestra-info-box.visible { display: block; }
.muestra-info-box .mi-reg { font-size: 1rem; font-weight: 700; color: var(--color-primary); }
.muestra-info-box .mi-mat { color: #444; }

/* ── Tablas de ensayo (6 probetas, etc.) ── */
.table-ensayo { font-size: .83rem; }
.table-ensayo th { background: #f1f3f5; font-weight: 700; text-align: center; }
.table-ensayo td { text-align: center; }
.table-ensayo td input[type="number"],
.table-ensayo td input[type="text"]  {
  width: 90px; text-align: right; font-size: .82rem;
  padding: .2rem .35rem;
}

/* ── Gráficos ── */
.chart-container { position: relative; }

/* ── Paginación ── */
.pagination { flex-wrap: wrap; gap: 2px; }
.pagination .page-link { font-size: .8rem; padding: .25rem .55rem; }

/* ── Responsive: colapso sidebar ── */
@media (max-width: 767.98px) {
  .afema-sidebar {
    transform: translateX(-100%);
    box-shadow: 2px 0 16px rgba(0,0,0,.35);
  }
  .afema-sidebar.open { transform: translateX(0); }
  .afema-main { margin-left: 0; padding: 1rem; }

  /* Fondo oscuro al abrir el menú (overlay). Lo muestra/oculta el JS con .show. */
  .sidebar-overlay {
    position: fixed; inset: var(--topbar-h) 0 0 0;
    background: rgba(0,0,0,.4);
    z-index: 1040;
    opacity: 0; pointer-events: none;
    transition: opacity .25s ease;
  }
  .sidebar-overlay.show { opacity: 1; pointer-events: auto; }

  /* Con el menú abierto, bloquear el scroll de la página de fondo. */
  body.sidebar-abierto { overflow: hidden; }
}

/* ── Utilidades extra ── */
.text-primary-dark { color: var(--color-primary) !important; }
.fw-800 { font-weight: 800; }
.ls-1 { letter-spacing: .05rem; }
.gap-xs { gap: .25rem; }
.table-sm td, .table-sm th { padding: .3rem .5rem; }

/* ── Print ── */
@media print {
  .afema-topbar,
  .afema-sidebar,
  .no-print { display: none !important; }
  .afema-main { margin: 0; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}

/* ── Buscador global ── */
.global-search input { font-size: .85rem; }
.global-search-results {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px;
  background: #fff; border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.25);
  max-height: 70vh; overflow-y: auto; z-index: 1200; display: none;
  color: var(--color-text);
}
.global-search-results.visible { display: block; }
.gsr-group-title {
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--color-muted); padding: .5rem .75rem .25rem; background: #f4f6f9;
  position: sticky; top: 0;
}
.gsr-item {
  display: flex; align-items: center; gap: .6rem; padding: .5rem .75rem;
  text-decoration: none; color: var(--color-text); border-bottom: 1px solid #f0f0f0;
}
.gsr-item:hover { background: #eef4fb; }
.gsr-item .gsr-ico { color: var(--color-accent); font-size: 1rem; flex-shrink: 0; }
.gsr-item .gsr-titulo { font-weight: 600; font-size: .82rem; }
.gsr-item .gsr-sub { font-size: .72rem; color: var(--color-muted); }
.gsr-empty { padding: 1rem; text-align: center; color: var(--color-muted); font-size: .82rem; }
.gsr-footer { padding: .5rem .75rem; text-align: center; border-top: 1px solid #e5e5e5; }

/* ── Granulometría: resaltado de serie de tamices ── */
tr.gran-row.serie-off { opacity: .4; }
tr.gran-row.serie-on  { background: #eafaf1; }
tr.gran-row.serie-on th { background: #d4f4e2; }
