:root {
  --navy: #0F172A;
  --navy-secondary: #111C33;
  --primary: #2563EB;
  --accent: #06B6D4;
  --success: #16A34A;
  --warning: #D97706;
  --danger: #DC2626;
  --bg: #F6F8FC;
  --surface: #FFFFFF;
  --text: #172033;
  --muted: #64748B;
  --border: #E2E8F0;
  
  --radius-sm: 0.5rem;
  --radius-md: 0.875rem; /* 14px */
  --radius-lg: 1.125rem; /* 18px */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 80px;
  --topbar-height: 70px;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --transition: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* App Shell */
.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: width var(--transition), transform var(--transition);
}
.sidebar.collapsed { width: var(--sidebar-collapsed-width); }

.sidebar-header {
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
}
.brand i { color: var(--accent); font-size: 1.4rem; }

.sidebar-profile {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-profile-name { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.2rem; text-overflow: ellipsis; overflow: hidden; }
.sidebar-profile-role { font-size: 0.75rem; color: #94A3B8; text-transform: uppercase; letter-spacing: 0.05em; }

.sidebar-nav {
  padding: 1rem 0.75rem;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #64748B;
  margin: 1.5rem 0.75rem 0.5rem;
  white-space: nowrap;
}

.sidebar a.nav-link {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  color: #94A3B8;
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin: 0.25rem 0;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: var(--transition);
  white-space: nowrap;
}
.sidebar a.nav-link i { font-size: 1.15rem; width: 24px; text-align: center; }

.sidebar a.nav-link:hover, .sidebar a.nav-link:focus-visible {
  background: var(--navy-secondary);
  color: #fff;
  outline: none;
}
.sidebar a.nav-link.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
  position: relative;
}
.sidebar a.nav-link.active::before {
  content: '';
  position: absolute;
  left: -0.75rem;
  top: 50%;
  transform: translateY(-50%);
  height: 20px;
  width: 4px;
  background: var(--accent);
  border-radius: 0 4px 4px 0;
}
.sidebar.collapsed a.nav-link.active::before {
  left: 0;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,0.05);
}
.sidebar-toggle-btn {
  background: transparent;
  border: none;
  color: #94A3B8;
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.9rem;
}
.sidebar-toggle-btn:hover { background: rgba(255,255,255,0.05); color: #fff; }

/* Collapsed Sidebar overrides */
.sidebar.collapsed .brand-text, 
.sidebar.collapsed .sidebar-profile-name, 
.sidebar.collapsed .sidebar-profile-role, 
.sidebar.collapsed .nav-section, 
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .sidebar-toggle-btn span {
  display: none;
}
.sidebar.collapsed .sidebar-header, .sidebar.collapsed .sidebar-profile { padding-left: 1rem; padding-right: 1rem; justify-content: center; }
.sidebar.collapsed .sidebar-nav { padding-left: 0.5rem; padding-right: 0.5rem; }
.sidebar.collapsed a.nav-link { justify-content: center; padding: 0.75rem 0; }
.sidebar.collapsed .sidebar-toggle-btn { justify-content: center; }
.sidebar.collapsed .sidebar-toggle-btn i { transform: rotate(180deg); }


/* Main Content Area */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0; /* prevent flex blowout */
  transition: margin-left var(--transition);
}
.sidebar.collapsed + .main-wrapper { margin-left: var(--sidebar-collapsed-width); }

/* Topbar */
.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}
.mobile-toggle { display: none; }
.page-title { font-weight: 700; font-size: 1.5rem; margin: 0; color: var(--navy); }

/* Content */
.content {
  padding: 2rem;
  flex: 1;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  font-weight: 600;
}
.card-body { padding: 1.5rem; }

.stat-card {
  padding: 1.5rem;
  height: 100%;
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}
.stat-icon-blue { background: rgba(37, 99, 235, 0.1); color: var(--primary); }
.stat-icon-green { background: rgba(22, 163, 74, 0.1); color: var(--success); }
.stat-icon-cyan { background: rgba(6, 182, 212, 0.1); color: var(--accent); }
.stat-icon-orange { background: rgba(217, 119, 6, 0.1); color: var(--warning); }
.stat-icon-navy { background: rgba(15, 23, 42, 0.1); color: var(--navy); }

.stat-details { flex: 1; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--navy); line-height: 1.1; margin-bottom: 0.25rem; }
.stat-label { color: var(--muted); font-size: 0.875rem; font-weight: 500; }

/* Buttons */
.btn {
  font-weight: 500;
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  transition: var(--transition);
}
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus-visible { background: #1D4ED8; border-color: #1D4ED8; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover, .btn-accent:focus-visible { background: #0891B2; border-color: #0891B2; color: #fff; }
.btn-outline-secondary { color: var(--muted); border-color: var(--border); }
.btn-outline-secondary:hover { background: var(--bg); color: var(--navy); border-color: #CBD5E1; }

/* Tables */
.table { margin-bottom: 0; }
.table>:not(caption)>*>* { padding: 1rem 1.25rem; vertical-align: middle; border-bottom-color: var(--border); }
.table thead th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: #F8FAFC;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.table tbody tr { transition: background-color var(--transition); }
.table tbody tr:hover { background-color: rgba(246,248,252,0.6); }

/* Badges */
.badge { font-weight: 600; padding: 0.35em 0.65em; border-radius: 4px; }
.bg-success { background-color: rgba(22, 163, 74, 0.1) !important; color: var(--success); }
.bg-warning { background-color: rgba(217, 119, 6, 0.1) !important; color: var(--warning); }
.bg-danger { background-color: rgba(220, 38, 38, 0.1) !important; color: var(--danger); }
.bg-secondary { background-color: rgba(100, 116, 139, 0.1) !important; color: var(--muted); }

/* Forms */
.form-label { font-weight: 600; font-size: 0.875rem; color: var(--navy); margin-bottom: 0.5rem; }
.form-control, .form-select {
  border-color: #CBD5E1;
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.required:after { content: " *"; color: var(--danger); }

/* Specific Modules */
.empty-state { text-align: center; padding: 4rem 1rem; color: var(--muted); }
.empty-state i { font-size: 3.5rem; color: #CBD5E1; margin-bottom: 1rem; display: block; }
.document-preview { max-height: 280px; max-width: 100%; object-fit: contain; background: #edf1f5; border-radius: var(--radius-sm); }
.signature-pad { width: 100%; height: 210px; border: 2px dashed #CBD5E1; border-radius: var(--radius-sm); background: #fff; touch-action: none; }
.camera-preview { width: 100%; max-height: 340px; background: #111; border-radius: var(--radius-sm); object-fit: cover; }
.credential-box { background: #fff8e5; border: 1px solid #e4bd63; padding: 1.25rem; border-radius: var(--radius-sm); font-family: ui-monospace, monospace; }
.details-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem 2rem; }
.details-grid dt { font-size: 0.75rem; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.details-grid dd { margin: 0; font-weight: 500; font-size: 0.95rem; }
.filter-card { background: var(--surface); padding: 1.25rem; border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 1.5rem; }

/* Auth Pages (Split Screen) */
.auth-page {
  min-height: 100vh;
  display: flex;
  background: var(--surface);
}
.auth-brand-panel {
  flex: 55%;
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 4rem;
  position: relative;
  overflow: hidden;
}
.auth-brand-panel::before {
  content: '';
  position: absolute;
  top: -50%; left: -50%; width: 200%; height: 200%;
  background: radial-gradient(circle at center, rgba(37,99,235,0.15) 0%, transparent 50%);
  pointer-events: none;
}
.auth-illustration {
  max-width: 80%;
  margin: 3rem auto;
  display: block;
}
.auth-features {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: 2rem;
}
.auth-feature {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.auth-feature i {
  color: var(--accent);
  font-size: 1.5rem;
  background: rgba(6,182,212,0.1);
  width: 48px; height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-feature h4 { margin: 0; font-size: 1rem; font-weight: 600; }
.auth-feature p { margin: 0; font-size: 0.85rem; color: #94A3B8; }

.auth-form-panel {
  flex: 45%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem;
  max-width: 600px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

/* Sidebar Backdrop for Mobile */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 1030;
  display: none;
  opacity: 0;
  transition: opacity var(--transition);
}

/* Responsive */
@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; opacity: 1; }
  
  .main-wrapper, .sidebar.collapsed + .main-wrapper { margin-left: 0; }
  .mobile-toggle { display: inline-flex; }
  .topbar { padding: 0 1.5rem; }
  .content { padding: 1.5rem; }
  
  .auth-page { flex-direction: column; }
  .auth-brand-panel { display: none; }
  .auth-form-panel { flex: 1; max-width: 100%; align-items: center; padding: 2rem; background: var(--bg); }
  .auth-card { background: var(--surface); padding: 2rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }
}

@media (max-width: 575px) {
  .topbar { padding: 0 1rem; }
  .content { padding: 1rem; }
  .details-grid { grid-template-columns: 1fr; }
  .table-actions { min-width: 150px; }
}
