/* ============================================================
   tContable CR — Estilos principales
   ============================================================ */

:root {
  --primary:    #1a6b4a;
  --primary-dk: #134d36;
  --primary-lt: #e8f5ee;
  --accent:     #f0a500;
  --danger:     #dc3545;
  --warning:    #ffc107;
  --success:    #28a745;
  --info:       #17a2b8;
  --gray-50:    #f8f9fa;
  --gray-100:   #f1f3f4;
  --gray-200:   #e9ecef;
  --gray-400:   #ced4da;
  --gray-600:   #6c757d;
  --gray-800:   #343a40;
  --white:      #ffffff;
  --shadow:     0 2px 8px rgba(0,0,0,.10);
  --shadow-lg:  0 4px 20px rgba(0,0,0,.15);
  --radius:     8px;
  --radius-lg:  12px;
  --font:       'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-100);
  line-height: 1.5;
}

/* ---- AUTH ---- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, var(--primary-dk) 0%, var(--primary) 100%); }
.auth-container { width: 100%; max-width: 400px; padding: 20px; }
.auth-logo { text-align: center; margin-bottom: 24px; color: white; }
.auth-logo h1 { font-size: 32px; font-weight: 700; }
.auth-logo h1 span { color: var(--accent); }
.auth-logo p { opacity: .8; margin-top: 4px; }
.auth-box { background: white; border-radius: var(--radius-lg); padding: 32px; box-shadow: var(--shadow-lg); }
.auth-box h2 { font-size: 20px; margin-bottom: 20px; color: var(--primary); }
.auth-switch { text-align: center; margin-top: 16px; color: var(--gray-600); font-size: 13px; }
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 600; }

/* ---- LAYOUT APP ---- */
.app-layout { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--primary-dk); color: white; flex-shrink: 0; display: flex; flex-direction: column; }
.sidebar-logo { padding: 20px 16px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-logo h1 { font-size: 20px; font-weight: 700; }
.sidebar-logo h1 span { color: var(--accent); }
.sidebar-logo p { font-size: 11px; opacity: .6; margin-top: 2px; }
.sidebar-contab { padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-contab label { font-size: 10px; text-transform: uppercase; opacity: .6; }
.sidebar-contab select { width: 100%; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2); color: white; border-radius: 6px; padding: 6px 8px; font-size: 13px; margin-top: 4px; cursor: pointer; }
.sidebar-contab select option { background: var(--primary-dk); }
.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; cursor: pointer; transition: background .15s; font-size: 14px; border: none; background: none; color: white; width: 100%; text-align: left; }
.nav-item:hover { background: rgba(255,255,255,.1); }
.nav-item.active { background: var(--primary); border-left: 3px solid var(--accent); }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-user { font-size: 12px; opacity: .7; margin-bottom: 8px; }
.main-content { flex: 1; overflow-y: auto; }
.topbar { background: white; padding: 12px 24px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; box-shadow: var(--shadow); }
.topbar h2 { font-size: 18px; color: var(--primary); }
.page-content { padding: 24px; }

/* ---- TARJETAS RESUMEN ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: white; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border-left: 4px solid var(--gray-200); }
.stat-card.ingresos { border-left-color: var(--success); }
.stat-card.gastos    { border-left-color: var(--danger); }
.stat-card.iva-pagar { border-left-color: var(--warning); }
.stat-card.iva-cred  { border-left-color: var(--info); }
.stat-card .label { font-size: 12px; color: var(--gray-600); text-transform: uppercase; letter-spacing: .5px; }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.stat-card .value.positive { color: var(--success); }
.stat-card .value.negative { color: var(--danger); }
.stat-card .value.warning  { color: var(--warning); }
.stat-card .sub { font-size: 12px; color: var(--gray-600); margin-top: 4px; }

/* ---- TABLAS ---- */
.table-card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 24px; }
.table-header { padding: 16px 20px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; }
.table-header h3 { font-size: 15px; color: var(--primary); }
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th { background: var(--gray-50); padding: 10px 14px; text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--gray-600); border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--gray-100); font-size: 13px; }
tbody tr:hover { background: var(--gray-50); }
tbody tr:last-child td { border-bottom: none; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-ingreso  { background: #d4edda; color: #155724; }
.badge-gasto    { background: #f8d7da; color: #721c24; }
.badge-sujeto   { background: #d1ecf1; color: #0c5460; }
.badge-nosujeto { background: #fff3cd; color: #856404; }
.badge-exento   { background: #e2e3e5; color: #383d41; }

/* ---- FILTROS ---- */
.filters-bar { background: white; border-radius: var(--radius); padding: 16px 20px; margin-bottom: 20px; box-shadow: var(--shadow); display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 11px; color: var(--gray-600); text-transform: uppercase; }

/* ---- D104 ---- */
.d104-section { background: white; border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); margin-bottom: 20px; }
.d104-section h3 { font-size: 16px; color: var(--primary); border-bottom: 2px solid var(--primary-lt); padding-bottom: 10px; margin-bottom: 16px; }
.d104-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--gray-100); }
.d104-row:last-child { border-bottom: none; }
.d104-row .d104-label { font-size: 14px; color: var(--gray-800); }
.d104-row .d104-field { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.d104-input { background: var(--gray-50); border: 1px solid var(--gray-400); border-radius: 6px; padding: 6px 12px; text-align: right; font-size: 14px; min-width: 160px; }
.d104-total { background: var(--primary-lt); border-color: var(--primary); font-weight: 700; color: var(--primary); }
.d104-neto  { background: #fff3cd; border-color: var(--warning); font-weight: 700; color: #856404; }

/* ---- FORMULARIOS ---- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--gray-800); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ---- INPUTS GENERALES ---- */
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--gray-400); border-radius: var(--radius);
  font-size: 14px; font-family: var(--font); transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-lt); }
textarea { resize: vertical; min-height: 80px; }

/* ---- BOTONES ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius); font-size: 14px; font-weight: 600; cursor: pointer; border: none; transition: all .15s; }
.btn-primary  { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dk); }
.btn-secondary { background: var(--gray-200); color: var(--gray-800); }
.btn-secondary:hover { background: var(--gray-400); }
.btn-danger   { background: var(--danger); color: white; }
.btn-success  { background: var(--success); color: white; }
.btn-warning  { background: var(--warning); color: var(--gray-800); }
.btn-sm       { padding: 5px 10px; font-size: 12px; }
.btn-full     { width: 100%; justify-content: center; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---- ALERTAS ---- */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }
.alert-error   { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.alert-info    { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* ---- MODAL ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal { background: white; border-radius: var(--radius-lg); width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; color: var(--primary); }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--gray-600); line-height: 1; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 8px; }

/* ---- UPLOAD ZONE ---- */
.upload-zone { border: 2px dashed var(--gray-400); border-radius: var(--radius); padding: 40px 20px; text-align: center; cursor: pointer; transition: all .2s; }
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--primary); background: var(--primary-lt); }
.upload-zone .upload-icon { font-size: 48px; margin-bottom: 12px; }
.upload-zone p { color: var(--gray-600); }
.upload-zone strong { color: var(--primary); }

/* ---- UTILIDADES ---- */
.hidden { display: none !important; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-600); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.fw-bold { font-weight: 700; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.colones::before { content: '₡'; }
.divider { border: none; border-top: 1px solid var(--gray-200); margin: 16px 0; }
.loading { opacity: .5; pointer-events: none; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3); border-radius: 50%; border-top-color: white; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .filters-bar { flex-direction: column; }
}

/* Mejora 1 — Botones en la misma fila que filtros */
.filter-group-actions { justify-content: flex-end; }
.btn-group-filters { display: flex; gap: 6px; align-items: center; }
.filters-bar { align-items: flex-end; }

/* Mejora 2 — Upload colapsable */
.upload-collapsible { margin-bottom: 16px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.upload-toggle { background: white; padding: 12px 20px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: var(--primary); font-size: 14px; border: 2px dashed var(--gray-400); border-radius: var(--radius); transition: all .2s; }
.upload-toggle:hover { border-color: var(--primary); background: var(--primary-lt); }
.upload-body { background: white; padding: 16px; border: 2px dashed var(--primary); border-top: none; border-radius: 0 0 var(--radius) var(--radius); }

/* Mejora 3 — Tabla facturas con scroll suave */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-responsive table { min-width: 900px; }
tbody td { white-space: nowrap; }
tbody td:nth-child(3) { white-space: normal; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
/* Número de factura truncado */
.num-factura { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; font-size: 11px; font-family: monospace; }

/* Mejora 4 — D-104 bienvenida */
.d104-welcome { text-align: center; padding: 40px 20px; background: white; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; }
.d104-welcome-icon { font-size: 48px; margin-bottom: 12px; }
.d104-welcome h3 { color: var(--primary); font-size: 18px; margin-bottom: 8px; }
.d104-welcome p { color: var(--gray-600); font-size: 14px; max-width: 500px; margin: 0 auto; line-height: 1.6; }

/* Mejora 5 — Alertas más compactas */
.alertas-wrapper .alert-item { padding: 8px 12px; font-size: 13px; }
.alertas-wrapper { margin-bottom: 16px !important; }
.alertas-wrapper > div { padding: 12px 16px !important; }
.alertas-wrapper > div > div:first-child { margin-bottom: 8px !important; }
