/* ── Variables ───────────────────────────────────────────── */
:root {
  --sidebar-bg: #1a2332;
  --sidebar-hover: rgba(255,255,255,.08);
  --sidebar-active: #0d6efd;
  --bs-purple: #6f42c1;
  --sidebar-width: 240px;
  --content-bg: #f4f6fb;
  --card-shadow: 0 2px 12px rgba(0,0,0,.07);
}

/* ── Primary color → sigue a --sidebar-active ───────────── */
.btn-primary,
.btn-primary:disabled,
.btn-primary.disabled {
  --bs-btn-bg:              var(--sidebar-active);
  --bs-btn-border-color:    var(--sidebar-active);
  --bs-btn-hover-bg:        var(--sidebar-active);
  --bs-btn-hover-border-color: var(--sidebar-active);
  --bs-btn-active-bg:       var(--sidebar-active);
  --bs-btn-active-border-color: var(--sidebar-active);
  --bs-btn-disabled-bg:     var(--sidebar-active);
  --bs-btn-disabled-border-color: var(--sidebar-active);
}
.btn-primary:hover, .btn-primary:focus-visible { filter: brightness(.88); }
.btn-primary:active                            { filter: brightness(.82); }

.btn-outline-primary {
  --bs-btn-color:              var(--sidebar-active);
  --bs-btn-border-color:       var(--sidebar-active);
  --bs-btn-hover-bg:           var(--sidebar-active);
  --bs-btn-hover-border-color: var(--sidebar-active);
  --bs-btn-active-bg:          var(--sidebar-active);
  --bs-btn-active-border-color: var(--sidebar-active);
}

.nav-pills .nav-link.active,
.nav-pills .show > .nav-link { background-color: var(--sidebar-active) !important; }

/* ── Body ────────────────────────────────────────────────── */
body { background: var(--content-bg); font-family: 'Segoe UI', system-ui, sans-serif; }

/* ── Login ───────────────────────────────────────────────── */
.login-bg {
  background: linear-gradient(135deg, #1a2332 0%, #0d6efd 100%);
}
.login-card { width: 100%; max-width: 400px; border-radius: 1rem; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  min-height: 100vh;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand { letter-spacing: .5px; }

.sidebar-divider {
  border-color: rgba(255,255,255,.1);
  margin: .5rem 0;
}

.sidebar-link {
  color: #fff !important;
  border-radius: .5rem;
  font-size: .875rem;
  padding: .5rem .75rem;
  transition: background .15s, color .15s;
}
.sidebar .text-white-50 { color: rgba(255,255,255,.82) !important; }
.sidebar-link:hover {
  background: var(--sidebar-hover) !important;
  color: #fff !important;
}
.sidebar-link.active {
  background: var(--sidebar-active) !important;
  color: #fff !important;
}

/* ── Favoritos: estrella al hover en ítems del menú ──────── */
.sidebar-link { position: relative; }
.fav-toggle {
  position: absolute;
  right: .6rem;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  font-size: .78rem;
  color: rgba(255,255,255,.65);
  cursor: pointer;
  padding: .15rem;          /* área de click más generosa */
}
.sidebar-link:hover .fav-toggle { display: inline-block; }
.fav-toggle:hover,
.fav-toggle.fav-on { color: #ffc107; }

/* Sub-items del menú colapsable I+D */
#id-submenu .sidebar-link {
  font-size: .82rem;
  padding: .35rem .6rem;
}
#id-submenu .sidebar-link.active {
  background: var(--sidebar-active) !important;
  opacity: .85;
}

/* ── Content area ────────────────────────────────────────── */
.content-area { background: var(--content-bg); }

/* ── Page header ─────────────────────────────────────────── */
.page-header {
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
}

/* ── Cards ───────────────────────────────────────────────── */
.card { border: none; border-radius: .75rem; box-shadow: var(--card-shadow); }
.card-header { border-radius: .75rem .75rem 0 0 !important; }

/* Stat cards */
.stat-card { border-radius: .75rem; transition: transform .15s; cursor: default; }
.stat-card:hover { transform: translateY(-2px); }
.stat-icon { width: 52px; height: 52px; border-radius: .6rem; display:flex; align-items:center; justify-content:center; font-size:1.4rem; }

/* ── Tables ──────────────────────────────────────────────── */
.table { font-size: .875rem; }
.table thead th { font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: #64748b; background: #f8fafc; border-bottom: 2px solid #e2e8f0; }
.table tbody tr:hover { background: #f0f4ff; }

/* ── Badges ──────────────────────────────────────────────── */
.badge { font-size: .72rem; font-weight: 600; letter-spacing: .03em; }
.bg-purple { background-color: #6f42c1 !important; color: #fff; }
.text-bg-purple { background-color: #6f42c1 !important; color: #fff !important; }
.text-purple { color: #6f42c1 !important; }

/* ── Forms ───────────────────────────────────────────────── */
.form-label { font-weight: 600; font-size: .83rem; color: #374151; }
.form-control, .form-select { font-size: .875rem; border-color: #d1d5db; }
.form-control:focus, .form-select:focus { border-color: #0d6efd; box-shadow: 0 0 0 .2rem rgba(13,110,253,.15); }

/* ── Modals ──────────────────────────────────────────────── */
.modal-header { background: #f8fafc; border-bottom: 1px solid #e2e8f0; }
.modal-title { font-weight: 700; font-size: 1rem; }

/* ── Workflow tabs (Calidad) ─────────────────────────────── */
.workflow-step { border-left: 3px solid #e2e8f0; padding-left: 1rem; margin-bottom: 1.5rem; }
.workflow-step.active-step { border-left-color: #0d6efd; }
.step-badge { width: 28px; height: 28px; border-radius: 50%; display:inline-flex; align-items:center; justify-content:center; font-size:.75rem; font-weight:700; }

/* ── Protocol print view ─────────────────────────────────── */
@media print {
  .sidebar, .modal-footer, #toast-container { display: none !important; }
  .modal-dialog { max-width: 100%; margin: 0; }
  .modal-content { border: none; box-shadow: none; }
}

/* ── Spinner overlay ─────────────────────────────────────── */
.spinner-overlay {
  position: absolute; inset: 0; background: rgba(255,255,255,.6);
  display: flex; align-items: center; justify-content: center;
  border-radius: inherit; z-index: 10;
}

/* ── Empty state ─────────────────────────────────────────── */
.empty-state { padding: 3rem 1rem; text-align: center; color: #94a3b8; }
.empty-state i { font-size: 3rem; display: block; margin-bottom: .75rem; }

/* ── Trazabilidad timeline ───────────────────────────────── */
.trace-step { display: flex; gap: .75rem; align-items: flex-start; margin-bottom: 1rem; }
.trace-dot { width: 12px; height: 12px; border-radius: 50%; background: #0d6efd; flex-shrink: 0; margin-top: 4px; }
.trace-line { width: 2px; background: #e2e8f0; flex-shrink: 0; }

/* ── Tom Select ─────────────────────────────────────────── */
/* Wrapper dentro de celdas de tabla */
.table td .ts-wrapper { min-width: 160px; }
.table-sm td .ts-wrapper .ts-control { padding: 2px 6px; font-size: .875rem; }
/* Dropdown anclado al body: debe estar sobre modales (z-index 1055) */
body > .ts-dropdown { z-index: 1070 !important; }

/* ── Responsive: menú deslizable en celular/tablet ─────── */
.mobile-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .45rem .75rem;
  padding-top: calc(.45rem + env(safe-area-inset-top, 0px));
  background: var(--sidebar-bg);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.mobile-menu-btn {
  position: relative;
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  padding: .2rem .45rem;
  border: none;
}
.mobile-menu-btn:hover, .mobile-menu-btn:focus-visible { color: #fff; background: var(--sidebar-hover); }
.mobile-notif-dot {
  position: absolute; top: .25rem; right: .25rem;
  width: 9px; height: 9px; border-radius: 50%;
  background: #dc3545; border: 2px solid var(--sidebar-bg);
}
.mobile-topbar-title { font-weight: 600; font-size: .95rem; min-width: 0; }
.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1045;
    width: min(290px, 85vw);
    min-width: 0;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding-top: calc(1rem + env(safe-area-inset-top, 0px)) !important;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px)) !important;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform .25s ease, visibility 0s linear .25s;
    overscroll-behavior: contain;
    box-shadow: 4px 0 24px rgba(0,0,0,.3);
  }
  body.sidebar-open .sidebar {
    transform: none;
    visibility: visible;
    transition: transform .25s ease;
  }
  .sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    z-index: 1040;
    background: rgba(0,0,0,.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
  }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  body.sidebar-open { overflow: hidden; }

  /* Ítems más altos: fáciles de tocar con el dedo */
  .sidebar-link { padding: .65rem .75rem; font-size: .95rem; }
  .sidebar .collapse .sidebar-link { padding-top: .5rem !important; padding-bottom: .5rem !important; }
  .notif-menu { max-width: calc(100vw - 2rem); }
  #page-content { padding: 1rem !important; }
}

/* Pantallas táctiles: sin hover, la estrella de favoritos queda siempre visible (tenue) */
@media (hover: none) {
  .fav-toggle { display: inline-block; opacity: .45; padding: .4rem; right: .3rem; }
  .fav-toggle.fav-on { opacity: 1; }
}
