/* ── TOUP.ES Gestión – Main Stylesheet ─────────────────────────────────── */

:root {
  --sb-bg:        #0f1117;   /* fondo sidebar */
  --sb-accent:    #5b34f2;   /* morado principal */
  --sb-accent2:   #7c5ef5;   /* morado hover */
  --sb-text:      #c9d1de;   /* texto items */
  --sb-muted:     #525f72;   /* texto grupos / separadores */
  --sb-hover-bg:  rgba(91,52,242,.14);
  --sb-active-bg: #5b34f2;
  --toup-dark:    #0f1117;
  --toup-darker:  #090c12;
  --toup-accent:  #5b34f2;
  --toup-accent2: #7c5ef5;
  --sidebar-w:    220px;
  --topbar-h:     60px;
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
  --safe-top:     env(safe-area-inset-top,    0px);
  --safe-left:    env(safe-area-inset-left,   0px);
}

* { box-sizing: border-box; }

html { height: -webkit-fill-available; }

body {
  font-family: 'Inter', 'DM Sans', sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overscroll-behavior: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════════════════════ */

.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  height: 100dvh;
  background: var(--sb-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  padding-left: var(--safe-left);
  z-index: 1040;
  overflow: hidden;
  transition: transform .28s cubic-bezier(.4,0,.2,1);
}

/* ── Logo ──────────────────────────────────────────────────────────────── */
.sidebar-header {
  padding: 22px 18px 18px;
  padding-top: calc(22px + var(--safe-top));
  flex-shrink: 0;
  /* separador sutil */
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.brand {
  text-decoration: none;
  display: block;
  line-height: 1;
}
.brand-text {
  font-size: 1.45rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.5px;
  font-family: 'Inter', sans-serif;
}
.brand-dot { color: var(--sb-accent); }
.brand-sub {
  display: block;
  color: var(--sb-muted);
  font-size: .65rem;
  font-weight: 500;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  margin-top: 5px;
}

/* ── Menú scrollable ───────────────────────────────────────────────────── */
.sidebar-menu {
  list-style: none;
  padding: 12px 8px 20px;
  margin: 0;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.sidebar-menu::-webkit-scrollbar       { width: 2px; }
.sidebar-menu::-webkit-scrollbar-track { background: transparent; }
.sidebar-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 1px; }

/* ── Dashboard (ítem directo) ──────────────────────────────────────────── */
.nav-single {
  margin-bottom: 4px;
}

.nav-single > a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--sb-text);
  text-decoration: none;
  font-size: .84rem;
  font-weight: 500;
  min-height: 40px;
  transition: background .15s, color .12s;
  -webkit-tap-highlight-color: transparent;
}
.nav-single > a i {
  font-size: .95rem;
  width: 18px;
  flex-shrink: 0;
  opacity: .75;
}
.nav-single > a:hover {
  background: var(--sb-hover-bg);
  color: #fff;
}
.nav-single > a:hover i { opacity: 1; }
.nav-single > a.active {
  background: var(--sb-active-bg);
  color: #fff;
  font-weight: 600;
}
.nav-single > a.active i { opacity: 1; }

/* ─────────────────────────────────────────────────────────────────────────
   GRUPOS COLAPSABLES
   ───────────────────────────────────────────────────────────────────────── */

.nav-group {
  margin-bottom: 1px;
}

/* Separador entre grupos */
.nav-group + .nav-group {
  padding-top: 0;
}

/* ── Botón toggle ──────────────────────────────────────────────────────── */
.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--sb-muted);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  cursor: pointer;
  min-height: 36px;
  text-align: left;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.nav-group-toggle:hover {
  color: #8899aa;
}

/* Cuando el grupo está abierto */
.nav-group.is-open > .nav-group-toggle {
  color: #8899aa;
}

/* Cuando el grupo contiene la página activa */
.nav-group.has-active > .nav-group-toggle {
  color: #a78bfa;
}

.nav-group-icon {
  width: 16px;
  flex-shrink: 0;
  font-size: .85rem;
  display: flex;
  align-items: center;
}

.nav-group-label { flex: 1; }

/* Flecha chevron */
.nav-arrow {
  font-size: .6rem;
  flex-shrink: 0;
  color: var(--sb-muted);
  transition: transform .2s ease, color .15s;
  opacity: .6;
}
.nav-group.is-open > .nav-group-toggle .nav-arrow {
  transform: rotate(180deg);
  color: var(--sb-accent2);
  opacity: 1;
}

/* ── Sub-ítems (altura controlada por JS con scrollHeight) ─────────────── */
.nav-group-items {
  list-style: none;
  margin: 0;
  padding: 0 0 2px 0;
  height: 0;
  overflow: hidden;
  transition: height .22s cubic-bezier(.4,0,.2,1);
}

.nav-group-items li {
  padding-left: 8px;
}

.nav-group-items a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px 7px 10px;
  border-radius: 7px;
  color: #8090a0;
  text-decoration: none;
  font-size: .835rem;
  font-weight: 400;
  min-height: 38px;
  transition: background .15s, color .12s;
  -webkit-tap-highlight-color: transparent;
}
.nav-group-items a i {
  font-size: .85rem;
  width: 16px;
  flex-shrink: 0;
  opacity: .55;
}

.nav-group-items a:hover {
  background: var(--sb-hover-bg);
  color: #fff;
}
.nav-group-items a:hover i { opacity: .9; }

.nav-group-items a.active {
  background: var(--sb-active-bg);
  color: #fff;
  font-weight: 600;
}
.nav-group-items a.active i { opacity: 1; }

/* ── Footer ────────────────────────────────────────────────────────────── */
.sidebar-footer {
  padding: 12px 18px;
  padding-bottom: calc(12px + var(--safe-bottom));
  border-top: 1px solid rgba(255,255,255,.05);
  flex-shrink: 0;
}

/* ── Botón cerrar (solo móvil) ─────────────────────────────────────────── */
.sidebar-close-btn {
  display: none;
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(255,255,255,.07);
  border: none;
  color: #8090a0;
  width: 32px;
  height: 32px;
  border-radius: 7px;
  font-size: 1rem;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, color .15s;
}
.sidebar-close-btn:hover { background: rgba(255,255,255,.12); color: #fff; }

/* ═══════════════════════════════════════════════════════════════════════════
   OVERLAY (fondo oscuro detrás del sidebar en móvil)
   ═══════════════════════════════════════════════════════════════════════════ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 1039;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .28s ease;
}
.sidebar-overlay.visible {
  display: block;
}
.sidebar-overlay.active {
  opacity: 1;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════════════════════════════════════════ */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Topbar ────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 100;
  /* Respeta notch en landscape (iPhone) */
  padding-right: env(safe-area-inset-right, 0px);
}

.page-title {
  font-size: .95rem;
  font-weight: 600;
  color: #1e293b;
  /* Evita overflow del título en pantallas pequeñas */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

/* ── Content area ──────────────────────────────────────────────────────── */
.content-area {
  flex: 1;
  /* Espacio extra para el home indicator de iPhone */
  padding-bottom: calc(16px + var(--safe-bottom));
}

/* ═══════════════════════════════════════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════════════════════════════════════ */
.card {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.card-header {
  background: #fff;
  border-bottom: 1px solid #f1f5f9;
  font-weight: 600;
  border-radius: 12px 12px 0 0 !important;
  padding: 14px 20px;
}

/* ── Stat cards ────────────────────────────────────────────────────────── */
.stat-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.1); }

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.stat-value { font-size: 1.5rem; font-weight: 700; color: #0f172a; }
.stat-label { font-size: .8rem; color: #64748b; font-weight: 500; }
.stat-change { font-size: .78rem; font-weight: 500; }

/* ═══════════════════════════════════════════════════════════════════════════
   TABLES
   ═══════════════════════════════════════════════════════════════════════════ */
.table-container {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  overflow: hidden;
}

.table { margin: 0; }
.table thead th {
  background: #f8fafc;
  font-size: .8rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .6px;
  border-bottom: 1px solid #e2e8f0;
  padding: 12px 16px;
  white-space: nowrap;
}
.table tbody td {
  padding: 12px 16px;
  vertical-align: middle;
  font-size: .875rem;
}
.table tbody tr:hover { background: #f8fafc; }

/* ═══════════════════════════════════════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════════════════════════════════════ */
.form-label { font-weight: 500; font-size: .875rem; color: #374151; }
.form-control, .form-select {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: .875rem;
  padding: 8px 12px;
  transition: border-color .15s, box-shadow .15s;
  /* Evita zoom automático en iOS (requiere font-size >= 16px en inputs) */
  font-size: max(.875rem, 16px);
}
.form-control:focus, .form-select:focus {
  border-color: var(--toup-accent);
  box-shadow: 0 0 0 3px rgba(91,52,242,.15);
}

/* ── Inputs en filtros pueden ser más pequeños (no se hace focus-zoom) ── */
.card .form-control,
.card .form-select {
  font-size: .875rem;
}

/* ═══════════════════════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════════════════════ */
.btn {
  border-radius: 8px;
  font-weight: 500;
  font-size: .875rem;
  /* Mínimo tap target en móvil */
  min-height: 38px;
  /* Quita el highlight azul en iOS al tocar */
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--toup-accent); border-color: var(--toup-accent); color: #fff; }
.btn-primary:hover { background: var(--toup-accent2); border-color: var(--toup-accent2); color: #fff; }

/* ═══════════════════════════════════════════════════════════════════════════
   LOGIN PAGE
   ═══════════════════════════════════════════════════════════════════════════ */
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(135deg, var(--toup-darker) 0%, #1e293b 50%, #0f172a 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
}

.login-card {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.login-logo {
  font-size: 2.5rem;
  font-weight: 800;
  color: #fff;
  text-align: center;
  margin-bottom: 4px;
}
.login-logo span { color: var(--toup-accent); }
.login-sub { text-align: center; color: #64748b; font-size: .875rem; margin-bottom: 32px; }

.login-card .form-control {
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.12);
  color: #fff;
  font-size: 16px; /* Evita zoom en iOS */
}
.login-card .form-control::placeholder { color: #64748b; }
.login-card .form-control:focus {
  background: rgba(255,255,255,.1);
  border-color: var(--toup-accent);
  color: #fff;
}
.login-card .form-label { color: #94a3b8; }

/* ═══════════════════════════════════════════════════════════════════════════
   INVOICE ITEMS
   ═══════════════════════════════════════════════════════════════════════════ */
.item-row { background: #f8fafc; border-radius: 8px; padding: 12px; margin-bottom: 8px; }
.item-row .form-control { background: #fff; }

/* ═══════════════════════════════════════════════════════════════════════════
   BADGE
   ═══════════════════════════════════════════════════════════════════════════ */
.badge { font-size: .75rem; padding: 4px 10px; border-radius: 6px; font-weight: 500; }

/* ═══════════════════════════════════════════════════════════════════════════
   INVOICE PRINT
   ═══════════════════════════════════════════════════════════════════════════ */
.invoice-print {
  background: #fff;
  max-width: 820px;
  margin: 0 auto;
  padding: 0;
  font-family: 'DM Sans', 'Inter', sans-serif;
}
.invoice-header-bar {
  background: var(--toup-dark);
  color: #fff;
  padding: 28px 40px;
  border-radius: 12px 12px 0 0;
}
.invoice-brand { font-size: 2rem; font-weight: 800; }
.invoice-brand-dot { color: var(--toup-accent); }
.invoice-body { padding: 32px 40px; }

/* ═══════════════════════════════════════════════════════════════════════════
   PRINT
   ═══════════════════════════════════════════════════════════════════════════ */
@media print {
  .no-print, .topbar, .sidebar, .sidebar-overlay, .btn, nav { display: none !important; }
  .main-content { margin: 0 !important; }
  .content-area { padding: 0 !important; }
  body { background: #fff; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — TABLET (≤ 991px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 991px) {

  .sidebar {
    transform: translateX(-100%);
    /* En iOS con notch el safe-area puede variar, forzar ancho completo */
    width: min(var(--sidebar-w), 85vw);
    /* Sombra al abrir */
    box-shadow: none;
    transition: transform .28s cubic-bezier(.4, 0, .2, 1),
                box-shadow .28s ease;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }

  .sidebar-close-btn {
    display: flex;
  }

  .main-content  { margin-left: 0; }
  .sidebar-toggle { display: flex !important; }

  /* Reducir padding en content area */
  .content-area { padding: 16px !important; }

  /* Encabezados de página más compactos */
  .page-title { max-width: 140px; }

  /* Stat cards más compactas */
  .stat-value { font-size: 1.2rem; }
  .stat-card  { padding: 14px; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — MÓVIL (≤ 575px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 575px) {

  /* ── Topbar ── */
  .topbar { padding-left: 12px !important; padding-right: 12px !important; }
  .page-title { max-width: 110px; font-size: .85rem; }

  /* El texto del usuario se oculta, solo queda el icono */
  .topbar .dropdown-toggle .d-none-xs { display: none; }

  /* ── Cards ── */
  .card-header { padding: 12px 16px; font-size: .9rem; }

  /* ── Tablas — scroll horizontal sin perder el diseño ── */
  .table-container { border-radius: 8px; }
  .table-responsive { -webkit-overflow-scrolling: touch; }

  /* Celdas más compactas en móvil */
  .table thead th   { padding: 10px 10px; font-size: .72rem; }
  .table tbody td   { padding: 10px 10px; font-size: .82rem; }

  /* Columnas de acciones: botones apilados o compactos */
  .btn-group-sm .btn { padding: .25rem .4rem; }

  /* ── Formularios de filtro ── */
  .card .form-control,
  .card .form-select {
    font-size: 16px; /* Evita zoom en iOS */
  }

  /* ── Content area ── */
  .content-area { padding: 12px !important; }

  /* ── Stat cards en columna ── */
  .stat-value { font-size: 1.1rem; }
  .stat-label { font-size: .72rem; }
  .stat-card  { padding: 12px; }

  /* ── Cabeceras de sección ── */
  .d-flex.align-items-center.justify-content-between.mb-4 {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 10px;
  }
  .d-flex.align-items-center.justify-content-between.mb-4 > a,
  .d-flex.align-items-center.justify-content-between.mb-4 > .btn {
    align-self: flex-start;
  }

  /* ── Login card ── */
  .login-card { padding: 28px 20px; }
  .login-logo { font-size: 2rem; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   iOS CHROME — FIXES ESPECÍFICOS
   ═══════════════════════════════════════════════════════════════════════════ */

/* Evitar que iOS redimensione los inputs al hacer focus (zoom) */
@supports (-webkit-touch-callout: none) {
  input[type="text"],
  input[type="email"],
  input[type="number"],
  input[type="date"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px !important;
  }

  /* Fix de scroll momentum en contenedores con overflow */
  .table-responsive,
  .sidebar-menu {
    -webkit-overflow-scrolling: touch;
  }
}
