/* ═══════════════════════════════════════════════════════════════════
   OrbitHR AIOS v2 — Design System
   Variables → Reset → Layout → Components → Utilities → Dark Mode
═══════════════════════════════════════════════════════════════════ */

/* ── CSS Variables ────────────────────────────────────────────── */
:root {
  /* Brand */
  --primary: #5B4EFF;
  --primary-dark: #4338E0;
  --primary-light: #EEF0FF;
  --accent: #FF6B35;
  --accent-light: #FFF0EB;

  /* Neutrals */
  --bg: #F5F6FA;
  --bg-card: #FFFFFF;
  --bg-input: #FFFFFF;
  --bg-hover: #F0F1F8;
  --bg-sidebar: #FFFFFF;
  --bg-topbar: #FFFFFF;

  --border: #E5E7EB;
  --border-focus: var(--primary);

  --text: #111827;
  --text-secondary: #6B7280;
  --text-muted: #9CA3AF;
  --text-inverse: #FFFFFF;

  /* Status colours */
  --success: #10B981; --success-bg: #ECFDF5;
  --warning: #F59E0B; --warning-bg: #FFFBEB;
  --danger:  #EF4444; --danger-bg:  #FEF2F2;
  --info:    #3B82F6; --info-bg:    #EFF6FF;

  /* AI feature accent */
  --ai: #8B5CF6; --ai-bg: #F5F3FF;

  /* Layout */
  --sidebar-w: 248px;
  --sidebar-collapsed-w: 64px;
  --topbar-h: 56px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.14);

  /* Transitions */
  --t: 200ms ease;
  --t-slow: 350ms ease;

  /* Font */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Dark Mode ────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg: #0F1117;
  --bg-card: #1A1D27;
  --bg-input: #252836;
  --bg-hover: #252836;
  --bg-sidebar: #13151F;
  --bg-topbar: #1A1D27;
  --border: #2D3045;
  --text: #F1F2F6;
  --text-secondary: #9CA3AF;
  --text-muted: #6B7280;
  --primary-light: #1E1A4A;
  --accent-light: #2A1A10;
  --success-bg: #052E20;
  --warning-bg: #2A1F00;
  --danger-bg: #2D0D0D;
  --info-bg: #0C1E3A;
  --ai-bg: #1B1238;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.5);
}

/* ── Reset ────────────────────────────────────────────────────── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden; /* prevent body scroll — main scrolls instead */
}
a { text-decoration: none; color: inherit; cursor: pointer; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
input,select,textarea { font-family: var(--font); }
ul { list-style: none; }
img { max-width: 100%; display: block; }

/* ═══════════════════════════════════════════════════════════════
   LOGIN SCREEN
═══════════════════════════════════════════════════════════════ */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
}
.login-bg {
  position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--primary) 0%, #8B5CF6 50%, var(--accent) 100%);
  opacity: .06;
}
.login-card {
  position: relative;
  width: 100%; max-width: 420px;
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 40px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.login-logo {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 32px;
}
.logo-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--primary), #8B5CF6);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.logo-name { font-size: 18px; font-weight: 700; color: var(--text); }
.logo-tagline { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.login-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-sub { color: var(--text-secondary); margin-bottom: 24px; }
.login-roles {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 16px; padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
}
.role-chip {
  padding: 4px 12px; border-radius: 20px;
  background: var(--primary-light); color: var(--primary);
  font-size: 12px; font-weight: 500;
  transition: background var(--t);
}
.role-chip:hover { background: var(--primary); color: #fff; }
.login-footer {
  margin-top: 24px; padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-muted);
  text-align: center;
}
.link-sm { font-size: 12px; color: var(--primary); float: right; }
.link-sm:hover { text-decoration: underline; }
.input-icon-wrap { position: relative; }
.input-icon-btn {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 16px; opacity: .5;
}
.input-icon-btn:hover { opacity: 1; }

/* ═══════════════════════════════════════════════════════════════
   APP LAYOUT
═══════════════════════════════════════════════════════════════ */
#app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--t-slow), min-width var(--t-slow);
  overflow: hidden;
  position: relative;
  z-index: 100;
}
#sidebar.collapsed {
  width: var(--sidebar-collapsed-w);
  min-width: var(--sidebar-collapsed-w);
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  overflow: hidden; white-space: nowrap;
}
.sidebar-logo-icon {
  font-size: 20px;
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--primary), #8B5CF6);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-logo-text {
  font-size: 15px; font-weight: 700; color: var(--text);
  transition: opacity var(--t);
}
.sidebar-collapse-btn {
  color: var(--text-muted); font-size: 10px; padding: 4px;
  border-radius: 4px; transition: all var(--t); flex-shrink: 0;
}
.sidebar-collapse-btn:hover { background: var(--bg-hover); color: var(--text); }
#sidebar.collapsed .sidebar-collapse-btn { transform: rotate(180deg); }
#sidebar.collapsed .sidebar-logo-text { opacity: 0; width: 0; }

/* Sidebar search */
.sidebar-search {
  position: relative;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-search input {
  width: 100%;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 30px 7px 12px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: all var(--t);
}
.sidebar-search input:focus { border-color: var(--primary); background: var(--bg-input); }
.search-icon {
  position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
  font-size: 13px; pointer-events: none;
}
#sidebar.collapsed .sidebar-search { display: none; }

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.nav-section { margin-bottom: 4px; }
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  padding: 10px 8px 4px;
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap;
  overflow: hidden;
}
#sidebar.collapsed .nav-section-label { opacity: 0; }
.badge-ai {
  background: var(--ai-bg); color: var(--ai);
  font-size: 9px; padding: 1px 5px; border-radius: 4px;
  font-weight: 700;
}
.nav-section-ai .nav-item .nav-icon { color: var(--ai); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--t);
  white-space: nowrap;
  overflow: hidden;
  position: relative;
}
.nav-item:hover { background: var(--bg-hover); }
.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}
.nav-item.active .nav-icon { filter: none; }
.nav-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.nav-label { font-size: 13px; transition: opacity var(--t); }
#sidebar.collapsed .nav-label { opacity: 0; width: 0; }
#sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }
#sidebar.collapsed .nav-item .nav-icon { font-size: 18px; }

/* Sidebar user */
.sidebar-user {
  border-top: 1px solid var(--border);
  padding: 10px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  min-height: 60px;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8B5CF6);
  color: #fff; font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-info { flex: 1; overflow: hidden; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role {
  font-size: 11px; color: var(--text-muted);
  white-space: nowrap;
}
.user-menu-btn {
  color: var(--text-muted); font-size: 18px; line-height: 1;
  padding: 4px; border-radius: 4px;
  transition: all var(--t); flex-shrink: 0;
}
.user-menu-btn:hover { color: var(--text); background: var(--bg-hover); }
.user-menu {
  position: absolute;
  bottom: 100%; right: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 160px;
  overflow: hidden;
  z-index: 200;
}
.user-menu a {
  display: block;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
  transition: background var(--t);
}
.user-menu a:hover { background: var(--bg-hover); }
.user-menu a.danger { color: var(--danger); }
#sidebar.collapsed .user-info, #sidebar.collapsed .user-menu-btn { display: none; }

/* ── Top Bar ──────────────────────────────────────────────────── */
#main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
#topbar {
  height: var(--topbar-h);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: var(--shadow);
  z-index: 50;
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.mobile-menu-btn {
  display: none; font-size: 18px; color: var(--text-secondary);
  padding: 6px; border-radius: var(--radius);
}
.mobile-menu-btn:hover { background: var(--bg-hover); }
.breadcrumb { font-size: 13px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.bc-sep { opacity: .4; }
#bc-current { color: var(--text); font-weight: 600; }

.topbar-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  color: var(--text-secondary);
  position: relative;
  transition: all var(--t);
}
.topbar-btn:hover { background: var(--bg-hover); color: var(--text); }

/* Notifications */
.notif-badge {
  position: absolute; top: 4px; right: 4px;
  background: var(--danger); color: #fff;
  font-size: 9px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  line-height: 1;
}
.notif-panel {
  position: absolute; top: var(--topbar-h); right: 12px;
  width: 320px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
}
.notif-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.notif-header button { font-size: 12px; color: var(--primary); }
.notif-list { max-height: 320px; overflow-y: auto; }
.notif-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--t);
}
.notif-item:hover { background: var(--bg-hover); }
.notif-item.unread { border-left: 3px solid var(--primary); }
.notif-item-title { font-size: 13px; font-weight: 500; }
.notif-item-body { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.notif-item-time { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.notif-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ── Main Content ─────────────────────────────────────────────── */
#content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#content::-webkit-scrollbar { width: 6px; }
#content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.content-loader {
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px;
  height: 200px;
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════
   COMPONENT LIBRARY
═══════════════════════════════════════════════════════════════ */

/* ── Page Header ──────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  margin-bottom: 24px;
}
.page-header-left h1 {
  font-size: 20px; font-weight: 700; color: var(--text);
}
.page-header-left p {
  font-size: 13px; color: var(--text-secondary); margin-top: 2px;
}
.page-header-right { display: flex; align-items: center; gap: 8px; }

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Stat cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 28px; font-weight: 700; margin: 6px 0; line-height: 1; }
.stat-delta { font-size: 12px; color: var(--success); }
.stat-delta.down { color: var(--danger); }
.stat-icon {
  float: right; font-size: 28px; opacity: .15;
  margin-top: -4px;
}

/* ── Grid layouts ─────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  transition: all var(--t);
  cursor: pointer; border: none; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--bg-hover); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #DC2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #059669; }
.btn-ghost { background: none; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }
.btn-outline { background: none; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-ai { background: var(--ai-bg); color: var(--ai); border: 1px solid #D8D0FF; }
.btn-ai:hover:not(:disabled) { background: var(--ai); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-full { width: 100%; }
.btn-icon { padding: 8px; width: 34px; height: 34px; border-radius: var(--radius); }
.btn-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn-loading::after {
  content: ''; position: absolute;
  width: 14px; height: 14px;
  border: 2px solid transparent; border-top-color: #fff;
  border-radius: 50%; animation: spin .6s linear infinite;
}

/* ── Forms ────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color var(--t), box-shadow var(--t);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,78,255,.12);
}
.form-input.error, .form-select.error { border-color: var(--danger); }
.form-help { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 11px; color: var(--danger); margin-top: 4px; }
.form-textarea { resize: vertical; min-height: 90px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; }
.form-section { margin-bottom: 24px; }
.form-section-title {
  font-size: 13px; font-weight: 700; color: var(--text);
  margin-bottom: 12px; padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-light);
}

/* ── Table ────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap; gap: 10px;
}
.table-search {
  position: relative;
}
.table-search input {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 12px 7px 32px;
  font-size: 13px; color: var(--text);
  outline: none; width: 220px;
  transition: all var(--t);
}
.table-search input:focus { border-color: var(--primary); background: var(--bg-input); }
.table-search::before {
  content: '🔍'; position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%); font-size: 12px; pointer-events: none;
}
.table-actions { display: flex; gap: 8px; align-items: center; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 10px 14px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--text); }
.data-table td {
  padding: 12px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }
.data-table .actions-col { text-align: right; white-space: nowrap; }
.data-table .actions-col button { margin-left: 4px; }
.table-empty {
  text-align: center; padding: 48px 20px;
  color: var(--text-muted);
}
.table-empty .empty-icon { font-size: 40px; margin-bottom: 12px; }
.table-empty p { font-size: 14px; }

/* Pagination */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-secondary);
}
.pagination-btns { display: flex; gap: 4px; }
.page-btn {
  width: 30px; height: 30px;
  border-radius: var(--radius);
  background: none; border: 1px solid var(--border);
  color: var(--text); font-size: 12px; cursor: pointer;
  transition: all var(--t);
  display: flex; align-items: center; justify-content: center;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Modal ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: modalIn .2s ease;
}
.modal-box.modal-lg { max-width: 760px; }
.modal-box.modal-xl { max-width: 960px; }
.modal-box.modal-sm { max-width: 400px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 30px; height: 30px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 18px; cursor: pointer;
  transition: all var(--t);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text); }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
}
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
  flex-shrink: 0;
}

/* Modal tabs */
.modal-tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  flex-shrink: 0;
}
.modal-tab {
  padding: 10px 16px;
  font-size: 13px; font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--t);
  white-space: nowrap;
}
.modal-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.modal-tab:hover:not(.active) { color: var(--text); }
.modal-tab-panel { display: none; }
.modal-tab-panel.active { display: block; }

/* ── Badges ───────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-info    { background: var(--info-bg);    color: var(--info); }
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-neutral { background: var(--bg-hover); color: var(--text-secondary); }
.badge-ai      { background: var(--ai-bg); color: var(--ai); }

/* ── Avatar ───────────────────────────────────────────────────── */
.avatar {
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8B5CF6);
  color: #fff; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-md { width: 36px; height: 36px; font-size: 14px; }
.avatar-lg { width: 48px; height: 48px; font-size: 18px; }
.avatar-xl { width: 64px; height: 64px; font-size: 24px; }

/* ── Progress bar ─────────────────────────────────────────────── */
.progress { background: var(--bg-hover); border-radius: 4px; height: 6px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 4px; background: var(--primary); transition: width .5s ease; }
.progress-bar.success { background: var(--success); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger  { background: var(--danger); }

/* ── Alert ────────────────────────────────────────────────────── */
[hidden] { display: none !important; }
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 13px; display: flex; align-items: flex-start; gap: 8px;
  margin-bottom: 16px;
}
.alert-success { background: var(--success-bg); color: #065F46; border: 1px solid #A7F3D0; }
.alert-warning { background: var(--warning-bg); color: #92400E; border: 1px solid #FDE68A; }
.alert-error   { background: var(--danger-bg);  color: #991B1B; border: 1px solid #FECACA; }
.alert-info    { background: var(--info-bg);    color: #1E40AF; border: 1px solid #BFDBFE; }

/* ── Toast ────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  min-width: 280px; max-width: 360px;
  pointer-events: all;
  animation: toastIn .25s ease;
  transition: all .25s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info    { border-left: 3px solid var(--info); }
.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast-body { flex: 1; }
.toast-title { font-size: 13px; font-weight: 600; }
.toast-msg { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.toast-close { color: var(--text-muted); font-size: 16px; cursor: pointer; flex-shrink: 0; }
.toast-close:hover { color: var(--text); }

/* ── Search Panel ─────────────────────────────────────────────── */
.search-results-panel {
  position: absolute;
  top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  overflow: hidden;
  max-height: 320px;
  overflow-y: auto;
}
.search-result-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background var(--t);
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-icon { font-size: 16px; width: 24px; text-align: center; }
.search-result-text { flex: 1; }
.search-result-title { font-size: 13px; font-weight: 500; }
.search-result-sub { font-size: 11px; color: var(--text-muted); }

/* ── Tabs (page-level) ────────────────────────────────────────── */
.tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab-btn {
  padding: 10px 18px;
  font-size: 13px; font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--t);
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn:hover:not(.active) { color: var(--text); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Pipeline / Kanban ────────────────────────────────────────── */
.pipeline {
  display: flex; gap: 12px;
  overflow-x: auto; padding-bottom: 12px;
}
.pipeline-col {
  min-width: 240px; max-width: 280px;
  background: var(--bg);
  border-radius: var(--radius-lg);
  padding: 12px;
  border: 1px solid var(--border);
}
.pipeline-col-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.pipeline-col-name { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.pipeline-count {
  background: var(--bg-hover); color: var(--text-muted);
  font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 10px;
}
.pipeline-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all var(--t);
}
.pipeline-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

/* ── AI Score ring ────────────────────────────────────────────── */
.score-ring {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800;
  flex-shrink: 0;
}
.score-ring.high   { background: var(--success-bg); color: var(--success); }
.score-ring.medium { background: var(--warning-bg); color: var(--warning); }
.score-ring.low    { background: var(--danger-bg);  color: var(--danger); }

/* ── Stepper ──────────────────────────────────────────────────── */
.stepper { display: flex; align-items: flex-start; margin-bottom: 28px; }
.step {
  display: flex; flex-direction: column; align-items: center;
  flex: 1; position: relative;
}
.step::after {
  content: ''; position: absolute; top: 14px; left: 50%;
  width: 100%; height: 2px; background: var(--border);
}
.step:last-child::after { display: none; }
.step.completed::after { background: var(--success); }
.step-dot {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--bg-hover); border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; z-index: 1;
  transition: all var(--t);
}
.step.active .step-dot { background: var(--primary); border-color: var(--primary); color: #fff; }
.step.completed .step-dot { background: var(--success); border-color: var(--success); color: #fff; }
.step-label { font-size: 11px; margin-top: 6px; color: var(--text-muted); text-align: center; }
.step.active .step-label { color: var(--primary); font-weight: 600; }

/* ── Risk meter ───────────────────────────────────────────────── */
.risk-meter {
  height: 8px; border-radius: 4px;
  background: linear-gradient(to right, var(--success), var(--warning), var(--danger));
  position: relative; margin-bottom: 4px;
}
.risk-needle {
  position: absolute; top: -4px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 3px solid var(--text);
  transform: translateX(-50%);
  transition: left .5s ease;
}

/* ── Copilot FAB ──────────────────────────────────────────────── */
.copilot-fab {
  position: fixed; bottom: 24px; right: 24px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ai), var(--primary));
  color: #fff; font-size: 22px;
  box-shadow: var(--shadow-lg);
  z-index: 500;
  transition: all var(--t);
  border: none; cursor: pointer;
}
.copilot-fab:hover { transform: scale(1.1); box-shadow: 0 12px 28px rgba(139,92,246,.4); }

/* ─── Divider / spacer ────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

/* ── Spinner ──────────────────────────────────────────────────── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner-sm { width: 18px; height: 18px; border-width: 2px; display: inline-block; }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 60px 20px; text-align: center;
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; opacity: .5; }
.empty-state h3 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.empty-state p { font-size: 13px; color: var(--text-secondary); max-width: 320px; }

/* ── Skeleton loader ──────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--border) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius);
  animation: shimmer 1.4s infinite;
}
.skeleton-row { height: 44px; margin-bottom: 4px; border-radius: 4px; }
.skeleton-text { height: 14px; margin-bottom: 8px; }

/* ═══════════════════════════════════════════════════════════════
   ANIMATIONS
═══════════════════════════════════════════════════════════════ */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes modalIn { from { opacity: 0; transform: scale(.96) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

.animate-fade { animation: fadeIn .3s ease; }
.animate-up   { animation: slideUp .3s ease; }

/* ═══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform var(--t-slow);
    box-shadow: none;
  }
  #sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  #main-wrap { width: 100%; }
  .mobile-menu-btn { display: flex !important; }
  .mobile-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.4);
    z-index: 190;
    display: none;
  }
  .mobile-overlay.show { display: block; }
  #content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .modal-box { max-width: 100%; margin: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; align-self: flex-end; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .pipeline { flex-direction: column; }
  .pipeline-col { max-width: 100%; min-width: 0; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ─── Print ───────────────────────────────────────────────────── */
@media print {
  #sidebar, #topbar, .copilot-fab, .toast-container { display: none !important; }
  #main-wrap { margin: 0; }
  #content { padding: 0; overflow: visible; }
  body { overflow: auto; }
}
