:root {
  --primary-color: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary-color: #64748b;
  --success-color: #059669;
  --warning-color: #d97706;
  --danger-color: #dc2626;
  --dark-color: #1e293b;
  --light-color: #f8fafc;
  --border-color: #e2e8f0;
  --text-color: #334155;
  --text-muted: #64748b;
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-color);
  background-color: var(--light-color);
  margin: 0;
  padding: 0;
}

/* Layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  margin: 0 -0.5rem;
}

.col {
  flex: 1;
  padding: 0 0.5rem;
}

.col-2 { flex: 0 0 16.666667%; }
.col-3 { flex: 0 0 25%; }
.col-4 { flex: 0 0 33.333333%; }
.col-6 { flex: 0 0 50%; }
.col-8 { flex: 0 0 66.666667%; }
.col-9 { flex: 0 0 75%; }
.col-12 { flex: 0 0 100%; }

/* Header */
.header {
  background: white;
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 0;
  margin-bottom: 2rem;
}

.header h1 {
  margin: 0;
  color: var(--primary-color);
  font-size: 1.5rem;
  font-weight: 600;
}

/* Navigation */
.nav {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 1rem;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  transition: all 0.2s;
}

.nav-link:hover, .nav-link.active {
  color: var(--primary-color);
  background-color: var(--light-color);
}

/* Cards */
.card {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.5rem;
  background-color: var(--light-color);
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
}

.card-body {
  padding: 1.5rem;
}

.card-footer {
  padding: 1rem 1.5rem;
  background-color: var(--light-color);
  border-top: 1px solid var(--border-color);
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text-color);
}

.form-control {
  display: block;
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text-color);
  background-color: white;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control:focus {
  border-color: var(--primary-color);
  outline: 0;
  box-shadow: 0 0 0 0.25rem rgba(37, 99, 235, 0.25);
}

.form-control.is-invalid {
  border-color: var(--danger-color);
}

.form-select {
  /* Hide native dropdown arrow to avoid double arrows */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23343a40' 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 0.75rem center;
  background-size: 16px 12px;
  padding-right: 2.5rem;
}

/* Hide dropdown arrow in legacy Edge/IE */
select.form-select::-ms-expand {
  display: none;
}

.invalid-feedback {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: var(--danger-color);
}

.was-validated .form-control:invalid {
  border-color: var(--danger-color);
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.5;
  text-align: center;
  text-decoration: none;
  vertical-align: middle;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 0.375rem;
  transition: all 0.2s ease-in-out;
  user-select: none;
}

.btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.btn-primary {
  color: white;
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

.btn-primary:hover {
  background-color: var(--primary-dark);
  border-color: var(--primary-dark);
}

.btn-secondary {
  color: white;
  background-color: var(--secondary-color);
  border-color: var(--secondary-color);
}

.btn-success {
  color: white;
  background-color: var(--success-color);
  border-color: var(--success-color);
}

.btn-danger {
  color: white;
  background-color: var(--danger-color);
  border-color: var(--danger-color);
}

.btn-outline-primary {
  color: var(--primary-color);
  border-color: var(--primary-color);
  background-color: transparent;
}

.btn-outline-primary:hover {
  color: white;
  background-color: var(--primary-color);
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

/* Alerts */
.alert {
  position: relative;
  padding: 1rem;
  margin-bottom: 1rem;
  border: 1px solid transparent;
  border-radius: 0.375rem;
}

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

.alert-success {
  color: #0f5132;
  background-color: #d1e7dd;
  border-color: #badbcc;
}

.alert-warning {
  color: #664d03;
  background-color: #fff3cd;
  border-color: #ffecb5;
}

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

.alert-dismissible {
  padding-right: 3rem;
}

.btn-close {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
  padding: 1.25rem 1rem;
  background: transparent;
  border: 0;
  cursor: pointer;
}

/* Alternate color variants to highlight new alerts */
.alert.alt { border-width: 2px; }
.alert-info.alt { background-color: #cfe7ed; border-color: #b9dbe4; }
.alert-success.alt { background-color: #c7e3d6; border-color: #a9d2bf; }
.alert-warning.alt { background-color: #ffe6a1; border-color: #ffdd87; }
.alert-danger.alt { background-color: #f3c1c7; border-color: #eaaab2; }

/* Tables */
.table {
  width: 100%;
  margin-bottom: 1rem;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 0.75rem;
  vertical-align: top;
  border-top: 1px solid var(--border-color);
  text-align: left;
}

.table thead th {
  vertical-align: bottom;
  border-bottom: 2px solid var(--border-color);
  font-weight: 600;
  color: var(--text-color);
}

.table-striped tbody tr:nth-of-type(odd) {
  background-color: rgba(0, 0, 0, 0.05);
}

/* Utilities */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary-color); }
.text-success { color: var(--success-color); }
.text-danger { color: var(--danger-color); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }

.d-none { display: none; }
.d-block { display: block; }
.d-flex { display: flex; }

.justify-content-between { justify-content: space-between; }
.align-items-center { align-items: center; }

.spinner-border {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  vertical-align: text-bottom;
  border: 0.125em solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spinner-border 0.75s linear infinite;
}

.spinner-border-sm {
  width: 0.75rem;
  height: 0.75rem;
  border-width: 0.1em;
}

@keyframes spinner-border {
  to {
    transform: rotate(360deg);
  }
}

/* Responsive */
@media (max-width: 768px) {
  .col-md-6 { flex: 0 0 50%; }
  .col-md-12 { flex: 0 0 100%; }
  
  .btn {
    width: 100%;
    margin-bottom: 0.5rem;
  }
  
  .table-responsive {
    overflow-x: auto;
  }
}

/* Background color utilities */
.bg-primary { background-color: var(--primary-color) !important; color: white; }
.bg-success { background-color: var(--success-color) !important; color: white; }
.bg-info { background-color: #17a2b8 !important; color: white; }
.bg-warning { background-color: var(--warning-color) !important; color: white; }
.bg-danger { background-color: var(--danger-color) !important; color: white; }
.bg-secondary { background-color: var(--secondary-color) !important; color: white; }
.bg-dark { background-color: var(--dark-color) !important; color: white; }
.bg-light { background-color: var(--light-color) !important; color: var(--text-color); }

/* Sidebar Styles */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 250px;
  height: 100vh;
  background: white;
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  z-index: 1000;
  padding-top: 5rem; /* Espacio para el header */
}

.sidebar-nav {
  padding: 1rem 0;
}

.sidebar-menu {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-item {
  margin: 0;
}

.sidebar-link {
  display: flex;
  align-items: center;
  padding: 0.75rem 1.5rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.2s;
  gap: 0.75rem;
}

.sidebar-link:hover {
  background-color: var(--light-color);
  color: var(--primary-color);
}

.sidebar-item.active .sidebar-link {
  background-color: var(--primary-color);
  color: white;
}

.sidebar-icon {
  font-size: 1.2rem;
  width: 1.5rem;
  text-align: center;
}

.sidebar-text {
  font-weight: 500;
}

/* Main content with sidebar */
.main-content {
  margin-left: 250px;
  /* Ensure content is not hidden behind fixed header */
  padding-top: 5rem;
}

/* Header with sidebar */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1001;
  margin-bottom: 0;
}

.header .container {
  margin-left: 250px;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
  }
  
  .sidebar.show {
    transform: translateX(0);
  }
  
  .main-content {
    margin-left: 0;
    padding-top: 5rem; /* maintain clearance for fixed header */
  }
  
  .header .container {
    margin-left: 0;
  }
}

/* Compact modal styles (apply across admin) */
body .modal {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background-color: rgba(0,0,0,0.5);
  z-index: 2000 !important; /* Above fixed header (1001) and sidebar (1000) */
}

/* Use high specificity and !important to override page-local styles */
body .modal-dialog {
  position: relative;
  margin: 10px auto !important;
  max-width: 860px !important;
  width: 98% !important;
}

body .modal-content {
  background: #fff;
  border-radius: 6px !important;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}

body .modal-header,
body .modal-footer {
  padding: 0.5rem 0.75rem !important;
  border-color: var(--border-color) !important;
}

body .modal-body {
  padding: 0.75rem !important;
  max-height: calc(100vh - 140px) !important;
  overflow-y: auto !important;
}

/* Tighter typography and controls inside modals */
body .modal .modal-title {
  font-size: 1rem !important;
  line-height: 1.2 !important;
}

body .modal .form-group { margin-bottom: 0.5rem !important; }
body .modal .form-label { margin-bottom: 0.35rem !important; font-weight: 600; }
body .modal .form-control,
body .modal .form-select {
  padding: 0.5rem 0.6rem !important;
  font-size: 0.9rem !important;
  line-height: 1.2 !important;
}

body .modal .btn { padding: 0.4rem 0.8rem !important; font-size: 0.9rem !important; }
body .modal .btn-sm { padding: 0.3rem 0.6rem !important; font-size: 0.85rem !important; }

/* Close button */
body .modal .btn-close {
  font-size: 1.1rem !important;
  padding: 0.25rem 0.4rem !important;
}

/* Compact table in modals (if any) */
body .modal .table th,
body .modal .table td { padding: 0.5rem !important; }

/* Two-column layout helpers for forms inside modals */
body .modal .row {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 0.5rem 0.75rem !important;
  margin: 0 !important;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 0.75rem;
}

.col-span-2 {
  grid-column: 1 / -1 !important;
}

/* Make large elements span both columns by default */
body .modal textarea,
body .modal .col-12,
body .modal .w-100 { grid-column: 1 / -1 !important; }