:root {
  --bg-main: #0B0E1E;
  --bg-card: #14182B;
  --border-color: #242B48;
  --text-primary: #F3F4F6;
  --text-muted: #9CA3AF;
  --indigo-primary: #6366F1;
  --green-primary: #10B981;
  --amber-primary: #F59E0B;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', -apple-system, sans-serif; background: #F6F7FB; color: #111827; }
body.theme-dark { background: var(--bg-main); color: var(--text-primary); }

.hidden { display: none !important; }

/* Login Container */
.login-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(circle at 50% 30%, #171C38 0%, #090C1B 100%); }
.login-card { width: 100%; max-width: 440px; background: #131728; border: 1px solid #28304E; border-radius: 20px; padding: 32px; box-shadow: 0 25px 50px rgba(0,0,0,0.6); }
.login-brand { text-align: center; margin-bottom: 24px; }
.logo-box { width: 48px; height: 48px; border-radius: 12px; background: linear-gradient(135deg, #6366F1, #4338CA); display: inline-flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.brand-icon { width: 26px; height: 26px; color: #FFF; }
.brand-title { font-size: 20px; font-weight: 800; color: #FFF; }
.brand-subtitle { font-size: 11px; color: #9CA3AF; margin-top: 4px; }

.db-status-bar { margin: 14px 0 18px 0; padding: 8px 12px; border-radius: 8px; font-size: 11px; text-align: center; border: 1px solid transparent; }
.db-status-bar.status-connected { background: rgba(16, 185, 129, 0.12); border-color: rgba(16, 185, 129, 0.3); color: #34D399; }
.db-status-bar.status-standalone { background: rgba(245, 158, 11, 0.12); border-color: rgba(245, 158, 11, 0.3); color: #FBBF24; }
.db-status-bar code { font-family: monospace; background: rgba(0,0,0,0.3); padding: 1px 4px; border-radius: 4px; color: #FFF; }
.status-dot { font-size: 10px; margin-right: 4px; }
.status-dot.green { color: #10B981; }
.status-dot.amber { color: #F59E0B; }

.portal-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #0A0D1A; padding: 4px; border-radius: 12px; border: 1px solid #222944; margin-bottom: 20px; }
.portal-tab { padding: 9px 12px; border: none; background: transparent; color: #9CA3AF; font-size: 12px; font-weight: 700; border-radius: 8px; cursor: pointer; transition: all 0.2s; }
.portal-tab.active { background: #6366F1; color: #FFF; box-shadow: 0 2px 8px rgba(99,102,241,0.4); }
#tab-rep.active { background: #10B981; box-shadow: 0 2px 8px rgba(16,185,129,0.4); }

.form-group { margin-bottom: 16px; text-align: left; }
.form-group label { display: block; font-size: 11px; font-weight: 600; color: #D1D5DB; margin-bottom: 6px; }
.form-group input { width: 100%; padding: 10px 14px; border-radius: 10px; background: #0E1222; border: 1px solid #2E385C; color: #FFF; font-size: 13px; outline: none; transition: border 0.2s; }
.form-group input:focus { border-color: #6366F1; }

.quick-reps { font-size: 11px; color: #9CA3AF; margin-bottom: 16px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.quick-reps button { background: #1C223A; border: 1px solid #2E385C; color: #A5B4FC; padding: 3px 8px; border-radius: 6px; font-size: 10px; font-weight: 700; cursor: pointer; }

.btn-submit { width: 100%; padding: 12px; border: none; border-radius: 11px; font-weight: 700; font-size: 13px; color: #FFF; cursor: pointer; transition: transform 0.1s; }
.btn-submit:active { transform: scale(0.98); }
.btn-admin { background: linear-gradient(135deg, #6366F1, #4F46E5); box-shadow: 0 4px 14px rgba(99,102,241,0.4); }
.btn-rep { background: linear-gradient(135deg, #10B981, #059669); box-shadow: 0 4px 14px rgba(16,185,129,0.4); }

.login-error { margin-top: 14px; padding: 10px; border-radius: 8px; background: rgba(220,38,38,0.2); border: 1px solid rgba(220,38,38,0.4); color: #FCA5A5; font-size: 12px; }
.login-footer { margin-top: 24px; padding-top: 16px; border-top: 1px solid #242B48; display: flex; justify-content: space-between; font-size: 11px; color: #6B7280; }
.badge-online { color: #10B981; font-weight: 700; }

/* Application Layout */
.app-layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; min-width: 220px; background: #121526; border-right: 1px solid #202640; display: flex; flex-direction: column; height: 100vh; position: sticky; top: 0; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 16px; border-bottom: 1px solid #202640; }
.logo-sq { width: 32px; height: 32px; border-radius: 8px; background: #6366F1; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sq-icon { width: 18px; height: 18px; color: #FFF; }
.brand-text-sm { font-size: 13px; font-weight: 800; color: #FFF; text-transform: uppercase; }
.brand-sub-sm { font-size: 10px; color: #9CA3AF; }

.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav-btn { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; background: transparent; border: none; color: #9CA3AF; font-size: 13px; font-weight: 600; cursor: pointer; text-align: left; width: 100%; transition: all 0.15s; }
.nav-btn:hover { background: #1A1F36; color: #FFF; }
.nav-btn.active { background: #1E2342; color: #818CF8; font-weight: 700; }
.nav-icon { font-size: 15px; }

.sidebar-footer { padding: 12px 16px; border-top: 1px solid #202640; display: flex; align-items: center; justify-content: space-between; }
.user-pill { display: flex; align-items: center; gap: 8px; min-width: 0; }
.avatar-sm { width: 30px; height: 30px; border-radius: 50%; background: #6366F1; color: #FFF; font-weight: 800; font-size: 11px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.user-meta { min-width: 0; }
.user-meta strong { display: block; font-size: 12px; color: #FFF; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { display: block; font-size: 10px; color: #9CA3AF; }
.btn-logout { background: transparent; border: none; color: #EF4444; font-size: 16px; cursor: pointer; padding: 4px; border-radius: 6px; }

.content-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.top-bar { padding: 16px 24px; border-bottom: 1px solid #202640; background: #121526; display: flex; justify-content: space-between; align-items: center; }
.page-title { font-size: 18px; font-weight: 800; color: #FFF; }
.page-subtitle { font-size: 12px; color: #9CA3AF; margin-top: 2px; }
.top-bar-right { display: flex; align-items: center; gap: 12px; }
.date-chip { font-size: 11px; font-weight: 600; color: #9CA3AF; background: #1A1F36; padding: 4px 10px; border-radius: 6px; }
.terminal-status { font-size: 11px; font-weight: 700; color: #10B981; }

.tab-body { padding: 24px; flex: 1; overflow-y: auto; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card { background: #14182B; border: 1px solid #242B48; border-radius: 14px; padding: 18px; }
.kpi-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: #9CA3AF; }
.kpi-val { font-size: 26px; font-weight: 900; color: #FFF; margin-top: 8px; font-family: 'JetBrains Mono', monospace; }
.kpi-sub { font-size: 11px; color: #10B981; font-weight: 600; margin-top: 4px; }

.panel { background: #14182B; border: 1px solid #242B48; border-radius: 16px; padding: 20px; margin-bottom: 20px; }
.panel-head { font-size: 15px; font-weight: 700; color: #FFF; margin-bottom: 12px; }
.table { width: 100%; border-collapse: collapse; font-size: 12px; }
.table th { text-align: left; padding: 10px 12px; border-bottom: 1px solid #202640; color: #9CA3AF; font-size: 11px; text-transform: uppercase; }
.table td { padding: 12px; border-bottom: 1px solid #1C223A; color: #D1D5DB; }
.badge-paid { padding: 3px 8px; border-radius: 999px; background: rgba(16,185,129,0.2); color: #34D399; font-weight: 700; font-size: 10px; }
.badge-owing { padding: 3px 8px; border-radius: 999px; background: rgba(245,158,11,0.2); color: #FBBF24; font-weight: 700; font-size: 10px; }
