/* ============================================================
   FACTURACIÓN 365 – Estilos principales
   ============================================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* --- Variables de color corporativo --- */
:root {
  --primary: #1e3a5f;
  --primary-light: #2d6a9f;
  --primary-dark: #152840;
  --accent: #3498db;
  --success: #27ae60;
  --warning: #f39c12;
  --danger: #e74c3c;
  --info: #17a2b8;
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #2c3e50;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --sidebar-width: 260px;
  --topbar-height: 60px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .10);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, .12);
  --radius: 10px;
  --radius-sm: 6px;
  --transition: all .2s ease;
}

/* --- Reset y base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

/* Scrollbar global (tablas, page-content, etc.) */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: #b0b8c1;
}

/* Scrollbar del sidebar (fondo oscuro) */
.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .2);
  border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, .35);
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--primary-light);
  text-decoration: none;
  transition: var(--transition);
}

a:hover {
  color: var(--primary);
}

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */

/* Wrapper principal */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 3px 0 10px rgba(0, 0, 0, .15);
  transition: var(--transition);
}

/* Logo en sidebar */
.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
  padding-right: 15px;
}

.sidebar-brand {
  padding: 20px 0 20px 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar-height);
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: rgba(255, 255, 255, .6);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 5px;
}

.sidebar-close:hover {
  color: #fff;
}

.sidebar-brand img {
  height: 38px;
  width: auto;
  object-fit: contain;
  border-radius: 6px;
}

.sidebar-brand-text {
  font-size: .85rem;
  font-weight: 600;
  line-height: 1.3;
  color: rgba(255, 255, 255, .9);
}

.sidebar-brand-text small {
  display: block;
  font-size: .72rem;
  font-weight: 400;
  color: rgba(255, 255, 255, .55);
}

/* Navegación */
.sidebar-nav {
  padding: 12px 0;
  flex: 1;
}

.nav-section-title {
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .4);
  padding: 16px 22px 6px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 22px;
  color: rgba(255, 255, 255, .75);
  font-size: .88rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: var(--transition);
}

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

.sidebar-nav a i {
  width: 18px;
  text-align: center;
  font-size: .9rem;
  opacity: .8;
}

/* Footer del sidebar */
.sidebar-footer {
  padding: 16px 22px;
  border-top: 1px solid rgba(255, 255, 255, .1);
  font-size: .82rem;
  color: rgba(255, 255, 255, .5);
}

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

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

.sidebar-user-name {
  font-weight: 500;
  color: rgba(255, 255, 255, .85);
  font-size: .85rem;
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255, 255, 255, .55) !important;
  font-size: .82rem;
  padding: 6px 0 !important;
  border-left: none !important;
  background: none !important;
}

.btn-logout:hover {
  color: var(--danger) !important;
}

/* ============================================================
   ÁREA DE CONTENIDO PRINCIPAL
   ============================================================ */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Topbar dentro del contenido */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 50;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text);
  cursor: pointer;
  margin-right: 15px;
}

.topbar-left {
  display: flex;
  align-items: center;
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Área de página */
.page-content {
  padding: 24px;
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  min-width: 0;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  min-width: 0;
  /* Previene el desbordamiento en CSS Grid */
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
}

.card-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title i {
  color: var(--primary-light);
}

.card-body {
  padding: 20px;
}

.card-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
}

/* Stats Cards (Dashboard) */
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  transition: var(--transition);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-icon.primary {
  background: rgba(30, 58, 95, .1);
  color: var(--primary);
}

.stat-icon.success {
  background: rgba(39, 174, 96, .1);
  color: var(--success);
}

.stat-icon.warning {
  background: rgba(243, 156, 18, .1);
  color: var(--warning);
}

.stat-icon.info {
  background: rgba(23, 162, 184, .1);
  color: var(--info);
}

.stat-icon.danger {
  background: rgba(231, 76, 60, .1);
  color: var(--danger);
}

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

.stat-label {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: 3px;
  font-weight: 500;
}

/* ============================================================
   BOTONES
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  opacity: .88;
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

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

.btn-accent {
  background: var(--primary-light);
  color: #fff;
}

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

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

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

.btn-info {
  background: var(--info);
  color: #fff;
}

.btn-light {
  background: #f8f9fa;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-sm {
  padding: 5px 10px;
  font-size: .78rem;
}

.btn-lg {
  padding: 11px 22px;
  font-size: .95rem;
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
}

/* En móvil, los botones deben ser más fáciles de tocar */
@media (max-width: 600px) {
  .btn {
    padding: 10px 18px;
  }

  .btn-sm {
    padding: 8px 12px;
  }
}

/* ============================================================
   TABLAS
   ============================================================ */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 60vh;
  border-radius: var(--radius-sm);
  -webkit-overflow-scrolling: touch;
}

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
  white-space: nowrap;
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  color: rgba(255, 255, 255, .9);
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 11px 16px;
  text-align: left;
  white-space: nowrap;
}

.table tbody tr {
  border-bottom: 1px solid var(--primary);
  transition: background .15s;
}

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

.table tbody tr:hover {
  background: rgba(45, 106, 159, .04);
}

.table tbody td {
  padding: 11px 16px;
  color: var(--text);
  vertical-align: middle;
}

/* Striping por columnas en lugar de por filas */
.table tbody td:nth-child(even) {
  background: #e2e6ea;
}

/* --- COLUMNA DE ACCIONES PEGAJOSA (Sticky Right) --- */
.table th:last-child,
.table td:last-child {
  position: sticky;
  right: 0;
  background: var(--card);
}

.table thead th:last-child {
  z-index: 12;
  /* Por encima del sticky superior */
  background: var(--primary);
  box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
}

.table tbody td:last-child {
  z-index: 2;
  /* Por encima del scroll normal */
  box-shadow: -2px 0 5px rgba(0, 0, 0, 0.03);
  background: var(--card) !important;
  /* Forza blanco puro base */
}

.table tbody tr:hover td:last-child {
  background: #f1f5f8 !important;
  /* Simula el hover */
}

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

.form-label {
  display: block;
  font-size: .83rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

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

.form-control {
  width: 100%;
  padding: 9px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(45, 106, 159, .12);
}

.form-control:invalid:not(:focus):not(:placeholder-shown) {
  border-color: var(--danger);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%236c757d' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
  padding-right: 36px;
}

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

.form-row {
  display: grid;
  gap: 16px;
  margin-bottom: 18px;
}

.form-row .form-group {
  margin-bottom: 0;
}

.form-row.col-2 {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.form-row.col-3 {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.form-row.col-4 {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.dashboard-row-custom {
  display: grid;
  grid-template-columns: 1fr 1fr 2fr;
  gap: 16px;
}

/* Grilla de 2 columnas para PC, 1 para Movil */
.dash-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 16px;
  grid-auto-rows: auto;
}

@media (max-width: 900px) {
  .dash-grid-2 {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   ALERTAS Y FLASH MESSAGES
   ============================================================ */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: .87rem;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  border: 1px solid transparent;
}

.alert-success {
  background: #d4edda;
  border-color: #c3e6cb;
  color: #155724;
}

.alert-danger {
  background: #f8d7da;
  border-color: #f5c6cb;
  color: #721c24;
}

.alert-warning {
  background: #fff3cd;
  border-color: #ffeeba;
  color: #856404;
}

.alert-info {
  background: #d1ecf1;
  border-color: #bee5eb;
  color: #0c5460;
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: .73rem;
  font-weight: 600;
}

.badge-primary {
  background: rgba(30, 58, 95, .12);
  color: var(--primary);
}

.badge-success {
  background: rgba(39, 174, 96, .12);
  color: var(--success);
}

.badge-warning {
  background: rgba(243, 156, 18, .12);
  color: #b7770c;
}

.badge-danger {
  background: rgba(231, 76, 60, .12);
  color: var(--danger);
}

.badge-info {
  background: rgba(23, 162, 184, .12);
  color: #0c6776;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}

.page-header-subtitle {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.breadcrumb {
  font-size: .8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.breadcrumb a {
  color: var(--primary-light);
}

.breadcrumb-sep {
  color: var(--border);
}

/* ============================================================
   TABLAS DE RENGLONES (Facturas/Presupuestos/Notas)
   ============================================================ */
.renglones-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}

.renglones-table th {
  background: #f8f9fa;
  padding: 9px 10px;
  border: 1px solid var(--primary);
  font-weight: 600;
  font-size: .78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.renglones-table td {
  padding: 7px 8px;
  border: 1px solid var(--primary);
  vertical-align: middle;
}

.renglones-table td:nth-child(even) {
  background: #e2e6ea;
}

.renglones-table .form-control {
  border: 1px solid #e0e0e0;
  padding: 5px 8px;
  font-size: .83rem;
  background: transparent;
}

.renglones-table tfoot td {
  background: #f8f9fa;
  font-weight: 600;
  padding: 9px 10px;
  border: 1px solid var(--primary);
}

.btn-remove-row {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: .9rem;
  padding: 4px 6px;
  border-radius: 4px;
  transition: var(--transition);
}

.btn-remove-row:hover {
  background: rgba(231, 76, 60, .1);
}

/* ============================================================
   TOTALES BOX (Facturas/Presupuestos/Notas)
   ============================================================ */
.totales-box {
  background: #f8f9fa;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
}

.totales-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  font-size: .88rem;
  border-bottom: 1px dashed var(--border);
}

.totales-row:last-child {
  border-bottom: none;
  padding-top: 10px;
  font-weight: 700;
  font-size: 1rem;
}

.totales-label {
  color: var(--text-muted);
}

.totales-value {
  font-weight: 600;
  font-family: 'Courier New', monospace;
}

/* ============================================================
   MODAL DE CONFIRMACIÓN
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 999;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  max-width: 420px;
  width: 90%;
  animation: modalIn .2s ease;
}

@keyframes modalIn {
  from {
    transform: scale(.92);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

.modal-icon {
  font-size: 2.5rem;
  color: var(--danger);
  margin-bottom: 12px;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.modal-text {
  font-size: .87rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  max-width: 360px;
  border-left: 4px solid;
  animation: toastIn .3s ease;
}

@keyframes toastIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast.success {
  border-color: var(--success);
}

.toast.error {
  border-color: var(--danger);
}

.toast.warning {
  border-color: var(--warning);
}

.toast-icon {
  font-size: 1.1rem;
}

.toast.success .toast-icon {
  color: var(--success);
}

.toast.error .toast-icon {
  color: var(--danger);
}

.toast.warning .toast-icon {
  color: var(--warning);
}

.toast-msg {
  font-size: .85rem;
  flex: 1;
}

/* ============================================================
   PÁGINA DE LOGIN
   ============================================================ */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  display: flex;
  width: 100%;
  max-width: 860px;
  min-height: 500px;
  overflow: hidden;
}

.login-left {
  flex: 1;
  background: var(--primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: #fff;
  position: relative;
  overflow: hidden;
}

.login-left::before {
  content: '';
  position: absolute;
  width: 300px;
  height: 300px;
  background: rgba(255, 255, 255, .05);
  border-radius: 50%;
  top: -80px;
  left: -80px;
}

.login-left::after {
  content: '';
  position: absolute;
  width: 200px;
  height: 200px;
  background: rgba(255, 255, 255, .05);
  border-radius: 50%;
  bottom: -40px;
  right: -40px;
}

.login-logo {
  width: 100%;
  max-width: 260px;
  height: auto;
  margin-bottom: 20px;
  position: relative;
  z-index: 1;
  border-radius: 10px;
  background: #fff;
  padding: 10px 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .15);
}

.login-brand-name {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
  z-index: 1;
}

.login-brand-sub {
  font-size: .85rem;
  opacity: .7;
  z-index: 1;
}

.login-right {
  flex: 1;
  padding: 50px 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.login-sub {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: 30px;
}

/* ============================================================
   UTILIDADES
   ============================================================ */
.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.text-muted {
  color: var(--text-muted);
}

.text-success {
  color: var(--success);
}

.text-danger {
  color: var(--danger);
}

.text-warning {
  color: var(--warning);
}

.text-primary {
  color: var(--primary);
}

.d-flex {
  display: flex;
}

.align-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-sm {
  gap: 8px;
}

.gap-md {
  gap: 16px;
}

.mb-0 {
  margin-bottom: 0;
}

.mb-1 {
  margin-bottom: 8px;
}

.mb-2 {
  margin-bottom: 16px;
}

.mb-3 {
  margin-bottom: 24px;
}

.mt-1 {
  margin-top: 8px;
}

.mt-2 {
  margin-top: 16px;
}

.mt-3 {
  margin-top: 24px;
}

.fw-600 {
  font-weight: 600;
}

.fw-700 {
  font-weight: 700;
}

.fs-sm {
  font-size: .8rem;
}

.w-100 {
  width: 100%;
}

/* Divisor de sección */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* Busqueda en tablas */
.search-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-bar .form-control {
  max-width: 280px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 14px;
  opacity: .35;
}

.empty-state p {
  font-size: .9rem;
}

/* ============================================================
   DASHBOARD GRIDS
   ============================================================ */

/* Fila 1 y 2: tarjetas stat con tamaño fijo y centradas */
.dash-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.dash-grid-4 .stat-card {
  min-height: 90px;
}

/* Layout tabla + formulario lateral */
.unidades-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .unidades-layout {
    grid-template-columns: 1fr;
  }
}

/* Fila 2: solo 2 tarjetas, mismo tamaño que las de arriba */
.dash-grid-2-stat {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.dash-grid-2-stat>*:nth-child(n+3) {
  display: none;
}

/* por si acaso */
.dash-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.stat-card-link {
  text-decoration: none;
  color: inherit;
  display: block;
}

.stat-card-tasa {
  background: linear-gradient(135deg, var(--success), #1e8449) !important;
  border: none !important;
}

.stat-card-tasa .stat-value,
.stat-card-tasa .stat-label {
  color: #fff !important;
}

/* Botones acceso rápido: 6 botones en 3 columnas iguales */
.dash-accesos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.dash-accesos .btn {
  justify-content: center;
  width: 100%;
}

/* ============================================================
   FILTROS DE DASHBOARD
   ============================================================ */
.filtros-container {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

.filtro-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
}

.filtro-label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.filtros-container .form-control {
  padding: 8px 11px;
  font-size: .85rem;
  height: 36px;
  border: 1.5px solid var(--border);
  background-color: #fff;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.filtros-container .form-control:hover {
  border-color: var(--primary-light);
  background-color: #f8fafb;
}

.filtros-container .form-control:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(45, 106, 159, 0.15);
  outline: none;
}

.filtros-container .form-select {
  padding-right: 30px;
  background-size: 12px;
}

.filtros-container .btn-light {
  height: 36px;
  padding: 6px 14px;
  font-size: .85rem;
  font-weight: 500;
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.filtros-container .btn-light:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(30, 58, 95, 0.2);
}

.filtros-container .btn-light:active {
  transform: translateY(0);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Tablet grande */
@media (max-width: 1100px) {
  .dash-grid-4 {
    grid-template-columns: repeat(2, minmax(0, 260px));
  }

  .dash-grid-mid {
    grid-template-columns: minmax(0, 260px) 1fr;
  }

  .dash-grid-mid>*:last-child {
    grid-column: 1 / -1;
  }
}

/* Tablet / móvil grande */
@media (max-width: 900px) {
  .dash-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .dash-grid-mid {
    grid-template-columns: 1fr;
  }

  .dash-grid-2 {
    grid-template-columns: 1fr;
  }

  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
    width: 100%;
  }

  .sidebar-toggle {
    display: flex !important;
  }

  .sidebar-close {
    display: block;
  }

  .login-left {
    display: none;
  }

  .page-content {
    padding: 16px;
  }

  .filtros-container {
    flex-direction: column;
    align-items: stretch;
  }

  .filtro-group {
    min-width: 100%;
  }
}

/* Móvil */
@media (max-width: 600px) {
  .dash-grid-4 {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .dash-accesos {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .stat-value,
  .stat-num {
    font-size: 1.4rem !important;
  }

  .topbar {
    height: auto;
    padding: 10px 16px;
    flex-direction: row;
    /* Volvemos a fila para que el botón de menú y título queden arriba */
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .topbar-left {
    flex: 1;
    min-width: 150px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }

  .card-header {
    padding: 12px 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .card-header .topbar-actions {
    width: 100%;
    border-top: none;
    padding-top: 0;
  }

  /* Ajuste de tablas para móvil */
  .table-wrapper {
    margin: 0 -16px;
    /* Pegar a los bordes en móvil */
    width: calc(100% + 32px);
    border-radius: 0;
  }
}

/* ============================================================
   SIDEBAR OVERLAY (móvil — al abrir el menú)
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 99;
}

@media (max-width: 900px) {
  .sidebar-overlay.active {
    display: block;
  }
}

/* ============================================================
   SIDEBAR TOGGLE — visible en TODAS las páginas en móvil
   El botón ya está en app.js; aseguramos el estilo
   ============================================================ */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--text);
  cursor: pointer;
  margin-right: 12px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.sidebar-toggle:hover {
  background: rgba(0, 0, 0, .06);
}