/* ===== CSS Custom Properties ===== */
:root {
  --sidebar-width: 260px;
  --sidebar-bg: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-text-hover: #f1f5f9;
  --sidebar-active-bg: rgba(99, 102, 241, 0.15);
  --sidebar-active-text: #818cf8;
  --sidebar-heading: #64748b;
  --topbar-bg: #ffffff;
  --topbar-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --body-bg: #f1f5f9;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.1);
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 0.75rem;
  --radius-sm: 0.5rem;
  --transition: 0.2s ease;
}

/* ===== Base ===== */
html {
  font-size: 14px;
  position: relative;
  min-height: 100%;
}

@media (min-width: 768px) {
  html {
    font-size: 15px;
  }
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--body-bg);
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1040;
  overflow-y: auto;
  transition: transform var(--transition);
}

.sidebar-brand {
  color: #fff;
}

.sidebar-brand i {
  color: var(--accent);
}

.sidebar-heading {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--sidebar-heading);
}

.sidebar-link {
  color: var(--sidebar-text) !important;
  font-size: 0.875rem;
  font-weight: 400;
  padding: 0.45rem 0.75rem !important;
  border-radius: var(--radius-sm) !important;
  transition: all var(--transition);
  display: flex;
  align-items: center;
}

.sidebar-link:hover {
  color: var(--sidebar-text-hover) !important;
  background: rgba(255, 255, 255, 0.06);
}

.sidebar-link.active,
.sidebar-link[aria-current="page"] {
  color: var(--sidebar-active-text) !important;
  background: var(--sidebar-active-bg);
  font-weight: 500;
}

.sidebar-link i {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  opacity: 0.7;
}

.sidebar-link:hover i,
.sidebar-link.active i {
  opacity: 1;
}

/* ===== Sidebar year selector ===== */
.sidebar-year {
  background: rgba(0, 0, 0, 0.12);
}

.sidebar-year-select {
  background-color: rgba(255, 255, 255, 0.08) !important;
  color: #f1f5f9 !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
  font-size: 0.875rem;
  font-weight: 500;
}

.sidebar-year-select:focus {
  background-color: rgba(255, 255, 255, 0.12) !important;
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.25) !important;
}

.sidebar-year-select option {
  background: var(--sidebar-bg);
  color: #f1f5f9;
}

/* ===== Main content area ===== */
#main-content {
  margin-left: var(--sidebar-width);
  transition: margin-left var(--transition);
  min-width: 0;
  overflow-x: hidden;
}

/* ===== Topbar ===== */
.topbar {
  background: var(--topbar-bg);
  box-shadow: var(--topbar-shadow);
  min-height: 52px;
  position: sticky;
  top: 0;
  z-index: 1020;
  flex-shrink: 0;
  overflow: hidden;
}

.topbar .breadcrumb-item a {
  color: var(--accent);
}

/* ===== Page header ===== */
.page-header {
  margin-bottom: 1.5rem;
}

.page-header h2 {
  font-weight: 700;
  font-size: 1.5rem;
  color: #1e293b;
  margin: 0;
}

.page-header p {
  color: #64748b;
  margin: 0.25rem 0 0;
}

/* ===== Cards ===== */
.card {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  transition: box-shadow var(--transition);
  background: #fff;
}

.card:hover {
  box-shadow: var(--card-shadow-hover);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid #e2e8f0;
  font-weight: 600;
  padding: 1rem 1.25rem;
}

/* ===== Tables ===== */
.table-modern {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 0.875rem;
}

.table-modern thead th {
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}

.table-modern tbody td {
  padding: 0.65rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
}

.table-modern tbody tr {
  transition: background var(--transition);
}

.table-modern tbody tr:hover {
  background: #f8fafc;
}

.table-modern tbody tr:last-child td {
  border-bottom: none;
}

.table-modern tbody tr.row-inactive {
  background-color: #f1f5f9;
}

.table-modern tbody tr.row-selectable {
  cursor: pointer;
}

.table-modern tbody tr.row-selected {
  background: rgba(99, 102, 241, 0.1);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ===== Document thumbnails ===== */
.doc-thumbnail {
  max-width: 100%;
  max-height: 120px;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid #e2e8f0;
}

#docPreview .doc-thumbnail {
  max-height: 200px;
}

.doc-pdf-preview {
  width: 100%;
  height: 400px;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
}

/* ===== Viewer modal ===== */
.viewer-img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  padding: 1rem;
}

.viewer-pdf {
  width: 100%;
  height: 80vh;
  border: none;
}

.viewer-iframe {
  width: 100%;
  height: 80vh;
  border: none;
}

.viewer-excel {
  text-align: left;
}

.excel-table-wrapper {
  overflow: auto;
  max-height: 70vh;
}

.excel-table-wrapper table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.8125rem;
  font-family: 'Segoe UI', Calibri, Arial, sans-serif;
}

.excel-table-wrapper th,
.excel-table-wrapper td {
  border: 1px solid #d5d8dc;
  padding: 3px 6px;
  white-space: nowrap;
  min-width: 60px;
}

.excel-table-wrapper tr:first-child td,
.excel-table-wrapper tr:first-child th {
  background: #e9ecef;
  font-weight: 600;
  color: #333;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 1;
}

.excel-table-wrapper tr td:first-child {
  background: #f1f3f5;
  color: #555;
  text-align: center;
  font-weight: 500;
  min-width: 40px;
}

.excel-table-wrapper tr:hover td {
  background-color: rgba(99, 102, 241, 0.04);
}

.excel-table-wrapper tr:hover td:first-child {
  background: #e2e6ea;
}

/* ===== Drop zone ===== */
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.5rem;
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius);
  background: #f8fafc;
  color: #64748b;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.drop-zone:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.04);
}

.drop-zone-over {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.08);
}

.drop-zone-has-file {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.06);
  color: #334155;
}

.drop-zone-icon {
  font-size: 1.75rem;
}

.drop-zone-input {
  display: none;
}

/* ===== Buttons ===== */
.btn {
  font-weight: 500;
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
  padding: 0.4rem 1rem;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
}

.btn-success:hover {
  background: #059669;
  border-color: #059669;
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
}

.btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
  transform: translateY(-1px);
}

.btn-warning {
  background: var(--warning);
  border-color: var(--warning);
  color: #fff;
}

.btn-warning:hover {
  background: #d97706;
  border-color: #d97706;
  color: #fff;
  transform: translateY(-1px);
}

.btn-outline-secondary {
  border-color: #cbd5e1;
  color: #475569;
}

.btn-outline-secondary:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
  color: #1e293b;
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.25);
}

/* ===== Forms ===== */
.form-control, .form-select {
  border-radius: var(--radius-sm);
  border: 1px solid #cbd5e1;
  font-size: 0.875rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.15);
}

.form-label {
  font-weight: 500;
  font-size: 0.8125rem;
  color: #475569;
  margin-bottom: 0.35rem;
}

/* ===== Action toolbar ===== */
.action-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

/* ===== Badges ===== */
.badge-status {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.3em 0.6em;
  border-radius: 50rem;
}

/* ===== Section card (for wrapping page content) ===== */
.section-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.section-card .section-title {
  font-weight: 600;
  font-size: 0.9375rem;
  color: #1e293b;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-card .section-title i {
  color: var(--accent);
}

/* ===== Footer ===== */
.app-footer {
  background: #fff;
  border-top: 1px solid #e2e8f0;
}

/* ===== Scrollbar ===== */
.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

/* ===== Progress bar ===== */
.progress {
  height: 0.6rem;
  border-radius: 50rem;
  background: #e2e8f0;
}

.progress-bar {
  background: linear-gradient(90deg, var(--accent), #818cf8);
  border-radius: 50rem;
}

/* ===== Responsive ===== */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.show {
    transform: translateX(0);
  }

  #main-content {
    margin-left: 0;
  }
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

main .container-fluid > * {
  animation: fadeIn 0.3s ease;
}

/* ===== Nav tabs modern ===== */
.nav-tabs .nav-link {
  font-weight: 500;
  font-size: 0.875rem;
  color: #64748b;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.6rem 1rem;
}

.nav-tabs .nav-link:hover {
  color: var(--accent);
  border-bottom-color: #c7d2fe;
}

.nav-tabs .nav-link.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: transparent;
}

/* ===== Home page cards ===== */
.home-card {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  transition: all 0.3s ease;
  overflow: hidden;
}

.home-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--card-shadow-hover);
}

.home-card .card-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  margin-bottom: 0.75rem;
}

.home-card .card-icon.bg-accent {
  background: rgba(99, 102, 241, 0.1);
  color: var(--accent);
}

.home-card .card-icon.bg-success-soft {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
}

.home-card .card-icon.bg-warning-soft {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning);
}

/* ===== Dropdown menu ===== */
.dropdown-menu {
  border: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  border-radius: var(--radius-sm);
}

/* ===== List group modern ===== */
.list-group-item {
  border-color: #f1f5f9;
}

/* ===== Backdrop for mobile sidebar ===== */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1035;
  display: none;
}

.sidebar-backdrop.show {
  display: block;
}

/* ===== Treeview Agrupaciones ===== */
.tree-view {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-group {
  margin-bottom: 0.5rem;
}

.tree-group-header {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.4rem;
  transition: background 0.15s;
}
.tree-group-header:hover {
  background: #f3f4f6;
}

.tree-group-name {
  font-weight: 600;
  margin-left: 0.5rem;
}

.tree-count {
  color: #888;
  font-size: 0.85em;
  margin-left: 0.5rem;
}

.tree-children {
  list-style: none;
  margin: 0;
  padding-left: 4rem;
  margin-top: 0.25rem;
}

.tree-item {
  display: flex;
  align-items: center;
  padding: 0.15rem 0.5rem 0.15rem 0.5rem;
  border-radius: 0.3rem;
  margin-bottom: 2px;
  cursor: grab;
  transition: background 0.15s;
}
.tree-item:hover {
  background: #f1f5f9;
}