/* ══════════════════════════════════════════════
   Conciliador POS — Design System
   Inspired by Mercado Pago seller panel
   White · Indigo · Flat surfaces · Subtle borders
   ══════════════════════════════════════════════ */

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

:root {
  /* ── Indigo: acciones y estado activo ── */
  --primary:        #3b5afe;
  --primary-dark:   #2d45d6;
  --primary-light:  #eef1ff;
  --primary-rgb:    59, 90, 254;

  /* Aliases para compatibilidad con var() existentes */
  --primary-50:  #eef1ff;
  --primary-100: #dde3ff;
  --primary-200: #c0caff;
  --primary-400: #7b8eff;
  --primary-500: #3b5afe;
  --primary-600: #3b5afe;
  --primary-700: #2d45d6;

  /* ── Amarillo: solo acento puntual ── */
  --accent:      #ffe600;
  --accent-dark: #f0d800;
  --accent-text: #1a1a1a;

  /* ── Fondos ── */
  --bg-primary:   #ffffff;
  --bg-secondary: #f7f7f7;
  --bg-hover:     #f5f6ff;

  /* ── Texto ── */
  --text-primary:    #1a1a1a;
  --text-secondary:  #4f4f4f;
  --text-muted:      #8c8c8c;
  --text-on-primary: #ffffff;

  /* ── Neutrals (alias gray-*) ── */
  --gray-25:  #fefefe;
  --gray-50:  #f7f7f7;
  --gray-100: #f0f0f0;
  --gray-200: #e5e5e5;
  --gray-300: #d4d4d4;
  --gray-400: #8c8c8c;
  --gray-500: #8c8c8c;
  --gray-600: #4f4f4f;
  --gray-700: #4f4f4f;
  --gray-800: #1a1a1a;
  --gray-900: #1a1a1a;

  /* ── Bordes: la separación se da con bordes, no con sombras ── */
  --border:        #e5e5e5;
  --border-light:  #f0f0f0;
  --border-strong: #d4d4d4;

  /* ── Estados: par -light (fondo) y -dark (texto) ── */
  --success:        #00a650;
  --success-light:  #e5f5ec;
  --success-dark:   #008c44;
  --success-50:     #e5f5ec;
  --success-500:    #00a650;
  --success-700:    #008c44;

  --error:          #f23d4f;
  --error-light:    #fdeaec;
  --error-dark:     #d32637;
  --error-50:       #fdeaec;
  --error-500:      #f23d4f;
  --error-700:      #d32637;

  --warning:        #ffa000;
  --warning-light:  #fff4e0;
  --warning-dark:   #e08e00;
  --warning-50:     #fff4e0;
  --warning-500:    #ffa000;
  --warning-700:    #e08e00;

  --info:           #3b5afe;
  --info-light:     #eef1ff;
  --info-dark:      #2d45d6;
  --info-50:        #eef1ff;
  --info-500:       #3b5afe;
  --info-700:       #2d45d6;

  /* ── Sombras: solo para capas flotantes ── */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.03);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.03);
  --shadow-md: 0 2px 6px rgba(0,0,0,.05);
  --shadow-lg: 0 6px 16px rgba(0,0,0,.07);
  --shadow-xl: 0 12px 28px rgba(0,0,0,.09);

  /* ── Radios ── */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --radius-xl:   20px;
  --radius-full: 9999px;

  /* ── Tipografía ── */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* ── Transitions ── */
  --transition-fast:   150ms ease;
  --transition-normal: 300ms ease;

  /* ── Layout ── */
  --sidebar-width: 248px;
  --topbar-height: 60px;

  /* ── Alias MP brand (sin uso en UI nueva) ── */
  --mp-blue:      #3b5afe;
  --mp-blue-dark: #2d45d6;
}

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

html { height: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.875rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100%;
  overflow-x: hidden;
}

/* ══════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: width var(--transition-normal), transform var(--transition-normal);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-logo svg { flex-shrink: 0; }

.sidebar-logo span {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.sidebar-section {
  padding: 20px 8px 6px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
}

.sidebar-section:first-child { padding-top: 4px; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.6rem 0.75rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast), color var(--transition-fast);
  margin-bottom: 2px;
}

.sidebar-nav a:hover {
  background: var(--bg-hover);
  color: var(--primary);
}

.sidebar-nav a.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-nav a svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.7;
}

.sidebar-nav a.active svg { opacity: 1; }
.sidebar-nav a:hover svg  { opacity: 1; }

/* ── Sidebar toggle ── */
.sidebar-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.sidebar-toggle:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.sidebar-toggle svg { width: 18px; height: 18px; }

/* ── Sidebar text (hideable) ── */
.sidebar-text {
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.2s ease;
}

/* ── Sidebar collapsed ── */
.sidebar.collapsed { width: 64px; }

.sidebar.collapsed .sidebar-text {
  opacity: 0;
  width: 0;
  display: none;
}

.sidebar.collapsed .sidebar-section {
  opacity: 0;
  height: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
}

.sidebar.collapsed .sidebar-logo {
  justify-content: center;
  padding: 24px 8px 20px;
}

.sidebar.collapsed .sidebar-nav a {
  justify-content: center;
  padding: 9px;
}

.sidebar.collapsed .sidebar-nav { padding: 16px 8px; }

/* ══════════════════════════════════════════════
   MAIN LAYOUT
   ══════════════════════════════════════════════ */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  background: var(--bg-secondary);
  width: calc(100% - var(--sidebar-width));
  overflow-x: hidden;
  transition: margin-left var(--transition-normal), width var(--transition-normal);
}

.main-content.sidebar-collapsed {
  margin-left: 64px;
  width: calc(100% - 64px);
}

/* ── Topbar ── */
.topbar {
  background: var(--bg-primary);
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.025em;
}

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

/* ── Page content ── */
.page-content {
  padding: 2rem 2.5rem 3rem;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* ══════════════════════════════════════════════
   CARDS
   ══════════════════════════════════════════════ */
.card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 24px;
  box-shadow: none;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.025em;
}

/* ══════════════════════════════════════════════
   STAT / KPI CARDS
   ══════════════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stats-grid.two-col { grid-template-columns: repeat(2, 1fr); }

.stat-card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 20px 22px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: border-color var(--transition-fast);
}

.stat-card:hover { border-color: var(--border-strong); }

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon.blue   { background: var(--primary-light); color: var(--primary); }
.stat-icon.green  { background: var(--success-light); color: var(--success); }
.stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-icon.red    { background: var(--error-light);   color: var(--error); }

.stat-info { flex: 1; min-width: 0; }

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

/* ── Commission section ── */
.commission-section {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 24px;
}

.commission-section .stats-grid { margin-bottom: 0; }

.commission-section .stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
}

.commission-section .stat-card:hover { background: var(--bg-primary); }

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.section-header .section-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--error-light);
  color: var(--error);
  display: flex;
  align-items: center;
  justify-content: center;
}

.section-header .section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.025em;
}

.section-header .section-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ══════════════════════════════════════════════
   KPI BAR
   ══════════════════════════════════════════════ */
.kpi-card { overflow: visible; }

.kpi-bar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 14px 20px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.kpi-period-tabs {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.kpi-tab {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
  white-space: nowrap;
}

.kpi-tab:hover {
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.kpi-tab.active {
  background: var(--primary);
  color: var(--text-on-primary);
  border-color: var(--primary);
}

.kpi-divider {
  width: 1px;
  height: 36px;
  background: var(--border);
  margin: 0 20px;
  flex-shrink: 0;
}

.kpi-metrics {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 1;
  overflow-x: auto;
}

.kpi-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 20px;
  flex-shrink: 0;
}

.kpi-metric-divider {
  width: 1px;
  height: 36px;
  background: var(--border-light);
  flex-shrink: 0;
}

.kpi-metric-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}

.kpi-metric-value {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.2;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.kpi-metric-sub {
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.kpi-custom-range {
  display: none;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border-light);
}

.kpi-custom-range.visible { display: block; }

/* ══════════════════════════════════════════════
   TABLES
   ══════════════════════════════════════════════ */
.table-wrapper {
  overflow-x: auto;
  margin: 0 -24px -24px;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  max-width: calc(100% + 48px);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

table.compact { font-size: 0.75rem; }

table.compact thead th {
  padding: 8px 10px;
  font-size: 0.6875rem;
}

table.compact tbody td { padding: 8px 10px; }

thead th {
  background: var(--bg-primary);
  padding: 10px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
  font-weight: 400;
}

tbody tr { transition: background var(--transition-fast); }
tbody tr:hover { background: var(--bg-hover); }
tbody tr:last-child td { border-bottom: none; }

/* ══════════════════════════════════════════════
   BADGES
   ══════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.badge-approved  { background: var(--success-light); color: var(--success-dark); }
.badge-pending   { background: var(--warning-light); color: var(--warning-dark); }
.badge-rejected  { background: var(--error-light);   color: var(--error-dark); }
.badge-refunded  { background: var(--info-light);    color: var(--info-dark); }
.badge-cancelled { background: var(--bg-secondary);  color: var(--text-muted); }

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ══════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  text-decoration: none;
  font-family: inherit;
  letter-spacing: -0.01em;
}

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

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

.btn-secondary {
  background: var(--primary-light);
  color: var(--primary);
  border: none;
}

.btn-secondary:hover { background: var(--primary-200); }

.btn-sm { padding: 6px 14px; font-size: 0.8125rem; }

.btn:disabled, .btn.htmx-request {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ══════════════════════════════════════════════
   FORMS / FILTERS
   ══════════════════════════════════════════════ */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-control {
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text-primary);
  background: var(--bg-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
  font-family: inherit;
}

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

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

select.form-control { min-width: 140px; }

/* ══════════════════════════════════════════════
   SPINNER / LOADING
   ══════════════════════════════════════════════ */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-flex; }

/* ══════════════════════════════════════════════
   ALERTS
   ══════════════════════════════════════════════ */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.alert-success {
  background: var(--success-light);
  color: var(--success-dark);
  border: 1px solid #b3e6cc;
}

.alert-error {
  background: var(--error-light);
  color: var(--error-dark);
  border: 1px solid #f8c0c6;
}

.alert-info {
  background: var(--info-light);
  color: var(--info-dark);
  border: 1px solid var(--primary-200);
}

/* ══════════════════════════════════════════════
   PAGINATION
   ══════════════════════════════════════════════ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px 8px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
}

.pagination-buttons { display: flex; gap: 4px; }

.pagination-buttons button,
.pagination-buttons a {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  font-family: inherit;
}

.pagination-buttons a:hover {
  background: var(--bg-secondary);
  border-color: var(--border-strong);
}

.pagination-buttons .active {
  background: var(--primary);
  color: var(--text-on-primary);
  border-color: var(--primary);
}

/* ══════════════════════════════════════════════
   EMPTY STATE
   ══════════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}

.empty-state svg { margin-bottom: 16px; opacity: 0.5; }
.empty-state p { font-size: 0.9375rem; margin: 0; font-weight: 500; }

/* ══════════════════════════════════════════════
   UTILITY
   ══════════════════════════════════════════════ */
.money {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.money-positive { color: var(--success-dark); }
.money-negative { color: var(--error-dark); }

code {
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text-secondary);
}

/* ══════════════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════════════ */
.sync-result { animation: fadeIn 0.3s ease; }

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

/* ══════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════ */
@media (min-width: 1600px) {
  .page-content { max-width: 1800px; padding: 32px 48px 48px; }
  .stat-value   { font-size: 2rem; }
}

@media (min-width: 1200px) {
  .table-wrapper { overflow-x: auto; max-width: 100%; }
  table          { min-width: 100%; }
}

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

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content, .main-content.sidebar-collapsed { margin-left: 0; width: 100%; }
  .page-content { padding: 20px 16px; }
  .topbar { padding: 0 16px; }
  .stats-grid { grid-template-columns: 1fr; }
}
