/* ========================================================================
   APP.CSS — Diseño Moderno y Profesional (Quipu-inspired)
   ======================================================================== */

:root {
  /* Colores Modernos */
  --primary: #0d47a1;              /* Azul marino profundo */
  --primary-light: #1565c0;
  --primary-dark: #0a3d91;
  --accent: #00bcd4;               /* Cyan/Turquesa moderno */
  --accent-light: #26c6da;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #f44336;
  
  /* Neutrales mejorados */
  --bg: #f5f5f5;
  --bg-light: #fafafa;
  --surface: #ffffff;
  --surface-hover: #f8f9fa;
  --border: #e0e0e0;
  --border-light: #eeeeee;
  --text: #212121;
  --text-muted: #757575;
  --text-light: #9e9e9e;
  
  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;
  --space-3xl: 48px;
  
  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 999px;
  
  /* Shadows mejorados */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.12);
  --shadow-xl: 0 12px 24px rgba(0, 0, 0, 0.15);
  
  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  --font-mono: "Menlo", "Monaco", "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  line-height: 1.6;
  font-weight: 400;
}

/* ========================================================================
   HEADER
   ======================================================================== */

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  padding: var(--space-md) var(--space-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: var(--space-md);
  box-shadow: var(--shadow-xs);
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.95);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand span.cb {
  font-weight: 700;
  color: var(--primary);
  background: none;
  -webkit-background-clip: unset;
  -webkit-text-fill-color: unset;
  background-clip: unset;
}

.brand span.tech {
  font-weight: 600;
  color: var(--accent);
  background: none;
  -webkit-background-clip: unset;
  -webkit-text-fill-color: unset;
  background-clip: unset;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tag {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: rgba(13, 71, 161, 0.08);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.toolbar-right {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  align-items: center;
}

/* ========================================================================
   MAIN LAYOUT
   ======================================================================== */

main {
  flex: 1;
  display: flex;
  gap: var(--space-xl);
  padding: var(--space-xl);
  overflow: hidden;
}

.layout {
  display: flex;
  gap: var(--space-xl);
  width: 100%;
}

/* ========================================================================
   SIDEBAR
   ======================================================================== */

.sidebar {
  width: 260px;
  flex: 0 0 260px;
  display: flex;
  flex-direction: column;
}

.sidebar-inner {
  position: sticky;
  top: 74px;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  background: var(--surface);
  padding: var(--space-lg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.sidebar-link {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-muted);
  background: transparent;
  border: none;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  position: relative;
}

.sidebar-link:hover {
  background: var(--surface-hover);
  color: var(--primary);
  padding-left: calc(var(--space-lg) + 4px);
}

.sidebar-link.active {
  background: linear-gradient(90deg, rgba(13, 71, 161, 0.1), transparent);
  color: var(--primary);
  font-weight: 600;
  border-left: 3px solid var(--primary);
  padding-left: calc(var(--space-lg) - 3px);
}

.sidebar-section-title {
  padding: var(--space-lg) var(--space-lg) var(--space-sm) var(--space-lg);
  margin-top: var(--space-md);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-light);
  letter-spacing: 0.5px;
  border-top: 1px solid var(--border-light);
}

.sidebar-section-title:first-child {
  border-top: none;
  margin-top: 0;
}

/* ========================================================================
   CONTENT AREA
   ======================================================================== */

.tab-content {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  padding: var(--space-xl);
  box-shadow: var(--shadow-md);
  overflow-y: auto;
  min-height: 400px;
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tab-content.content {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

/* ========================================================================
   TOOLBAR & GRID
   ======================================================================== */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-lg);
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--space-xl);
  border-bottom: 1px solid var(--border-light);
}

.toolbar-left,
.toolbar-right {
  display: flex;
  gap: var(--space-lg);
  flex-wrap: wrap;
  align-items: center;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--space-xl);
}

@media (min-width: 768px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1200px) {
  .grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1600px) {
  .grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ========================================================================
   BUTTONS
   ======================================================================== */

.btn {
  padding: var(--space-md) var(--space-lg);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-lg);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  text-decoration: none;
  line-height: 1;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.1);
  transform: translate(-50%, -50%);
  transition: width 0.5s, height 0.5s;
}

.btn:hover:not(:disabled)::before {
  width: 300px;
  height: 300px;
}

.btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-light);
  border-color: var(--primary-light);
  box-shadow: 0 4px 12px rgba(13, 71, 161, 0.3);
}

.btn-accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 600;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-light);
  border-color: var(--accent-light);
  box-shadow: 0 4px 12px rgba(0, 188, 212, 0.3);
}

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

.btn-danger:hover:not(:disabled) {
  background: rgba(244, 67, 54, 0.08);
}

.btn-icon {
  padding: var(--space-sm) var(--space-md);
  font-size: 13px;
}

.btn-sm {
  padding: var(--space-sm) var(--space-md);
  font-size: 12px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Variantes adicionales de botones */

.btn-secondary {
  background: var(--surface);
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--primary);
}

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

.btn-outline:hover:not(:disabled) {
  background: rgba(13, 71, 161, 0.05);
  border-color: var(--accent);
}

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

.btn-success:hover:not(:disabled) {
  background: #059669;
  border-color: #059669;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

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

.btn-warning:hover:not(:disabled) {
  background: #d97706;
  border-color: #d97706;
}

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

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
  border-color: #dc2626;
  box-shadow: 0 4px 12px rgba(244, 67, 54, 0.3);
}

/* Botones para tablas */
.btn-table {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: var(--radius-md);
}

.btn-edit {
  background: rgba(0, 188, 212, 0.1);
  color: #00bcd4;
  border-color: #00bcd4;
}

.btn-edit:hover:not(:disabled) {
  background: #00bcd4;
  color: white;
}

.btn-delete {
  background: rgba(244, 67, 54, 0.1);
  color: var(--danger);
  border-color: var(--danger);
}

.btn-delete:hover:not(:disabled) {
  background: var(--danger);
  color: white;
}

.btn-view {
  background: rgba(13, 71, 161, 0.1);
  color: var(--primary);
  border-color: var(--primary);
}

.btn-view:hover:not(:disabled) {
  background: var(--primary);
  color: white;
}

/* ========================================================================
   PANELS & CARDS
   ======================================================================== */

.panel {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.panel:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  border-color: var(--accent);
}

.panel-h {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.5), rgba(250, 250, 250, 0.5));
}

.panel-t {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  gap: var(--space-md);
  align-items: center;
}

.panel-b {
  padding: var(--space-lg);
}

/* ========================================================================
   PILLS & BADGES
   ======================================================================== */

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-full);
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  margin-right: var(--space-sm);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.pill.ok {
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.08);
  color: #047857;
}

.pill.warn {
  border-color: rgba(245, 158, 11, 0.3);
  background: rgba(245, 158, 11, 0.08);
  color: #92400e;
}

.pill.bad {
  border-color: rgba(244, 67, 54, 0.3);
  background: rgba(244, 67, 54, 0.08);
  color: #b71c1c;
}

.pill.danger {
  border-color: rgba(244, 67, 54, 0.3);
  background: rgba(244, 67, 54, 0.08);
  color: #b71c1c;
}

.pill.secondary {
  border-color: rgba(107, 114, 128, 0.3);
  background: rgba(107, 114, 128, 0.08);
  color: #374151;
}

.pill.info {
  border-color: rgba(59, 130, 246, 0.3);
  background: rgba(59, 130, 246, 0.08);
  color: #1e40af;
}

/* ========================================================================
   FORM INPUTS
   ======================================================================== */

.input,
.select,
.textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-md) var(--space-lg);
  outline: none;
  font-size: 14px;
  font-family: inherit;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(13, 71, 161, 0.08);
}

.input::placeholder {
  color: var(--text-light);
}

.textarea {
  resize: vertical;
  min-height: 100px;
  font-family: var(--font-mono);
}

/* ========================================================================
   TABLES
   ======================================================================== */

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 14px;
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table th {
  background: linear-gradient(135deg, rgba(13, 71, 161, 0.05), rgba(0, 188, 212, 0.05));
  border-bottom: 2px solid var(--border);
  padding: var(--space-md) var(--space-lg);
  text-align: left;
  font-weight: 600;
  color: var(--primary);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table td {
  border-bottom: 1px solid var(--border-light);
  padding: var(--space-md) var(--space-lg);
  color: var(--text);
}

.table tbody tr {
  transition: background-color 0.2s ease;
}

.table tbody tr:hover {
  background: var(--surface-hover);
}

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

/* ========================================================================
   UTILITIES
   ======================================================================== */

.tiny {
  font-size: 12px;
  color: var(--text-muted);
}

.muted-help {
  color: var(--text-muted);
  font-size: 13px;
  margin: var(--space-md) 0;
  line-height: 1.6;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: var(--space-xl) 0 var(--space-lg) 0;
  padding-bottom: var(--space-lg);
  border-bottom: 2px solid var(--border-light);
}

/* ========================================================================
   FOOTER
   ======================================================================== */

footer {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border-light);
  padding: var(--space-md) var(--space-xl);
  font-size: 12px;
  text-align: center;
  color: var(--text-muted);
  z-index: 10;
}

/* ========================================================================
   TOAST & ALERTS
   ======================================================================== */

.toast-container {
  position: fixed;
  right: var(--space-xl);
  bottom: 72px;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  z-index: 50;
}

.toast {
  min-width: 300px;
  max-width: 420px;
  background: var(--text);
  color: white;
  border-radius: var(--radius-lg);
  padding: var(--space-lg) var(--space-xl);
  font-size: 13px;
  box-shadow: var(--shadow-xl);
  display: flex;
  align-items: flex-start;
  gap: var(--space-lg);
  animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

@keyframes slideIn {
  from {
    transform: translateX(420px) scale(0.95);
    opacity: 0;
  }
  to {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
}

.toast-icon {
  flex: 0 0 auto;
  margin-top: 2px;
  font-size: 18px;
}

.toast-body {
  flex: 1;
}

.toast-title {
  font-weight: 600;
  margin-bottom: 4px;
}

/* ========================================================================
   DROPZONE
   ======================================================================== */

.dropzone {
  border: 2px dashed var(--primary);
  border-radius: var(--radius-lg);
  padding: var(--space-3xl) var(--space-xl);
  text-align: center;
  background: linear-gradient(135deg, rgba(13, 71, 161, 0.02), rgba(0, 188, 212, 0.02));
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-lg);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.dropzone:hover,
.dropzone.dragover {
  background: linear-gradient(135deg, rgba(13, 71, 161, 0.08), rgba(0, 188, 212, 0.08));
  border-style: solid;
  border-color: var(--accent);
  transform: scale(1.01);
}

.dropzone p {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.dropzone strong {
  color: var(--primary);
  font-weight: 700;
}

/* ========================================================================
   RESPONSIVE MOBILE FIRST
   ======================================================================== */

/* Tablets: 768px y menores */
@media (max-width: 768px) {
  :root {
    --space-lg: 12px;
    --space-xl: 18px;
    --space-2xl: 24px;
  }

  main {
    gap: var(--space-lg);
    padding: var(--space-lg);
  }

  /* Header responsive */
  header {
    padding: var(--space-md) var(--space-lg);
    flex-direction: column;
    gap: var(--space-lg);
  }

  .brand {
    font-size: 18px;
  }

  .header-right {
    width: 100%;
    gap: var(--space-md);
  }

  /* Sidebar responsive */
  .sidebar {
    width: 100%;
    flex: 1 1 auto;
  }

  .sidebar-inner {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--space-md);
  }

  .sidebar-nav {
    display: flex;
    flex-direction: row;
    gap: var(--space-sm);
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-link {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Grids responsive */
  .grid {
    grid-template-columns: 1fr;
    gap: var(--space-lg);
  }

  .grid[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Toolbar responsive */
  .toolbar {
    gap: var(--space-md);
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-left,
  .toolbar-right {
    width: 100%;
  }

  .toolbar-left {
    order: 1;
  }

  .toolbar-right {
    order: 2;
  }

  /* Tabla responsive - ocultar columnas no críticas */
  .table {
    font-size: 12px;
  }

  .table th,
  .table td {
    padding: var(--space-sm) var(--space-md);
  }

  /* Permitir scroll horizontal solo en tablas compactas (IVA, Retención) */
  .panel-b:has(.table-compact) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-compact {
    min-width: 100%;
  }

  /* Ocultar columna 4 en tablas normales (no-compact) para que botones sean visibles */
  .table:not(.table-compact) thead th:nth-child(4),
  .table:not(.table-compact) thead + tbody td:nth-child(4) {
    display: none;
  }

  /* Ajustar columna de acciones */
  .table th:nth-child(5),
  .table td:nth-child(5) {
    padding: var(--space-sm) var(--space-md);
  }

  /* Botones en tabla - hacer muy compactos */
  .btn-table {
    padding: 8px 6px;
    font-size: 11px;
    width: auto !important;
    flex: 0 0 auto;
    min-width: 38px;
    height: 38px;
    white-space: nowrap;
  }

  /* Flex container para botones - siempre en una línea */
  .table td div[style*="display: flex"] {
    flex-wrap: nowrap;
    gap: 4px;
  }

  /* Formularios responsive */
  .panel-b[style*="max-width: 600px"] {
    max-width: 100% !important;
  }

  /* Input fields más grandes para touch */
  .input {
    padding: 12px;
    font-size: 16px;
    min-height: 44px;
  }

  .input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 188, 212, 0.1);
  }

  /* Botones más grandes para touch */
  .btn {
    padding: 12px 16px;
    font-size: 14px;
    min-height: 44px;
    border-radius: var(--radius-lg);
  }

  .btn-primary,
  .btn-secondary {
    width: 100%;
  }

  /* Labels más legibles */
  label {
    font-size: 13px !important;
  }

  /* Ocultar información secundaria en cards */
  .muted-help {
    font-size: 12px;
  }

  /* Pills y tags */
  .pill,
  .tag {
    font-size: 11px;
    padding: 4px 8px;
  }

  /* Reduce font sizes for better mobile fit */
  h2 {
    font-size: 18px !important;
  }

  h3 {
    font-size: 13px !important;
  }
}

/* Teléfonos: 480px y menores */
@media (max-width: 480px) {
  :root {
    --space-md: 8px;
    --space-lg: 10px;
    --space-xl: 14px;
    --space-2xl: 20px;
  }

  main {
    padding: var(--space-md);
    gap: var(--space-md);
  }

  header {
    padding: var(--space-md);
    gap: var(--space-md);
  }

  .brand {
    font-size: 16px;
  }

  .brand .tech {
    display: none;
  }

  /* Esconder elementos no esenciales */
  .tag,
  .pill {
    display: none;
  }

  /* Toolbar muy simplificado */
  .toolbar {
    gap: var(--space-md);
  }

  .toolbar h2 {
    font-size: 16px !important;
  }

  .toolbar p {
    font-size: 12px;
  }

  /* Botones ocupan todo el ancho - EXCEPTO en tablas */
  .btn {
    width: 100%;
    padding: 12px;
    font-size: 13px;
  }

  /* Botones en tablas: muy pequeños y en línea */
  .btn-table {
    width: auto !important;
    padding: 5px 6px !important;
    font-size: 14px !important;
    min-width: 32px;
    height: 32px;
    flex: 0 0 auto;
  }

  /* Contenedor de botones: siempre en una línea */
  .table td div[style*="display: flex"] {
    flex-wrap: nowrap;
    gap: 4px !important;
  }

  /* Hacer tabla scrolleable en móvil - SOLO para tablas compactas (IVA, Retención) */
  .panel-b .table-compact {
    min-width: 100%;
  }

  .table-compact + .table-compact,
  .table-compact {
    display: table;
  }

  /* Para tablas compactas: permitir scroll en el contenedor padre */
  .panel-b:has(.table-compact) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Tabla aún más comprimida */
  .table {
    font-size: 11px;
  }

  /* Mantener widths mínimos en tablas para scroll (SOLO para table-compact) */
  .table-compact th,
  .table-compact td {
    padding: 8px 6px;
    white-space: nowrap;
    min-width: 80px;
  }

  .table-compact td:first-child,
  .table-compact th:first-child {
    min-width: 120px;
  }

  .table-compact td:last-child,
  .table-compact th:last-child {
    min-width: 110px;
    padding: 8px 4px;
  }

  /* Tablas normales: comprimidas, sin scroll */
  .table:not(.table-compact) {
    font-size: 11px;
  }

  /* Padding comprimido en tablas */
  .table:not(.table-compact) th,
  .table:not(.table-compact) td {
    padding: 6px 4px;
  }

  .table:not(.table-compact) td:last-child {
    padding: 6px 2px;
  }

  /* Ocultar columnas en tablas normales en 480px */
  .table:not(.table-compact) thead th:nth-child(2),
  .table:not(.table-compact) thead + tbody td:nth-child(2),
  .table:not(.table-compact) thead th:nth-child(3),
  .table:not(.table-compact) thead + tbody td:nth-child(3),
  .table:not(.table-compact) thead th:nth-child(4),
  .table:not(.table-compact) thead + tbody td:nth-child(4) {
    display: none;
  }

  /* Form spacing */
  .input {
    padding: 10px;
    font-size: 14px;
  }

  label {
    font-size: 11px !important;
    margin-bottom: 4px;
  }

  h3 {
    font-size: 12px !important;
    margin-bottom: 12px !important;
  }

  .grid[style*="gap:"] {
    gap: 8px !important;
  }

  /* Separator lines */
  div[style*="border-top:"] {
    margin: 16px 0 !important;
    padding-top: 16px !important;
  }
}

/* ========================================================================
   DARK MODE (OPCIONAL)
   ======================================================================== */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --bg-light: #1e1e1e;
    --surface: #1f1f1f;
    --surface-hover: #2a2a2a;
    --border: #404040;
    --border-light: #333333;
    --text: #e0e0e0;
    --text-muted: #9e9e9e;
    --text-light: #757575;
  }

  header {
    background: rgba(31, 31, 31, 0.95);
  }
}

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

@media (max-width: 1024px) {
  main {
    flex-direction: column;
    padding: var(--space-md);
    gap: var(--space-md);
  }

  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    gap: var(--space-md);
    overflow-x: auto;
  }

  .sidebar-inner {
    position: static;
    flex-direction: row;
    gap: var(--space-sm);
  }

  .sidebar-nav {
    flex-direction: row;
    gap: var(--space-sm);
  }

  .sidebar-link {
    padding: var(--space-sm) var(--space-md);
    font-size: 13px;
  }

  .tab-content {
    padding: var(--space-lg);
  }

  header {
    padding: var(--space-sm) var(--space-md);
  }

  .brand {
    font-size: 16px;
  }
}

@media (max-width: 768px) {
  header {
    flex-direction: column;
    gap: var(--space-sm);
  }

  .header-right {
    width: 100%;
    justify-content: flex-start;
  }

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

  .toolbar-left,
  .toolbar-right {
    width: 100%;
  }

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

  .btn {
    width: 100%;
  }

  .tab-content {
    padding: var(--space-md);
    border-radius: var(--radius-md);
  }
}

/* ========================================================================
   MISC UTILITIES
   ======================================================================== */

.file-input { 
  display: none; 
}

.mini-input { 
  border-radius: var(--radius-full); 
  border: 1px solid var(--border); 
  padding: var(--space-sm) var(--space-md); 
  font-size: 12px; 
  min-width: 240px; 
}

.mini-num { 
  border-radius: var(--radius-full); 
  border: 1px solid var(--border); 
  padding: var(--space-sm) var(--space-md); 
  font-size: 12px; 
  width: 110px; 
}

select.mini-input { 
  appearance: auto; 
}

textarea.out { 
  width: 100%; 
  resize: vertical; 
  border: 1px solid var(--border); 
  border-radius: var(--radius-lg); 
  padding: var(--space-lg); 
  font-size: 12px; 
  line-height: 1.45; 
  font-family: var(--font-mono); 
  background: var(--surface); 
  color: var(--text); 
}

