/*
 * app.css — Estilos del layout principal: sidebar, topbar, contenido.
 * Importar DESPUÉS de theme.css.
 */

/* ═══════════════════════════════════════════════════
   LAYOUT SHELL (sidebar + topbar + main)
════════════════════════════════════════════════════ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 200;
  transition: width var(--transition-normal), transform var(--transition-normal);
  overflow: hidden;
}
.sidebar.collapsed { width: var(--sidebar-collapsed-width); }

/* Overlay móvil */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 199;
}
.sidebar-overlay.active { display: block; }

/* Logo / brand */
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border-color);
  text-decoration: none;
  overflow: hidden;
  flex-shrink: 0;
}
.sidebar__brand-icon {
  width: 36px;
  height: 36px;
  background: var(--color-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}
.sidebar__brand-icon svg { width: 20px; height: 20px; }
.sidebar__brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--text-primary);
  white-space: nowrap;
  opacity: 1;
  transition: opacity var(--transition-fast);
}
.sidebar.collapsed .sidebar__brand-name { opacity: 0; pointer-events: none; }

/* Nav items */
.sidebar__nav { flex: 1; padding: 1rem 0; overflow-y: auto; overflow-x: hidden; }

.sidebar__section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.5rem 1.25rem;
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity var(--transition-fast);
}
.sidebar.collapsed .sidebar__section-label { opacity: 0; }

.sidebar__nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 1.25rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: 0;
  position: relative;
  transition: color var(--transition-fast), background-color var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  margin: 1px 0.5rem;
  border-radius: var(--radius-md);
}
.sidebar__nav-item:hover {
  color: var(--color-primary);
  background-color: var(--color-primary-light);
}
.sidebar__nav-item.active {
  color: var(--color-primary);
  background-color: var(--color-primary-light);
  font-weight: 600;
}
.sidebar__nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--color-primary);
  border-radius: 0 2px 2px 0;
}
.sidebar__nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.sidebar__nav-label {
  opacity: 1;
  transition: opacity var(--transition-fast);
}
.sidebar.collapsed .sidebar__nav-label { opacity: 0; }

/* Badge de notificación en nav */
.sidebar__nav-badge {
  margin-left: auto;
  background: var(--color-danger);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
  opacity: 1;
  transition: opacity var(--transition-fast);
}
.sidebar.collapsed .sidebar__nav-badge { opacity: 0; }

/* Footer del sidebar (usuario logueado) */
.sidebar__footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  overflow: hidden;
  flex-shrink: 0;
}
.sidebar__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar__avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar__user-info { overflow: hidden; opacity: 1; transition: opacity var(--transition-fast); }
.sidebar.collapsed .sidebar__user-info { opacity: 0; }
.sidebar__user-name { font-size: 0.875rem; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user-role { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }

/* ── Topbar ──────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar__toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.topbar__toggle:hover { background: var(--bg-elevated); color: var(--text-primary); }
.topbar__toggle svg { width: 22px; height: 22px; }

.topbar__breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  overflow: hidden;
  flex: 1;
}
.topbar__breadcrumb a { color: var(--text-secondary); text-decoration: none; white-space: nowrap; }
.topbar__breadcrumb a:hover { color: var(--color-primary); }
.topbar__breadcrumb .sep { color: var(--border-color); }
.topbar__breadcrumb .current { color: var(--text-primary); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar__spacer { flex: 1; }

/* Reloj */
.topbar__clock {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-muted);
  white-space: nowrap;
  display: none;
}
@media (min-width: 768px) { .topbar__clock { display: block; } }

/* Indicador online/offline */
.topbar__sync {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--color-success-light);
  color: var(--color-success);
  white-space: nowrap;
}
.topbar__sync.offline {
  background: var(--color-warning-light);
  color: var(--color-warning);
}
.topbar__sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.topbar__sync.online .topbar__sync-dot { animation: pulse-dot 2s ease infinite; }
@keyframes pulse-dot {
  0%,100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Botones de acción en topbar */
.topbar__action {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  position: relative;
  text-decoration: none;
}
.topbar__action:hover { background: var(--bg-elevated); color: var(--text-primary); }
.topbar__action svg { width: 20px; height: 20px; }

/* Toggle idioma */
.lang-toggle {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.lang-toggle:hover { border-color: var(--color-primary); color: var(--color-primary); }

/* ── Área principal ───────────────────────────────── */
.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition-normal);
}
.app-main.sidebar-collapsed { margin-left: var(--sidebar-collapsed-width); }

.page-content {
  flex: 1;
  padding: 1.75rem 1.5rem;
}

/* ── Page Header ─────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}
.page-header__title { font-size: 1.5rem; font-weight: 700; }
.page-header__sub   { font-size: 0.9375rem; color: var(--text-muted); margin-top: 0.25rem; }
.page-header__actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }

/* ── Tablas ──────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}
.table thead th {
  padding: 0.875rem 1rem;
  text-align: left;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}
.table tbody tr {
  border-bottom: 1px solid var(--border-color);
  transition: background-color var(--transition-fast);
}
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background-color: var(--bg-elevated); }
.table tbody td {
  padding: 0.875rem 1rem;
  color: var(--text-primary);
  vertical-align: middle;
}
.table td.text-muted { color: var(--text-muted); }
.table .actions-cell { white-space: nowrap; text-align: right; }
.table .actions-cell .btn { padding: 5px 10px; font-size: 0.8125rem; }

/* ── Filtros / buscador ───────────────────────────── */
.filter-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  align-items: flex-end;
}
.filter-bar .form-control { max-width: 240px; }

/* ── Tabs de configuración ────────────────────────── */
.config-tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 2rem;
  overflow-x: auto;
}
.config-tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all var(--transition-fast);
}
.config-tab:hover { color: var(--color-primary); }
.config-tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.config-tab svg { width: 18px; height: 18px; }

/* ── Stats / KPI cards ────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  min-width: 0;
}
.stat-card__icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-card__icon svg { width: 22px; height: 22px; }
.stat-card__body { min-width: 0; flex: 1; }
.stat-card__value {
  font-size: clamp(1.125rem, 2vw, 1.5rem);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-card__label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  line-height: 1.3;
}

/* ── Color swatch ──────────────────────────────────── */
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-color);
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ── Barra de uso resolución DIAN ─────────────────── */
.resolution-bar {
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  overflow: hidden;
  margin-top: 4px;
}
.resolution-bar__fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-success);
  transition: width 0.4s ease;
}
.resolution-bar__fill.warning { background: var(--color-warning); }
.resolution-bar__fill.danger  { background: var(--color-danger); }

/* ── Empty state ──────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}
.empty-state svg {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  opacity: 0.35;
}
.empty-state h3 { font-size: 1.125rem; margin-bottom: 0.5rem; color: var(--text-secondary); }
.empty-state p  { font-size: 0.9375rem; }

/* ── Form layout 2 columnas ───────────────────────── */
.form-grid { display: grid; gap: 1.25rem; }
.form-grid-2 { grid-template-columns: repeat(2, 1fr); }
.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
.col-span-2  { grid-column: span 2; }
.col-span-3  { grid-column: span 3; }
@media (max-width: 767px) {
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .col-span-2, .col-span-3  { grid-column: span 1; }
}

/* ── Responsive sidebar ───────────────────────────── */
@media (max-width: 1023px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }
  .app-main { margin-left: 0 !important; }
}

/* ── Modal ────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fade-in var(--transition-normal) forwards;
}
.modal {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 480px;
  animation: modal-in var(--transition-normal) forwards;
  overflow: hidden;
}
.modal-lg { max-width: 680px; }
.modal__header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal__title { font-size: 1.125rem; font-weight: 600; }
.modal__close {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal__close:hover { background: var(--bg-elevated); color: var(--text-primary); }
.modal__close svg { width: 18px; height: 18px; }
.modal__body   { padding: 1.5rem; }
.modal__footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

@keyframes fade-in { from { opacity:0 } to { opacity:1 } }
@keyframes modal-in {
  from { opacity:0; transform: scale(0.94) translateY(8px); }
  to   { opacity:1; transform: scale(1)    translateY(0); }
}
