*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #root { height: 100%; }
body { font-family: -apple-system, 'Segoe UI', Helvetica, sans-serif; background: #f1f5f9; color: #0f172a; }
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar { width: 240px; min-width: 240px; background: #0f172a; display: flex; flex-direction: column; overflow-y: auto; }
.sidebar-brand { padding: 24px 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.07); }
.sidebar-brand h1 { color: #f8fafc; font-size: 18px; font-weight: 700; letter-spacing: -0.4px; }
.sidebar-brand p { color: #475569; font-size: 11px; margin-top: 3px; }
.db-status { display: flex; align-items: center; gap: 5px; font-size: 10px; margin-top: 8px; font-weight: 600; }
.db-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.db-dot.connected { background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,0.3); }
.db-dot.connecting { background: #f59e0b; animation: pulse 1.2s infinite; }
.db-dot.error { background: #ef4444; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

.sidebar-nav { padding: 10px 0; flex: 1; }
.sidebar-section { padding: 14px 20px 4px; font-size: 10px; font-weight: 600; letter-spacing: 0.1em; color: #334155; text-transform: uppercase; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; margin: 1px 8px; border-radius: 8px; cursor: pointer; transition: all 0.12s; color: #94a3b8; font-size: 13.5px; font-weight: 500; border: none; background: none; width: calc(100% - 16px); text-align: left; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #e2e8f0; }
.nav-item.active { background: rgba(255,255,255,0.10); color: #f8fafc; }
.nav-item svg { opacity: 0.65; flex-shrink: 0; }
.nav-item.active svg { opacity: 1; }
.sidebar-footer { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,0.07); }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: #1e3a5f; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #93c5fd; flex-shrink: 0; }

.main { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.page-header { background: #fff; border-bottom: 1px solid #e2e8f0; padding: 14px 28px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10; }
.page-title { font-size: 16px; font-weight: 700; color: #0f172a; }
.page-subtitle { font-size: 12px; color: #94a3b8; margin-top: 1px; }
.page-content { padding: 22px 28px; flex: 1; }

.card { background: #fff; border-radius: 12px; border: 1px solid #e2e8f0; padding: 20px; }
.card-title { font-size: 11px; font-weight: 700; color: #94a3b8; margin-bottom: 14px; text-transform: uppercase; letter-spacing: 0.07em; }

.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 20px; }
.kpi-card { background: #fff; border-radius: 12px; border: 1px solid #e2e8f0; padding: 18px; }
.kpi-label { font-size: 11px; color: #94a3b8; font-weight: 600; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.06em; }
.kpi-value { font-size: 25px; font-weight: 800; color: #0f172a; letter-spacing: -0.5px; }
.kpi-badge { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 100px; margin-top: 10px; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef9c3; color: #854d0e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-neutral { background: #f1f5f9; color: #475569; }

.charts-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 14px; margin-bottom: 20px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { padding: 9px 12px; text-align: left; font-size: 10.5px; font-weight: 700; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 1px solid #e2e8f0; background: #f8fafc; white-space: nowrap; }
tbody tr { border-bottom: 1px solid #f1f5f9; transition: background 0.1s; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 11px 12px; color: #334155; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.search-input { flex: 1; padding: 8px 12px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 13.5px; color: #0f172a; background: #f8fafc; outline: none; transition: border-color 0.15s; }
.search-input:focus { border-color: #94a3b8; background: #fff; }
.filter-select { padding: 8px 12px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 13.5px; color: #334155; background: #f8fafc; outline: none; cursor: pointer; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer; font-size: 13.5px; font-weight: 600; transition: all 0.12s; white-space: nowrap; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: #0f172a; color: #f8fafc; }
.btn-primary:hover:not(:disabled) { background: #1e293b; }
.btn-outline { background: #fff; color: #334155; border: 1px solid #e2e8f0; }
.btn-outline:hover:not(:disabled) { background: #f8fafc; }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.btn-danger:hover:not(:disabled) { background: #fee2e2; }

.type-badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 100px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.type-compra { background: #fef9c3; color: #713f12; }
.type-venta { background: #dcfce7; color: #14532d; }
.type-retencion { background: #fce7f3; color: #831843; }

.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #fff; border-radius: 16px; padding: 28px; width: 540px; max-width: 95vw; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.modal-title { font-size: 17px; font-weight: 800; color: #0f172a; }
.form-group { margin-bottom: 13px; }
.form-label { display: block; font-size: 11px; font-weight: 700; color: #64748b; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.06em; }
.form-input { width: 100%; padding: 9px 12px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 13.5px; color: #0f172a; outline: none; transition: border-color 0.15s; background: #f8fafc; }
.form-input:focus { border-color: #64748b; background: #fff; }
.form-input:disabled { opacity: 0.45; cursor: not-allowed; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; padding-top: 16px; border-top: 1px solid #f1f5f9; }

.tabs { display: flex; border-bottom: 1px solid #e2e8f0; margin-bottom: 18px; }
.tab-btn { padding: 10px 18px; border: none; background: none; cursor: pointer; font-size: 13.5px; font-weight: 600; color: #94a3b8; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: all 0.15s; }
.tab-btn.active { color: #0f172a; border-bottom-color: #0f172a; }
.tab-btn:hover { color: #334155; }

.spinner-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 260px; gap: 14px; }
.spinner { width: 30px; height: 30px; border: 3px solid #e2e8f0; border-top-color: #0f172a; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-label { font-size: 13px; color: #94a3b8; font-weight: 500; }

.toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 10px; background: #1e293b; color: #f8fafc; font-size: 13px; font-weight: 500; box-shadow: 0 8px 24px rgba(0,0,0,0.2); animation: slide-in 0.2s ease; min-width: 240px; }
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }
@keyframes slide-in { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }

.auth-container { display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); color: #f8fafc; }
.auth-card { background: rgba(255,255,255,0.05); backdrop-filter: blur(20px); border: 1px solid rgba(255,255,255,0.1); border-radius: 24px; padding: 48px; width: 440px; max-width: 90vw; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); }
.auth-header { text-align: center; margin-bottom: 32px; }
.auth-header h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; margin-bottom: 8px; }
.auth-header p { font-size: 14px; color: #94a3b8; }
.auth-form-group { margin-bottom: 20px; }
.auth-label { display: block; font-size: 12px; font-weight: 600; color: #cbd5e1; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.auth-input { width: 100%; padding: 14px 16px; border: 1px solid rgba(255,255,255,0.1); border-radius: 12px; font-size: 15px; color: #f8fafc; background: rgba(0,0,0,0.2); outline: none; transition: all 0.2s; }
.auth-input:focus { border-color: #3b82f6; background: rgba(0,0,0,0.4); box-shadow: 0 0 0 4px rgba(59,130,246,0.1); }
.auth-input::placeholder { color: #475569; }
.auth-btn { width: 100%; padding: 14px; border-radius: 12px; border: none; font-size: 15px; font-weight: 600; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 10px; }
.auth-btn-primary { background: #3b82f6; color: #fff; }
.auth-btn-primary:hover:not(:disabled) { background: #2563eb; transform: translateY(-1px); }
.auth-btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.auth-error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.2); color: #fca5a5; padding: 12px 16px; border-radius: 10px; font-size: 13px; margin-bottom: 20px; display: flex; align-items: center; gap: 8px; }

@media(max-width:900px) { .kpi-grid{grid-template-columns:1fr 1fr} .charts-grid{grid-template-columns:1fr} }
