/* ============================================================
   SISTEMA DE ARMADO WEB — Estilos principales
   Paleta: azul industrial oscuro + grises + acentos teal
   ============================================================ */

:root {
  --color-primary:     #1E3A5F;
  --color-primary-lt:  #2B5491;
  --color-accent:      #00B4A6;
  --color-accent-lt:   #00D4C4;
  --color-bg:          #F0F4F8;
  --color-sidebar:     #151E2D;
  --color-sidebar-lt:  #1E2D45;
  --color-text:        #1A202C;
  --color-muted:       #718096;
  --color-success:     #38A169;
  --color-warning:     #D69E2E;
  --color-danger:      #E53E3E;
  --color-info:        #3182CE;
  --sidebar-width:     260px;
  --topbar-height:     60px;
  --radius:            8px;
  --shadow:            0 2px 12px rgba(0,0,0,0.10);
  --transition:        0.2s ease;
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.6;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--color-sidebar);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
  overflow-y: auto;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.sidebar-brand h1 {
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.3;
}

.sidebar-brand span {
  color: var(--color-accent);
  font-size: 0.72rem;
  font-weight: 400;
  display: block;
}

.sidebar-nav { padding: 12px 0; flex: 1; }

.nav-section-label {
  padding: 14px 20px 4px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 0.855rem;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: var(--color-sidebar-lt);
  color: #fff;
  border-left-color: var(--color-accent);
}

.sidebar-nav a .nav-icon {
  width: 26px; height: 26px;
  border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 0.9rem;
  transition: transform 0.15s;
}
.sidebar-nav a .nav-icon svg { width: 14px; height: 14px; stroke-width: 2; }

/* Colores de íconos sidebar */
.ni-blue   { background: rgba(59,130,246,0.18); color: #60A5FA; }
.ni-green  { background: rgba(52,211,153,0.15); color: #34D399; }
.ni-teal   { background: rgba(0,180,166,0.15);  color: #00D4C4; }
.ni-purple { background: rgba(167,139,250,0.18); color: #A78BFA; }
.ni-orange { background: rgba(251,146,60,0.18);  color: #FB923C; }
.ni-red    { background: rgba(248,113,113,0.18); color: #F87171; }
.ni-yellow { background: rgba(250,204,21,0.18);  color: #FACC15; }
.ni-sky    { background: rgba(56,189,248,0.18);  color: #38BDF8; }
.ni-slate  { background: rgba(148,163,184,0.15); color: #94A3B8; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.07);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.sidebar-user .avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--color-primary-lt);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.sidebar-user .user-info small {
  display: block;
  color: rgba(255,255,255,0.4);
  font-size: 0.7rem;
}

.sidebar-user .user-name {
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
}

.btn-logout {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.07);
  border: none;
  border-radius: var(--radius);
  color: rgba(255,255,255,0.6);
  font-size: 0.82rem;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition);
}

.btn-logout:hover { background: rgba(229,62,62,0.25); color: #fc8181; }

/* ── Layout principal ────────────────────────────────────── */
.main-layout {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #E2E8F0;
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

/* Botón hamburguesa oculto en desktop, visible solo en móvil */
#sidebarToggle { display: none; }

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-primary);
  flex: 1;
}

.page-content {
  flex: 1;
  padding: 28px;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid #E2E8F0;
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid #EDF2F7;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-primary);
  margin: 0;
}

.card-body { padding: 20px; }

/* ── Stat cards (dashboard) ──────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid #E2E8F0;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.stat-icon {
  width: 46px; height: 46px;
  border-radius: 12px;
  background: rgba(59,130,246,0.15);
  color: #60A5FA;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.stat-icon.green  { background: rgba(52,211,153,0.15); color: #10B981; }
.stat-icon.orange { background: rgba(251,146,60,0.18);  color: #F97316; }
.stat-icon.teal   { background: rgba(0,200,180,0.15);   color: #14B8A6; }
.stat-icon.purple { background: rgba(167,139,250,0.18); color: #8B5CF6; }
.stat-icon svg    { width: 22px; height: 22px; stroke-width: 1.8; }

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--color-muted);
  margin-top: 2px;
}

/* ── Botones ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all var(--transition);
  line-height: 1.4;
}

.btn-sm { padding: 5px 11px; font-size: 0.78rem; }
.btn-lg { padding: 11px 24px; font-size: 0.95rem; }

.btn-primary   { background: var(--color-primary);   color: #fff; }
.btn-primary:hover { background: var(--color-primary-lt); color: #fff; }

.btn-accent    { background: var(--color-accent);    color: #fff; }
.btn-accent:hover { background: var(--color-accent-lt); color: #fff; }

.btn-success   { background: var(--color-success);   color: #fff; }
.btn-danger    { background: var(--color-danger);    color: #fff; }
.btn-warning   { background: var(--color-warning);   color: #fff; }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--color-primary);
  color: var(--color-primary);
}
.btn-outline:hover { background: var(--color-primary); color: #fff; }

.btn-ghost {
  background: transparent;
  color: var(--color-muted);
  border: 1.5px solid #E2E8F0;
}
.btn-ghost:hover { background: #F7FAFC; color: var(--color-text); }

/* ── Tablas ──────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
}

table.app-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.app-table thead th {
  background: var(--color-primary);
  color: #fff;
  padding: 11px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.app-table tbody tr {
  border-bottom: 1px solid #EDF2F7;
  transition: background var(--transition);
}

.app-table tbody tr:hover { background: #F7FAFC; }

.app-table tbody td {
  padding: 10px 14px;
  color: var(--color-text);
  vertical-align: middle;
}

.app-table tbody tr:last-child { border-bottom: none; }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge-success  { background: #F0FFF4; color: #276749; }
.badge-danger   { background: #FFF5F5; color: #9B2335; }
.badge-warning  { background: #FFFAF0; color: #7B341E; }
.badge-info     { background: #EBF8FF; color: #2C5282; }
.badge-neutral  { background: #F7FAFC; color: #4A5568; }
.badge-accent   { background: #E6FFFA; color: #285E61; }

/* ── Formularios ─────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: 5px;
}

.form-label .req { color: var(--color-danger); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid #CBD5E0;
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--color-text);
  background: #fff;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}

.form-control:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(0,180,166,0.15);
}

.form-control::placeholder { color: #A0AEC0; }

select.form-control { cursor: pointer; }

textarea.form-control { resize: vertical; min-height: 80px; }

.form-hint {
  font-size: 0.75rem;
  color: var(--color-muted);
  margin-top: 4px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

/* ── Alertas flash ───────────────────────────────────────── */
.flash-container { padding: 0 0 16px; }

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 10px;
  border: 1px solid transparent;
}

.alert-success { background: #F0FFF4; border-color: #9AE6B4; color: #276749; }
.alert-danger  { background: #FFF5F5; border-color: #FEB2B2; color: #9B2335; }
.alert-warning { background: #FFFAF0; border-color: #FAF089; color: #7B341E; }
.alert-info    { background: #EBF8FF; border-color: #90CDF4; color: #2C5282; }

.alert .close-btn {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: inherit;
  opacity: 0.6;
  padding: 0;
  line-height: 1;
}

/* ── Mermas dinámicas ────────────────────────────────────── */
.merma-row {
  display: grid;
  grid-template-columns: 100px 140px 1fr 36px;
  gap: 8px;
  align-items: end;
  margin-bottom: 8px;
  padding: 10px;
  background: #F7FAFC;
  border-radius: var(--radius);
  border: 1px solid #E2E8F0;
}

.btn-remove-merma {
  background: none;
  border: 1.5px solid #FEB2B2;
  border-radius: var(--radius);
  color: var(--color-danger);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  height: 36px;
  width: 36px;
}

.btn-remove-merma:hover { background: #FFF5F5; }

/* ── Página de login ─────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--color-sidebar) 0%, var(--color-primary) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-box {
  background: #fff;
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo h2 {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--color-primary);
  margin: 0 0 4px;
}

.login-logo p {
  color: var(--color-muted);
  font-size: 0.82rem;
  margin: 0;
}

/* ── Filtros ─────────────────────────────────────────────── */
.filter-bar {
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.filter-bar .form-group { margin: 0; min-width: 150px; }

/* ── Badges de tabla de roles ────────────────────────────── */
.role-badge-admin  { background: #EBF8FF; color: #2B6CB0; }
.role-badge-usuario { background: #F0FFF4; color: #276749; }
.role-badge-visor  { background: #FAF5FF; color: #553C9A; }

/* ── Precio vigente ──────────────────────────────────────── */
.precio-vigente {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-success);
}

.precio-sin-vigencia {
  font-size: 0.85rem;
  color: var(--color-danger);
  font-weight: 600;
}

/* ── Responsive / Mobile first ───────────────────────────── */

/* Overlay oscuro cuando sidebar está abierto en móvil */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

@media (max-width: 900px) {

  /* Sidebar como drawer lateral */
  .sidebar {
    transform: translateX(-100%);
    z-index: 200;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* Contenido ocupa todo el ancho */
  .main-layout {
    margin-left: 0;
  }

  /* Topbar: mostrar botón hamburguesa solo en móvil */
  #sidebarToggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    background: #F0F4F8;
    border: 1.5px solid #E2E8F0;
    font-size: 1.2rem;
    cursor: pointer;
    flex-shrink: 0;
  }

  .topbar {
    padding: 0 14px;
    gap: 10px;
  }

  .topbar-title {
    font-size: 0.9rem;
  }

  .page-content {
    padding: 14px;
  }

  /* Stats en 2 columnas */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .stat-card {
    padding: 14px;
    gap: 10px;
  }

  .stat-value { font-size: 1.3rem; }

  /* Grids de layout en columna única */
  div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns:1fr 320px"],
  div[style*="grid-template-columns: 1fr 320px"],
  div[style*="grid-template-columns:1fr 380px"],
  div[style*="grid-template-columns: 1fr 380px"] {
    grid-template-columns: 1fr !important;
  }

  /* Panel sticky del form de producción: no sticky en móvil */
  .card[style*="position:sticky"],
  .card[style*="position: sticky"] {
    position: static !important;
  }

  /* Filtros en columna */
  .filter-bar {
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }
  .filter-bar .form-group {
    min-width: unset;
    width: 100%;
  }

  /* form-row en columna en pantallas chicas */
  .form-row {
    grid-template-columns: 1fr;
  }

  /* Controles más grandes para touch */
  .form-control {
    padding: 12px 14px;
    font-size: 1rem;
    min-height: 48px;
  }

  select.form-control {
    min-height: 48px;
  }

  textarea.form-control {
    min-height: 90px;
  }

  /* Botones más grandes para touch */
  .btn {
    padding: 11px 18px;
    font-size: 0.9rem;
    min-height: 44px;
  }
  .btn-sm {
    padding: 9px 14px;
    font-size: 0.82rem;
    min-height: 38px;
  }
  .btn-lg {
    padding: 14px 24px;
    font-size: 1rem;
    min-height: 52px;
  }

  /* Mermas: apilar en móvil */
  .merma-row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 8px;
  }
  .merma-row .form-group:nth-child(3) {
    grid-column: 1 / -1;
  }
  .btn-remove-merma {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    align-self: end;
  }

  /* Tablas: scroll horizontal con indicador visual */
  .table-wrapper {
    -webkit-overflow-scrolling: touch;
    border: 1px solid #E2E8F0;
    border-radius: var(--radius);
  }
  .table-wrapper::after {
    content: '';
    display: block;
  }

  /* Tabla de historial: reducir columnas visibles en móvil */
  .app-table { font-size: 0.8rem; }
  .app-table thead th,
  .app-table tbody td {
    padding: 9px 10px;
  }

  /* Ocultar columnas secundarias en historial móvil */
  .hide-mobile { display: none !important; }

  /* Cards sin padding lateral excesivo */
  .card-body { padding: 14px; }
  .card-header { padding: 12px 14px; }
}

/* Pantallas muy chicas (< 480px) */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .login-box {
    padding: 28px 20px;
  }

  .topbar-title { font-size: 0.85rem; }

  /* Apilar acciones del topbar */
  .topbar > div {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }
}

/* ── Utilidades ──────────────────────────────────────────── */
.text-muted  { color: var(--color-muted); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.text-primary { color: var(--color-primary); }
.fw-bold { font-weight: 700; }
.mb-0 { margin-bottom: 0; }
.mt-0 { margin-top: 0; }
.gap-2 { gap: 8px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-100 { width: 100%; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E0; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #A0AEC0; }

/* ══════════════════════════════════════════════════════════
   APP MODE — Operario en smartphone (body.app-mode)
   Activa cuando rol == 'usuario'. Admin no se ve afectado.
   ══════════════════════════════════════════════════════════ */

/* Ocultar sidebar y overlay completamente */
body.app-mode .sidebar,
body.app-mode .sidebar-overlay { display: none !important; }

/* Layout ocupa todo el ancho sin margen lateral */
body.app-mode .main-layout { margin-left: 0; }

/* Topbar estilo app: fondo primario, título centrado, sin hamburguesa */
body.app-mode .topbar {
  background: var(--color-primary);
  border-bottom: none;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  padding: 0 14px;
  position: sticky;
  top: 0;
  z-index: 50;
}

body.app-mode #sidebarToggle { display: none !important; }

body.app-mode .topbar-title {
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
}

/* Acciones del topbar (ej: ← Historial) — estilo blanco sobre oscuro */
body.app-mode .topbar > div .btn-ghost,
body.app-mode .topbar > div .btn {
  color: rgba(255,255,255,0.9);
  border-color: rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.1);
  font-size: 0.82rem;
  padding: 7px 12px;
  min-height: auto;
}

/* Contenido con padding inferior para no quedar bajo la barra de navegación */
body.app-mode .page-content {
  padding: 12px 12px 80px;
  background: #EAEFF5;
}

/* Fondo general más limpio en modo app */
body.app-mode { background: #EAEFF5; }

/* Cards sin sombra pesada en modo app */
body.app-mode .card {
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* ── Bottom navigation bar ─────────────────────────────── */
.app-bottom-nav { display: none; }          /* oculto para admin/visor */

body.app-mode .app-bottom-nav {
  display: flex;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 62px;
  padding-bottom: env(safe-area-inset-bottom); /* soporte notch iOS */
  background: #fff;
  border-top: 1px solid #E2E8F0;
  box-shadow: 0 -3px 16px rgba(0,0,0,0.10);
  z-index: 200;
}

.app-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 8px;
  gap: 3px;
  text-decoration: none;
  color: #A0AEC0;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: none;
  background: none;
  cursor: pointer;
  transition: color var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.app-nav-item .nav-ico { font-size: 1.35rem; line-height: 1; }

.app-nav-item.active { color: var(--color-accent); }

/* Ítem central — botón FAB elevado */
.app-nav-center {
  position: relative;
  justify-content: flex-end;
  color: var(--color-accent);
}

.app-nav-fab {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 300;
  box-shadow: 0 4px 16px rgba(0,180,166,0.45);
  transition: background var(--transition), transform var(--transition);
  line-height: 1;
}

.app-nav-center:active .app-nav-fab {
  background: var(--color-accent-lt);
  transform: translateX(-50%) scale(0.94);
}

.app-nav-center.active .app-nav-fab {
  background: var(--color-primary);
  box-shadow: 0 4px 16px rgba(30,58,95,0.35);
}

/* Texto del ítem central debajo del FAB */
.app-nav-center > span:last-child {
  margin-top: 4px;
  font-size: 0.6rem;
}
