/* ============================================================
   JB SACCO Management System — Main Design System
   ============================================================ */

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

/* ============================================================
   CSS CUSTOM PROPERTIES
   ============================================================ */
:root {
  --primary: hsl(220, 90%, 56%);
  --primary-dark: hsl(220, 90%, 45%);
  --primary-light: hsl(220, 90%, 70%);
  --primary-glow: hsla(220, 90%, 56%, 0.25);
  --accent: hsl(160, 80%, 45%);
  --accent-dark: hsl(160, 80%, 35%);
  --accent-glow: hsla(160, 80%, 45%, 0.25);
  --warning: hsl(38, 95%, 55%);
  --warning-dark: hsl(38, 95%, 42%);
  --warning-glow: hsla(38, 95%, 55%, 0.25);
  --danger: hsl(0, 80%, 58%);
  --danger-dark: hsl(0, 80%, 45%);
  --danger-glow: hsla(0, 80%, 58%, 0.2);
  --success: hsl(130, 60%, 45%);
  --success-dark: hsl(130, 60%, 35%);
  --success-glow: hsla(130, 60%, 45%, 0.25);
  --bg: hsl(222, 22%, 7%);
  --bg-2: hsl(222, 20%, 10%);
  --surface: hsl(222, 18%, 13%);
  --surface-2: hsl(222, 16%, 17%);
  --surface-3: hsl(222, 14%, 22%);
  --border: hsl(222, 15%, 20%);
  --border-light: hsl(222, 12%, 28%);
  --text: hsl(220, 15%, 95%);
  --text-muted: hsl(220, 10%, 58%);
  --text-dim: hsl(220, 8%, 38%);
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-sm: 0 2px 12px rgba(0,0,0,0.35);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.6);
  --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: all 0.12s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--primary-glow); color: var(--text); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

a { color: var(--primary-light); text-decoration: none; }
a:hover { color: var(--primary); }

h1, h2, h3, h4, h5, h6 {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
}

img { max-width: 100%; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
#login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

#login-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, hsla(220,90%,56%,0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, hsla(160,80%,45%,0.10) 0%, transparent 60%),
    radial-gradient(ellipse at 60% 80%, hsla(38,95%,55%,0.08) 0%, transparent 50%);
  pointer-events: none;
}

.login-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg), 0 0 80px hsla(220,90%,56%,0.1);
  animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.login-logo-icon {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin: 0 auto 16px;
  box-shadow: 0 8px 24px var(--primary-glow);
}

.login-title {
  font-size: 1.6rem;
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  background: linear-gradient(135deg, var(--text) 40%, var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 4px;
}

.login-error {
  background: hsla(0,80%,58%,0.12);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.875rem;
  margin-bottom: 16px;
  display: none;
}

.login-error.visible { display: block; }

/* ============================================================
   APP LAYOUT
   ============================================================ */
#app-shell {
  display: none;
  min-height: 100vh;
}

#app-shell.visible {
  display: flex;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.sidebar-brand-text {
  overflow: hidden;
}

.sidebar-brand-name {
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 1rem;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
}

.sidebar-brand-tagline {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

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

.nav-section-label {
  font-size: 0.67rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 14px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 2px;
  position: relative;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

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

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.nav-item-icon {
  font-size: 1.1rem;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.nav-item-label { flex: 1; }

.nav-badge {
  background: var(--danger);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--primary-dark), var(--accent-dark));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

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

.sidebar-user-name {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

/* ============================================================
   TOPBAR
   ============================================================ */
#topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background: hsla(222, 18%, 13%, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  z-index: 50;
}

.topbar-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
}

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

.online-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.online-indicator.online {
  background: hsla(130, 60%, 45%, 0.15);
  color: var(--success);
  border: 1px solid hsla(130, 60%, 45%, 0.3);
}

.online-indicator.offline {
  background: hsla(38, 95%, 55%, 0.15);
  color: var(--warning);
  border: 1px solid hsla(38, 95%, 55%, 0.3);
}

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

.online-indicator.online .online-dot {
  animation: pulse 2s infinite;
}

.sync-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition);
}

.sync-btn:hover { background: var(--surface-3); color: var(--text); }

.sync-btn.syncing .sync-icon { animation: spin 1s linear infinite; }

.topbar-divider { width: 1px; height: 24px; background: var(--border); }

.topbar-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
}

.topbar-logout:hover { border-color: var(--danger); color: var(--danger); }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
#main-wrapper {
  margin-left: var(--sidebar-width);
  margin-top: var(--topbar-height);
  flex: 1;
  min-height: calc(100vh - var(--topbar-height));
}

#main-content {
  padding: 28px;
  min-height: calc(100vh - var(--topbar-height));
  animation: fadeIn 0.25s ease;
}

.page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title-group {}

.page-title {
  font-size: 1.6rem;
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  font-family: 'Outfit', sans-serif;
  color: var(--text);
}

.card-body { padding: 20px; }
.card-body.no-pad { padding: 0; }
.card-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

.stat-card:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
}

.stat-card.blue::before { background: linear-gradient(90deg, var(--primary), var(--primary-light)); }
.stat-card.green::before { background: linear-gradient(90deg, var(--accent), hsl(160,80%,60%)); }
.stat-card.amber::before { background: linear-gradient(90deg, var(--warning), hsl(38,95%,70%)); }
.stat-card.red::before { background: linear-gradient(90deg, var(--danger), hsl(0,80%,70%)); }
.stat-card.purple::before { background: linear-gradient(90deg, hsl(270,70%,60%), hsl(290,60%,70%)); }

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  margin-bottom: 14px;
}

.stat-card.blue .stat-icon { background: var(--primary-glow); }
.stat-card.green .stat-icon { background: var(--accent-glow); }
.stat-card.amber .stat-icon { background: var(--warning-glow); }
.stat-card.red .stat-icon { background: var(--danger-glow); }
.stat-card.purple .stat-icon { background: hsla(270,70%,60%,0.2); }

.stat-value {
  font-size: 1.5rem;
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-trend {
  position: absolute;
  top: 18px;
  right: 18px;
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 3px;
}

.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* ============================================================
   GRID LAYOUTS
   ============================================================ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.grid-1-2 { display: grid; grid-template-columns: 1fr 2fr; gap: 20px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mb-8 { margin-bottom: 32px; }
.mt-4 { margin-top: 16px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

/* ============================================================
   LOADING OVERLAY
   ============================================================ */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: hsla(222, 22%, 7%, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}

#loading-overlay.visible { display: flex; }

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ============================================================
   CHARTS
   ============================================================ */
.chart-container {
  position: relative;
  width: 100%;
}

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
  #sidebar, #topbar, .no-print { display: none !important; }
  #main-wrapper { margin: 0 !important; }
  #main-content { padding: 0 !important; }
  body { background: white !important; color: black !important; }
  .card { border: 1px solid #ccc !important; background: white !important; }
  .report-header { margin-bottom: 20px; }
  .page-break { page-break-after: always; }
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}

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

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  :root { --sidebar-width: 220px; }
}

@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }

  #sidebar {
    transform: translateX(-260px);
    width: 260px;
  }

  #sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  #topbar { left: 0; }
  #main-wrapper { margin-left: 0; }

  .grid-2, .grid-3, .grid-2-1, .grid-1-2 {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  #main-content { padding: 16px; }

  .page-header { flex-direction: column; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}
