/* ============================================================================
   BÚFALOS ERP — Hoja de estilos principal
   Paleta oficial Búfalos: Rojo #A72020 · Gris #5B585D · Blanco #FFFFFF
   Tokens y lenguaje visual heredados de bufaloshc (evolución, no rediseño).
   ========================================================================= */

:root {
  --color-primary: #A72020;
  --color-primary-dark: #8A1A1A;
  --color-primary-light: #C94040;
  --color-secondary: #5B585D;
  --color-secondary-dark: #434147;
  --color-dark: #2B2828;
  --color-darker: #1E1C1C;
  --color-canvas: #F0F2F5;
  --color-gray: #6B7280;
  --color-gray-light: #9CA3AF;
  --color-border: #E5E7EB;
  --color-success: #10B981;
  --color-warning: #F59E0B;
  --color-error: #EF4444;

  --sidebar-width: 264px;
  --header-height: 64px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

/* El atributo `hidden` debe ganar siempre: varios componentes usan
   `display: flex`, que de lo contrario anularía el `display: none` nativo. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { max-width: 100%; overflow-x: hidden; }

body {
  font-family: var(--font-sans);
  background: var(--color-canvas);
  color: var(--color-dark);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

img, svg, video { max-width: 100%; height: auto; }
p, h1, h2, h3, h4, span, a, li, label { overflow-wrap: break-word; }

a { color: inherit; text-decoration: none; }

/* Accesibilidad: foco siempre visible con el color de marca. */
:focus-visible {
  outline: 3px solid var(--color-primary-light);
  outline-offset: 2px;
  border-radius: 4px;
}

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

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: var(--color-primary); border-radius: 3px; }

/* ── LOGIN ────────────────────────────────────────────────────────────────── */
.login-body { background: var(--color-darker); }

#login-page {
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(135deg, #1E1C1C 0%, #2B2828 50%, var(--color-primary-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

#login-page::before,
#login-page::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
#login-page::before {
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(167, 32, 32, 0.22) 0%, transparent 70%);
  top: -140px; right: -140px;
}
#login-page::after {
  width: 420px; height: 420px;
  background: radial-gradient(circle, rgba(91, 88, 93, 0.25) 0%, transparent 70%);
  bottom: -80px; left: -80px;
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  background: #fff;
  border-radius: var(--radius-xl);
  padding: 44px 40px 32px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.35);
  animation: slide-up 0.35s ease both;
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}

.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo img {
  height: 110px; width: auto; object-fit: contain;
  margin: 0 auto 18px; display: block;
  filter: drop-shadow(0 6px 18px rgba(167, 32, 32, 0.28));
}
.login-logo h1 {
  font-size: 26px; font-weight: 800; letter-spacing: -0.5px; color: var(--color-dark);
}
.login-logo p { color: var(--color-gray); font-size: 13.5px; margin-top: 6px; }

.login-footer {
  margin-top: 22px; padding-top: 18px;
  border-top: 1px solid var(--color-border);
  text-align: center;
}
.login-footer p { font-size: 12px; color: var(--color-gray-light); }

/* ── FORMULARIOS ──────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-dark);
  margin-bottom: 7px;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  color: var(--color-dark);
  background: #fff;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.form-input::placeholder { color: var(--color-gray-light); }
.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(167, 32, 32, 0.12);
}
.form-input:disabled { background: #F9FAFB; cursor: not-allowed; }

.form-hint { font-size: 12px; color: var(--color-gray); margin-top: 6px; }

.input-with-action { position: relative; }
.input-with-action .form-input { padding-right: 46px; }
.input-action {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  border: none; background: none;
  color: var(--color-gray-light);
  cursor: pointer;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  line-height: 1;
}
.input-action:hover { color: var(--color-primary); }

/* Evita el zoom automático de iOS en inputs < 16px. */
@media (max-width: 768px) {
  .form-input { font-size: 16px; }
}

/* ── BOTONES ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, transform 0.12s, box-shadow 0.18s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.65; cursor: not-allowed; }
.btn:not(:disabled):active { transform: translateY(1px); }

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:not(:disabled):hover {
  background: var(--color-primary-dark);
  box-shadow: 0 6px 18px rgba(167, 32, 32, 0.28);
}

.btn-ghost { background: transparent; color: var(--color-secondary); }
.btn-ghost:hover { background: rgba(0, 0, 0, 0.05); }

.btn-icon { padding: 9px; min-width: 40px; }

.btn-block { width: 100%; padding: 13px 18px; }

.btn-logout {
  width: 100%;
  background: rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 13px;
  padding: 9px 12px;
  margin-top: 10px;
}
.btn-logout:hover { background: var(--color-primary); color: #fff; border-color: transparent; }

.btn-spinner {
  width: 17px; height: 17px;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── ALERTAS ──────────────────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 18px;
  border: 1px solid transparent;
}
.alert-error { background: #FEF2F2; color: #991B1B; border-color: #FECACA; }
.alert-info { background: #EFF6FF; color: #1E40AF; border-color: #BFDBFE; }
.alert-success { background: #ECFDF5; color: #065F46; border-color: #A7F3D0; }

/* ── LAYOUT DE APLICACIÓN ─────────────────────────────────────────────────── */
#app-layout { display: flex; min-height: 100vh; min-height: 100dvh; }

#sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, #1E1C1C 0%, #2B2828 100%);
  color: #fff;
  position: fixed;
  inset: 0 auto 0 0;
  height: 100vh;
  height: 100dvh;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.28s ease;
}

.sidebar-header {
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}
.sidebar-logo { display: flex; align-items: center; gap: 12px; }
.sidebar-logo-img { height: 42px; width: auto; object-fit: contain; flex-shrink: 0; }
.sidebar-logo-text { display: flex; flex-direction: column; min-width: 0; }
.sidebar-logo-text strong {
  font-size: 16px; font-weight: 800; letter-spacing: -0.3px; color: #fff;
}
.sidebar-logo-text small { font-size: 11px; color: rgba(255, 255, 255, 0.5); }

.sidebar-nav {
  flex: 1;
  padding: 14px 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); }

.nav-section { margin-bottom: 18px; }
.nav-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: rgba(255, 255, 255, 0.3);
  padding: 0 8px;
  margin-bottom: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: background 0.18s, color 0.18s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-item.active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(167, 32, 32, 0.4);
}
.nav-item .nav-icon { width: 18px; text-align: center; flex-shrink: 0; font-size: 14px; }
.nav-item .nav-label { flex: 1; min-width: 0; }

.nav-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 3px 7px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.55);
  flex-shrink: 0;
}
.nav-item.active .nav-badge { background: rgba(255, 255, 255, 0.28); color: #fff; }

.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
}
.user-avatar {
  width: 36px; height: 36px;
  background: var(--color-primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff;
  flex-shrink: 0;
}
.user-details { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.user-name {
  font-size: 13px; font-weight: 600; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-role { font-size: 11px; color: rgba(255, 255, 255, 0.45); }

/* ── CONTENIDO PRINCIPAL ──────────────────────────────────────────────────── */
#main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

#top-header {
  min-height: var(--header-height);
  padding: 0 max(24px, var(--safe-right)) 0 max(20px, var(--safe-left));
  background: #fff;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

#sidebar-toggle { display: none; }

.header-titles { flex: 1; min-width: 0; }
.header-title {
  font-size: 18px; font-weight: 700; color: var(--color-dark);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-subtitle { font-size: 12.5px; color: var(--color-gray); }

.header-actions { display: flex; align-items: center; gap: 12px; }
.header-user {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--color-secondary);
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.page-content {
  flex: 1;
  padding: 24px max(24px, var(--safe-right)) 32px max(24px, var(--safe-left));
  width: 100%;
  min-width: 0;
}

#sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.25s;
}
#sidebar-overlay:not([hidden]) { opacity: 1; }

/* ── TARJETAS ─────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}
.card + .card, .card + section, section + .card { margin-top: 20px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.card-title { font-size: 16px; font-weight: 700; color: var(--color-dark); }
.card-hint { font-size: 12px; color: var(--color-gray-light); }

.form-card { max-width: 520px; }

.welcome-card {
  background: linear-gradient(135deg, var(--color-darker) 0%, var(--color-dark) 55%, var(--color-primary-dark) 100%);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 26px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.welcome-eyebrow {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.2px; color: rgba(255, 255, 255, 0.55); margin-bottom: 6px;
}
.welcome-card h2 { font-size: 24px; font-weight: 800; letter-spacing: -0.4px; }
.welcome-text {
  font-size: 14px; color: rgba(255, 255, 255, 0.78);
  margin-top: 8px; max-width: 62ch;
}
.role-chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 7px 14px; border-radius: 30px;
  font-size: 12.5px; font-weight: 600;
  flex-shrink: 0;
}

/* ── ESTADÍSTICAS ─────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
  list-style: none;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  border-left: 4px solid var(--color-primary);
  transition: transform 0.18s, box-shadow 0.18s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0, 0, 0, 0.09); }
.stat-label { font-size: 12.5px; color: var(--color-gray); font-weight: 500; }
.stat-value {
  font-size: 30px; font-weight: 800; color: var(--color-dark);
  line-height: 1.15; margin-top: 4px;
}
.stat-value-sm { font-size: 17px; }
.stat-hint { font-size: 11.5px; color: var(--color-gray-light); margin-top: 4px; }

/* ── MÓDULOS ──────────────────────────────────────────────────────────────── */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  list-style: none;
}
.module-tile {
  display: flex;
  gap: 13px;
  padding: 15px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #FAFAFA;
}
.module-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: rgba(167, 32, 32, 0.09);
  color: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}
.module-name { font-size: 14px; font-weight: 700; color: var(--color-dark); }
.module-desc { font-size: 12.5px; color: var(--color-gray); margin-top: 3px; }

/* ── ESTADO VACÍO / PLACEHOLDER ───────────────────────────────────────────── */
.empty-state {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 52px 28px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  max-width: 640px;
  margin: 24px auto;
}
.empty-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 72px; height: 72px;
  border-radius: 20px;
  background: rgba(167, 32, 32, 0.09);
  color: var(--color-primary);
  font-size: 28px;
  margin-bottom: 18px;
}
.empty-state h2 { font-size: 22px; font-weight: 800; color: var(--color-dark); }
.empty-badge {
  display: inline-block;
  margin: 10px 0 14px;
  padding: 5px 13px;
  border-radius: 20px;
  background: var(--color-primary);
  color: #fff;
  font-size: 11.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
}
.empty-text { font-size: 14.5px; color: var(--color-secondary); max-width: 52ch; margin: 0 auto; }
.empty-note {
  font-size: 12.5px; color: var(--color-gray-light);
  margin: 14px auto 22px; max-width: 52ch;
}

/* ── PÁGINA DE ERROR ──────────────────────────────────────────────────────── */
.error-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 32px;
  background: linear-gradient(135deg, #1E1C1C 0%, #2B2828 55%, var(--color-primary-dark) 100%);
  color: #fff;
}
.error-code { font-size: 58px; font-weight: 800; color: var(--color-primary-light); line-height: 1; }
.error-page h1 { font-size: 22px; font-weight: 700; }
.error-text { color: rgba(255, 255, 255, 0.7); font-size: 14px; margin-bottom: 16px; }

/* ── TOASTS ───────────────────────────────────────────────────────────────── */
#toast-root {
  position: fixed;
  right: 18px; bottom: 18px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 300;
  pointer-events: none;
}
.toast {
  background: var(--color-dark);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  max-width: 340px;
  animation: slide-up 0.22s ease both;
}
.toast-error { background: #991B1B; }
.toast-success { background: #065F46; }

/* ── RESPONSIVE ───────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sidebar-width: 236px; }
}

@media (max-width: 860px) {
  #sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0, 0, 0, 0.4); }
  #sidebar.is-open { transform: none; }
  #main-content { margin-left: 0; }
  #sidebar-toggle { display: inline-flex; }
  .page-content { padding: 18px 16px 28px; }
  .welcome-card { padding: 20px; }
  .welcome-card h2 { font-size: 21px; }
  .header-user span { display: none; }
}

@media (max-width: 480px) {
  .login-card { padding: 32px 22px 24px; }
  .login-logo img { height: 88px; }
  .stat-value { font-size: 26px; }
}

@media print {
  #sidebar, #top-header, #toast-root { display: none !important; }
  #main-content { margin-left: 0; }
}
