/* ============================================================
   FacturaIA Uruguay — Main Stylesheet
   Design: Clean financial dashboard with Uruguayan blue tones
   ============================================================ */

:root {
  --primary: #1a56db;
  --primary-dark: #1342b0;
  --primary-light: #e8eefb;
  --secondary: #0e9f6e;
  --secondary-light: #def7ec;
  --danger: #e02424;
  --danger-light: #fde8e8;
  --warning: #c27803;
  --warning-light: #fdf6b2;
  --sidebar-w: 250px;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #1a56db;
  --topbar-h: 60px;
  --body-bg: #f1f5f9;
  --card-bg: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --font: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'DM Mono', monospace;
  --transition: all .2s cubic-bezier(.4,0,.2,1);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--body-bg);
  color: var(--text-main);
  font-size: 15px;
  line-height: 1.6;
}

/* ── Layout ─────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: var(--transition);
}

.page-content {
  padding: 28px 32px;
  flex: 1;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px;
  border-bottom: 1px solid #1e293b;
}

.brand-icon {
  width: 38px; height: 38px;
  background: var(--primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
}

.brand-text {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.3px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid #1e293b;
  background: rgba(255,255,255,.03);
}

.user-avatar {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  letter-spacing: .5px;
}

.user-info { overflow: hidden; flex: 1; }

.user-name {
  display: block;
  color: #f1f5f9;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  letter-spacing: .5px;
  text-transform: uppercase;
}

.badge-admin { background: rgba(26,86,219,.3); color: #93c5fd; }
.badge-web { background: rgba(14,159,110,.3); color: #6ee7b7; }

.sidebar-nav {
  padding: 12px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: #94a3b8;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
}

.nav-item i { font-size: 16px; flex-shrink: 0; }

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #f1f5f9;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  box-shadow: 0 2px 8px rgba(26,86,219,.4);
}

.nav-item-danger { color: #f87171; }
.nav-item-danger:hover { background: rgba(239,68,68,.15); color: #fca5a5; }

.nav-divider {
  height: 1px;
  background: #1e293b;
  margin: 8px 0;
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0;
  height: var(--topbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 28px;
  z-index: 900;
  backdrop-filter: blur(8px);
}

.sidebar-toggle {
  background: none; border: none;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: var(--transition);
  display: none;
}

.sidebar-toggle:hover { background: var(--body-bg); color: var(--text-main); }

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  flex: 1;
}

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

.topbar-date {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.card-header-custom {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-header-custom h5 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body-custom { padding: 20px 24px; }

/* ── Stat Cards ──────────────────────────────────────────── */
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  box-shadow: var(--shadow);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: var(--accent, var(--primary));
  border-radius: 4px 0 0 4px;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.stat-icon {
  width: 50px; height: 50px;
  border-radius: 12px;
  background: var(--icon-bg, var(--primary-light));
  color: var(--icon-color, var(--primary));
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

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

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

.stat-card.primary { --accent: var(--primary); --icon-bg: var(--primary-light); --icon-color: var(--primary); }
.stat-card.success { --accent: var(--secondary); --icon-bg: var(--secondary-light); --icon-color: var(--secondary); }
.stat-card.danger  { --accent: var(--danger);    --icon-bg: var(--danger-light);    --icon-color: var(--danger); }
.stat-card.warning { --accent: #f59e0b;           --icon-bg: #fffbeb;                --icon-color: #d97706; }

/* ── Tables ─────────────────────────────────────────────── */
.table-wrapper {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-toolbar {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.table-toolbar h5 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 320px;
}

.search-box i {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 15px;
}

.search-box input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  background: var(--body-bg);
  color: var(--text-main);
  transition: var(--transition);
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(26,86,219,.1);
}

.table { margin: 0; }

.table thead th {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  padding: 12px 16px;
  white-space: nowrap;
}

.table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 14px;
  vertical-align: middle;
}

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

.table tbody tr:hover { background: #f8fafc; }

/* ── Badges ─────────────────────────────────────────────── */
.badge-tipo-compra { background: var(--danger-light); color: var(--danger); font-weight: 600; font-size: 11px; padding: 3px 10px; border-radius: 20px; }
.badge-tipo-venta { background: var(--secondary-light); color: var(--secondary); font-weight: 600; font-size: 11px; padding: 3px 10px; border-radius: 20px; }

.badge-estado-procesado { background: #dcfce7; color: #15803d; font-size: 11px; padding: 3px 10px; border-radius: 20px; font-weight: 600; }
.badge-estado-pendiente { background: var(--warning-light); color: var(--warning); font-size: 11px; padding: 3px 10px; border-radius: 20px; font-weight: 600; }
.badge-estado-error { background: var(--danger-light); color: var(--danger); font-size: 11px; padding: 3px 10px; border-radius: 20px; font-weight: 600; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  font-family: var(--font);
  font-weight: 500;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 14px;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  border: 1px solid transparent;
}

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

.btn-success { background: var(--secondary); color: #fff; border-color: var(--secondary); }
.btn-success:hover { background: #057a55; color: #fff; }

.btn-outline { background: transparent; border-color: var(--border); color: var(--text-main); }
.btn-outline:hover { background: var(--body-bg); }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; color: #fff; }

.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-icon { padding: 6px 10px; }

/* ── Forms ─────────────────────────────────────────────── */
.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
  display: block;
}

.form-control, .form-select {
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  background: #fff;
  transition: var(--transition);
  width: 100%;
}

.form-control:focus, .form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.1);
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Upload Zone ─────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: #fafbfc;
  position: relative;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-zone input[type="file"] {
  position: absolute; inset: 0;
  opacity: 0; cursor: pointer;
  width: 100%; height: 100%;
}

.upload-icon {
  font-size: 48px;
  color: var(--primary);
  margin-bottom: 12px;
  display: block;
}

.upload-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.upload-hint { font-size: 13px; color: var(--text-muted); }

.upload-preview {
  margin-top: 20px;
  display: none;
}

.upload-preview img {
  max-height: 200px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ── Pagination ─────────────────────────────────────────── */
.pagination-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  flex-wrap: wrap;
  gap: 12px;
}

.pagination-info { font-size: 13px; color: var(--text-muted); }

.pagination { margin: 0; gap: 4px; display: flex; }

.page-link {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
  text-decoration: none;
  transition: var(--transition);
  font-family: var(--font);
  background: #fff;
}

.page-link:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.page-link.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-link.disabled { opacity: .4; pointer-events: none; }

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  padding: 12px 16px;
}

.alert-danger { background: var(--danger-light); color: var(--danger); }
.alert-success { background: var(--secondary-light); color: #065f46; }
.alert-warning { background: var(--warning-light); color: #92400e; }

/* ── Login Page ─────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 48px 44px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .logo-icon {
  width: 64px; height: 64px;
  background: var(--primary);
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  color: #fff;
  margin: 0 auto 16px;
  box-shadow: 0 8px 24px rgba(26,86,219,.35);
}

.login-logo h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}

.login-logo p {
  font-size: 14px;
  color: var(--text-muted);
}

/* ── Code / API Key ─────────────────────────────────────── */
.api-key-box {
  background: #0f172a;
  color: #7dd3fc;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  word-break: break-all;
  display: flex;
  align-items: center;
  gap: 12px;
}

.api-key-text { flex: 1; }

/* ── Detail page ─────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.detail-item label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 3px;
}

.detail-item span {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-main);
}

/* ── Chart containers ────────────────────────────────────── */
.chart-container { position: relative; height: 280px; }

/* ── Page header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-header p {
  font-size: 14px;
  color: var(--text-muted);
  margin: 3px 0 0;
}

/* ── Switch toggle ───────────────────────────────────────── */
.form-switch .form-check-input {
  width: 40px; height: 22px;
  cursor: pointer;
}

.form-check-input:checked { background-color: var(--secondary); border-color: var(--secondary); }

/* ── Factura image preview ───────────────────────────────── */
.factura-img {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: zoom-in;
}

/* ── Type selector ───────────────────────────────────────── */
.tipo-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.tipo-option {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.tipo-option input[type="radio"] {
  position: absolute;
  opacity: 0; pointer-events: none;
}

.tipo-option:hover { border-color: var(--primary); background: var(--primary-light); }
.tipo-option.selected-compra { border-color: var(--danger); background: var(--danger-light); }
.tipo-option.selected-venta { border-color: var(--secondary); background: var(--secondary-light); }

.tipo-option i { font-size: 28px; display: block; margin-bottom: 8px; }
.tipo-option.compra i { color: var(--danger); }
.tipo-option.venta i { color: var(--secondary); }
.tipo-option strong { font-size: 15px; display: block; }
.tipo-option small { font-size: 12px; color: var(--text-muted); }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main-content { margin-left: 0; }
  .sidebar-toggle { display: flex; }
  .page-content { padding: 20px 16px; }
  .detail-grid { grid-template-columns: 1fr; }
  .tipo-selector { grid-template-columns: 1fr; }
  .topbar { padding: 0 16px; }
  .stat-value { font-size: 20px; }
  .login-card { padding: 32px 24px; }
}

/* ── Utilities ──────────────────────────────────────────── */
.text-money { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.text-primary { color: var(--primary) !important; }
.text-success { color: var(--secondary) !important; }
.text-danger  { color: var(--danger) !important; }
.text-muted   { color: var(--text-muted) !important; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.gap-2 { gap: 8px; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 999; display: none; }
.overlay.open { display: block; }

/* Loading spinner */
.spinner-border-sm { width: 16px; height: 16px; border-width: 2px; }

/* JSON viewer */
.json-viewer {
  background: #0f172a;
  color: #a5f3fc;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  max-height: 340px;
  overflow-y: auto;
  white-space: pre;
}
