*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-bg: #1B1C1E;
  --sidebar-hover: rgba(255,255,255,0.05);
  --sidebar-active-bg: rgba(157,192,224,0.14);
  --sidebar-active: #9DC0E0;
  --sidebar-text: #9CA1AA;
  --sidebar-text-active: #F5F5F7;
  --sidebar-width: 240px;

  --topbar-height: 60px;
  --topbar-bg: #FFFFFF;

  --accent: #33526E;
  --accent-hover: #28405A;
  --accent-light: #E7EEF4;

  --page-bg: #F3F4F6;
  --surface: #FFFFFF;
  --surface-2: #EEF0F2;
  --border: #E2E4E8;
  --border-strong: #C9CDD3;
  --text: #1B1C1E;
  --text-muted: #676B72;
  --text-light: #9BA0A8;

  --success: #2E7D46;
  --success-light: #E7F3EA;
  --danger: #B23A2F;
  --danger-light: #F6E7E4;
  --warning: #A6740A;
  --warning-light: #F5ECD4;

  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(20,21,23,0.05);
  --shadow: 0 2px 8px rgba(20,21,23,0.08);
  --shadow-lg: 0 14px 32px rgba(20,21,23,0.18);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { scrollbar-color: var(--border-strong) transparent; }

body.portal-layout {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  background: var(--page-bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ─── Sidebar ─── */
#sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-logo {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 18px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
  gap: 10px;
}
.logo-wordmark { font-size: 14px; font-weight: 700; color: #f5f5f7; letter-spacing: -0.1px; line-height: 1.3; }
.sidebar-logo-img { height: 22px; width: auto; display: block; filter: brightness(0) invert(1); }
.logo-sub { font-size: 10px; color: var(--sidebar-text); text-transform: uppercase; letter-spacing: 0.7px; margin-top: 4px; }

#sidenav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px 0;
  scrollbar-width: none;
}
#sidenav::-webkit-scrollbar { display: none; }

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: rgba(167,158,137,0.55);
  padding: 14px 10px 6px;
}

.nav-list { list-style: none; }
.nav-list li { margin-bottom: 1px; position: relative; }
.nav-list li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
  position: relative;
}
.nav-list li a:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-active);
}
.nav-list li.current a {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active);
  font-weight: 600;
}
.nav-icon {
  width: 17px; height: 17px;
  flex-shrink: 0;
  opacity: 0.65;
  transition: opacity 0.15s;
}
.nav-list li.current .nav-icon,
.nav-list li a:hover .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
  position: relative;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}
.sidebar-user:hover { background: var(--sidebar-hover); }
.sidebar-user-avatar {
  width: 30px; height: 30px;
  border-radius: 6px;
  background: rgba(157,192,224,0.18);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--sidebar-active);
  text-transform: uppercase;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: #ececf1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 11px;
  color: var(--sidebar-text);
  text-transform: capitalize;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-chevron { width: 14px; height: 14px; color: var(--sidebar-text); flex-shrink: 0; transition: transform 0.15s; }
.sidebar-user.open .sidebar-user-chevron { transform: rotate(180deg); }

.sidebar-user-menu {
  display: none;
  position: absolute;
  left: 10px; right: 10px; bottom: calc(100% + 6px);
  background: #26272A;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 5px;
}
.sidebar-user-menu.open { display: block; }
.sidebar-user-menu a {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 5px;
  color: #D4D5D8; text-decoration: none; font-size: 13px; font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.sidebar-user-menu a:hover { background: rgba(255,255,255,0.06); color: #f5f5f7; }
.sidebar-user-menu a.danger:hover { background: rgba(178,58,47,0.16); color: #e29a90; }
.sidebar-user-menu .menu-divider { height: 1px; background: rgba(255,255,255,0.08); margin: 5px 4px; }
.sidebar-user-menu a svg { width: 15px; height: 15px; }

/* ─── Top Bar ─── */
#topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 0 26px;
  justify-content: space-between;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-breadcrumb-current { color: var(--text); font-weight: 600; font-size: 14.5px; letter-spacing: -0.1px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* ─── Main Content ─── */
#main-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
  padding: 28px;
}
#content-body { width: 100%; }

/* ─── Page Header ─── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 20px; font-weight: 700; color: var(--text); letter-spacing: -0.2px; line-height: 1.3; }
.page-title small { font-size: 13px; color: var(--text-muted); margin-left: 9px; font-weight: 500; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 550; cursor: pointer;
  border: 1px solid transparent; text-decoration: none;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  line-height: 1.4; white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); border-color: #B7BBC2; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 5px; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #993127; border-color: #993127; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #24663a; border-color: #24663a; }
.btn-block { width: 100%; justify-content: center; padding: 10px; font-size: 14px; font-weight: 600; }
.btn-icon { padding: 7px 9px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ─── Cards ─── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-body { padding: 20px; }
.card-header { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 13.5px; font-weight: 650; color: var(--text); letter-spacing: -0.1px; }

/* ─── Dashboard charts ─── */
.dashboard-charts-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 24px; }
@media (max-width: 720px) { .dashboard-charts-grid { grid-template-columns: 1fr; } }

/* ─── Stats Grid ─── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.stat-icon { width: 36px; height: 36px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.stat-icon svg { width: 18px; height: 18px; }
.stat-card.accent-blue .stat-icon { background: var(--accent-light); color: var(--accent); }
.stat-card.accent-green .stat-icon { background: var(--success-light); color: var(--success); }
.stat-card.accent-red .stat-icon { background: var(--danger-light); color: var(--danger); }
.stat-card.accent-yellow .stat-icon { background: var(--warning-light); color: var(--warning); }
.stat-value { font-size: 27px; font-weight: 700; color: var(--text); letter-spacing: -0.6px; line-height: 1; margin-bottom: 6px; }
.stat-label { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }

/* ─── Toolbar ─── */
.table-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-light); pointer-events: none; }
.search-input { padding: 7px 11px 7px 33px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 13px; width: 260px; background: var(--surface); color: var(--text); }
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(51,82,110,0.12); }
.filter-select { padding: 7px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 13px; background: var(--surface); color: var(--text); cursor: pointer; }
.filter-select:focus { outline: none; border-color: var(--accent); }

/* ─── Data Table ─── */
.data-table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table thead th { background: var(--surface-2); border-bottom: 1px solid var(--border); padding: 11px 16px; text-align: left; font-weight: 650; font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px; white-space: nowrap; }
.data-table tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table td { padding: 12px 16px; vertical-align: middle; color: var(--text); }
.data-table td.muted { color: var(--text-muted); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ─── Empty state ─── */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 52px 24px; }
.empty-state-icon { width: 44px; height: 44px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; color: var(--text-light); margin-bottom: 14px; }
.empty-state-icon svg { width: 20px; height: 20px; }
.empty-state-title { font-size: 14px; font-weight: 650; color: var(--text); margin-bottom: 4px; }
.empty-state-sub { font-size: 13px; color: var(--text-muted); max-width: 320px; line-height: 1.55; }
.empty-state .btn { margin-top: 16px; }

/* ─── Status Pills ─── */
.status-pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 4px; font-size: 11.5px; font-weight: 650; text-transform: capitalize; white-space: nowrap; }
.status-pill::before { content: ''; display: inline-block; width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.status-pill.active, .status-pill.approved, .status-pill.completed { background: var(--success-light); color: #1e5c31; }
.status-pill.active::before, .status-pill.approved::before, .status-pill.completed::before { background: var(--success); }
.status-pill.terminated, .status-pill.rejected, .status-pill.suspended { background: var(--danger-light); color: #862e25; }
.status-pill.terminated::before, .status-pill.rejected::before, .status-pill.suspended::before { background: var(--danger); }
.status-pill.pending_review, .status-pill.invited, .status-pill.pending { background: var(--warning-light); color: #7c5908; }
.status-pill.pending_review::before, .status-pill.invited::before, .status-pill.pending::before { background: var(--warning); }
.status-pill.inactive { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.status-pill.inactive::before { background: var(--text-light); }

/* ─── Pagination ─── */
.pagination { display: flex; align-items: center; gap: 4px; margin-top: 20px; justify-content: flex-end; }
.pagination a, .pagination span { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 30px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 13px; color: var(--text); text-decoration: none; background: var(--surface); }
.pagination a:hover { background: var(--surface-2); border-color: #B7BBC2; }
.pagination span.current-page { background: var(--accent); color: #fff; border-color: var(--accent); }
.pagination-info { color: var(--text-muted); font-size: 13px; margin-right: 8px; }

/* ─── Notice / Alert (static fallback, still used pre-JS) ─── */
.notice { padding: 11px 15px; border-radius: var(--radius-sm); margin-bottom: 20px; font-size: 13px; font-weight: 500; border: 1px solid transparent; }
.notice.success { background: var(--success-light); color: #1e5c31; border-color: #bfdcc4; }
.notice.error   { background: var(--danger-light);  color: #862e25; border-color: #e3c3bd; }
.notice.info    { background: var(--accent-light);  color: #2a4258; border-color: #c7d5e0; }

/* ─── Toasts ─── */
#toast-stack {
  position: fixed; top: 18px; right: 18px; z-index: 900;
  display: flex; flex-direction: column; gap: 10px;
  width: 340px; max-width: calc(100vw - 36px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 13px;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.2s var(--ease);
  border-left: 3px solid var(--accent);
}
.toast.leaving { animation: toastOut 0.16s var(--ease) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(12px); } }
.toast-icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.toast.success { border-left-color: var(--success); }
.toast.success .toast-icon { color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.error .toast-icon { color: var(--danger); }
.toast.info { border-left-color: var(--accent); }
.toast.info .toast-icon { color: var(--accent); }
.toast-body { flex: 1; min-width: 0; }
.toast-message { font-size: 13px; font-weight: 500; color: var(--text); line-height: 1.5; }
.toast-close { flex-shrink: 0; width: 18px; height: 18px; border: none; background: none; cursor: pointer; color: var(--text-light); padding: 0; display: flex; align-items: center; justify-content: center; border-radius: 4px; }
.toast-close:hover { color: var(--text); background: var(--surface-2); }
.toast-close svg { width: 13px; height: 13px; }

/* ─── Info Rows ─── */
.info-row { display: flex; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; gap: 12px; }
.info-row:last-child { border-bottom: none; }
.info-label { width: 42%; color: var(--text-muted); font-weight: 500; flex-shrink: 0; }
.info-value { color: var(--text); flex: 1; }

/* ─── Section Label ─── */
.section-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.7px; color: var(--text-muted); margin-bottom: 12px; }

/* ─── Modal ─── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(20,21,23,0.5); z-index: 500; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius-lg); padding: 26px; width: 440px; max-width: 92vw; box-shadow: var(--shadow-lg); animation: modalIn 0.16s var(--ease); max-height: 88vh; overflow-y: auto; }
@keyframes modalIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.modal-title { font-size: 15px; font-weight: 700; margin-bottom: 8px; color: var(--text); }
.modal-body { font-size: 13.5px; color: var(--text-muted); margin-bottom: 20px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ─── Forms ─── */
.form-group { margin-bottom: 16px; }
.form-group label, .form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-control { width: 100%; padding: 9px 12px; border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 14px; color: var(--text); background: var(--surface); transition: border-color 0.15s, box-shadow 0.15s; }
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(51,82,110,0.14); }
textarea.form-control { resize: vertical; }
select.form-control { cursor: pointer; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ─── OTP code input ─── */
.otp-input { text-align: center; letter-spacing: 10px; font-size: 24px; font-weight: 700; }

/* ─── Auth / unified login page ─── */
body.auth-page {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--page-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.auth-hero {
  flex-shrink: 0;
  background: var(--sidebar-bg);
  padding: 34px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-hero-logo {
  background: #fff;
  border-radius: var(--radius-md, 8px);
  padding: 12px 22px;
  display: inline-flex;
  align-items: center;
}
.auth-hero-logo img { height: 32px; width: auto; display: block; }

.page-watermark {
  position: fixed;
  right: 16px;
  bottom: 14px;
  z-index: 50;
  opacity: 0.6;
  pointer-events: none;
}
.page-watermark img { height: 20px; width: auto; display: block; }
.auth-body {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 36px 20px;
}
.auth-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 44px 40px; width: 440px; max-width: 100%; box-shadow: var(--shadow-lg); }
.auth-heading { text-align: center; margin-bottom: 30px; }
.auth-heading h1 { font-size: 22px; font-weight: 700; color: var(--text); letter-spacing: -0.2px; }
.auth-heading p { font-size: 13.5px; color: var(--text-muted); margin-top: 6px; line-height: 1.5; }
.auth-logo { text-align: center; margin-bottom: 26px; }
.auth-logo .sub { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.auth-error { background: var(--danger-light); border: 1px solid #e3c3bd; border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; color: #862e25; margin-bottom: 16px; }
.auth-hint { background: var(--accent-light); border: 1px solid #c7d5e0; border-radius: var(--radius-sm); padding: 10px 14px; font-size: 12.5px; color: #2a4258; margin-bottom: 16px; line-height: 1.5; }
.auth-footer-link { text-align: center; margin-top: 22px; font-size: 13px; color: var(--text-muted); }
.auth-footer-link a { color: var(--accent); text-decoration: none; font-weight: 600; }
.auth-security-note { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); font-size: 11.5px; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; }
.auth-security-note svg { width: 13px; height: 13px; flex-shrink: 0; }

/* ─── Responsive portal shell (sidebar collapses to an off-canvas drawer) ─── */
.sidebar-toggle {
  display: none;
  align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-toggle svg { width: 18px; height: 18px; }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(20,21,23,0.45);
  z-index: 250;
}
.sidebar-backdrop.open { display: block; }

@media (max-width: 880px) {
  .sidebar-toggle { display: inline-flex; }
  #sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s var(--ease);
    z-index: 300;
    box-shadow: var(--shadow-lg);
  }
  #sidebar.open { transform: translateX(0); }
  #topbar { left: 0; padding: 0 16px; }
  #main-content { margin-left: 0; padding: 18px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  #main-content { padding: 14px; }
  .modal { width: 100%; padding: 20px; }
  .search-input { width: 100%; }
  .table-toolbar { flex-direction: column; align-items: stretch; }
  #toast-stack { left: 10px; right: 10px; width: auto; top: 10px; }
  .form-row { grid-template-columns: 1fr; }
}
