:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #111827;
  --muted: #667085;
  --line: #e5e7eb;
  --primary: #111827;
  --accent: #2563eb;
  --success: #0f9f6e;
  --danger: #dc2626;
  --shadow: 0 14px 36px rgba(15, 23, 42, .08);
  --radius: 18px;
  --sidebar: 252px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100vh; }
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.app-loading, .fatal-shell, .onboarding-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.boot-card, .fatal-card { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 30px; box-shadow: var(--shadow); display: grid; gap: 10px; min-width: 280px; text-align: center; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: linear-gradient(135deg, #111827, #2563eb); color: white; font-weight: 800; letter-spacing: -.04em; }
.boot-card .brand-mark, .fatal-card .brand-mark { margin: auto; }
.boot-card span, .fatal-card p, .fatal-card small { color: var(--muted); }

.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(420px, .95fr); }
.auth-panel { padding: clamp(36px, 6vw, 90px); background: radial-gradient(circle at 15% 15%, #284b8f 0, #111827 38%, #080d18 100%); color: white; display: flex; flex-direction: column; justify-content: space-between; gap: 50px; }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand > div:last-child { display: grid; }
.auth-brand span { color: rgba(255,255,255,.64); font-size: 12px; }
.auth-brand.compact { color: var(--text); margin-bottom: 10px; }
.auth-copy { max-width: 680px; }
.auth-copy h1 { font-size: clamp(42px, 5vw, 72px); line-height: .98; letter-spacing: -.055em; margin: 14px 0 24px; }
.auth-copy p { font-size: 18px; line-height: 1.65; color: rgba(255,255,255,.72); max-width: 620px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 11px; font-weight: 800; color: var(--muted); }
.auth-panel .eyebrow { color: #93c5fd; }
.auth-card-wrap { background: var(--surface); display: grid; place-items: center; padding: 40px; }
.auth-card-centered { grid-column: 1 / -1; }
.auth-card { width: min(100%, 430px); display: grid; gap: 20px; }
.auth-card h2 { margin: 8px 0 6px; font-size: 34px; letter-spacing: -.035em; }
.auth-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.auth-actions { display: flex; justify-content: space-between; gap: 12px; }

label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; color: #344054; }
input, select { width: 100%; border: 1px solid #d0d5dd; border-radius: 11px; background: white; min-height: 44px; padding: 0 13px; color: var(--text); outline: none; transition: border-color .16s, box-shadow .16s; }
input:focus, select:focus { border-color: #7aa2f7; box-shadow: 0 0 0 4px rgba(37,99,235,.1); }
input[type="color"] { padding: 5px; }
.btn { border: 0; border-radius: 11px; min-height: 42px; padding: 0 16px; font-weight: 750; display: inline-flex; justify-content: center; align-items: center; gap: 8px; }
.btn:disabled { opacity: .62; cursor: wait; }
.btn-primary { background: var(--primary); color: white; }
.btn-ghost { background: var(--surface-2); color: #344054; border: 1px solid var(--line); }
.btn-small { min-height: 34px; padding: 0 12px; font-size: 12px; }
.btn-block { width: 100%; }
.link-button { border: 0; background: transparent; padding: 0; color: var(--accent); font-weight: 700; }
.icon-button { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: white; color: #344054; }

.onboarding-card { width: min(100%, 760px); padding: clamp(28px, 5vw, 54px); background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.onboarding-card h1 { font-size: 38px; margin: 12px 0; letter-spacing: -.04em; }
.onboarding-card > p { color: var(--muted); line-height: 1.6; margin-bottom: 28px; }
.step-badge { display: inline-flex; margin-top: 28px; background: #eff6ff; color: #1d4ed8; border-radius: 999px; padding: 7px 10px; font-size: 11px; font-weight: 800; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; padding-top: 4px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) minmax(0,1fr); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: #0d1422; color: white; padding: 20px 14px; display: flex; flex-direction: column; z-index: 30; }
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 5px 9px 22px; }
.sidebar-brand > div:last-child { display: grid; }
.sidebar-brand strong { font-size: 16px; }
.sidebar-brand span { color: #78859a; font-size: 11px; }
.nav-list { display: grid; gap: 5px; }
.nav-list a { display: flex; align-items: center; gap: 11px; padding: 11px 12px; border-radius: 10px; color: #aab4c5; font-size: 14px; font-weight: 650; }
.nav-list a span { width: 20px; color: #6f7e94; }
.nav-list a:hover, .nav-list a.active { background: #172135; color: white; }
.nav-list a.active span { color: #8ab4ff; }
.sidebar-note { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid #233049; border-radius: 12px; background: #111c2d; }
.sidebar-note div { display: grid; }
.sidebar-note strong { font-size: 12px; }
.sidebar-note small { color: #7d8ca4; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 4px rgba(52,211,153,.12); }
.main-shell { grid-column: 2; min-width: 0; }
.topbar { height: 72px; background: rgba(255,255,255,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 14px; padding: 0 28px; position: sticky; top: 0; z-index: 20; }
.topbar-spacer { flex: 1; }
.org-switcher { display: flex; align-items: center; gap: 10px; }
.org-switcher span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.org-switcher select { min-width: 210px; min-height: 38px; font-weight: 700; }
.user-menu { border: 0; background: transparent; display: flex; align-items: center; gap: 10px; padding: 5px 6px; border-radius: 11px; text-align: left; }
.user-menu:hover { background: var(--surface-2); }
.user-menu > div:nth-child(2) { display: grid; min-width: 120px; }
.user-menu strong { font-size: 12px; }
.user-menu span { color: var(--muted); font-size: 11px; }
.avatar { width: 34px; height: 34px; border-radius: 10px; background: #eef2ff; color: #3730a3; display: grid; place-items: center; font-size: 11px; font-weight: 850; }
.user-popover { display: none; position: absolute; right: 28px; top: 62px; width: 240px; background: white; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 10px; }
.user-popover.open { display: grid; gap: 8px; }
.user-popover span { font-size: 12px; color: var(--muted); padding: 7px; overflow: hidden; text-overflow: ellipsis; }
.user-popover button { border: 0; background: #f8fafc; border-radius: 8px; padding: 9px; text-align: left; font-weight: 700; }
.page { padding: 28px; max-width: 1600px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 24px; }
.page-head h1 { margin: 5px 0 4px; font-size: clamp(28px, 3vw, 38px); letter-spacing: -.04em; }
.page-head p { margin: 0; color: var(--muted); }
.status-pill { display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; padding: 6px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.status-active { background: #ecfdf3; color: #067647; }
.status-muted { background: #f2f4f7; color: #667085; }
.metric-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 16px; }
.metric-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: grid; gap: 7px; box-shadow: 0 1px 2px rgba(15,23,42,.02); }
.metric-card span { font-size: 12px; color: var(--muted); font-weight: 700; }
.metric-card strong { font-size: 31px; letter-spacing: -.04em; }
.metric-card small { color: #98a2b3; }
.dashboard-grid { margin-top: 16px; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: 0 1px 2px rgba(15,23,42,.02); }
.panel-span-2 { grid-column: span 2; }
.panel-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 18px; }
.panel-head h2, .panel-head h3 { margin: 0 0 5px; letter-spacing: -.02em; }
.panel-head p { margin: 0; color: var(--muted); font-size: 13px; }
.activity-list, .audit-list { display: grid; }
.activity-row, .audit-row { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-top: 1px solid #eef0f3; }
.activity-row:first-child, .audit-row:first-child { border-top: 0; }
.activity-icon { width: 32px; height: 32px; border-radius: 10px; background: #eff6ff; color: #2563eb; display: grid; place-items: center; }
.activity-row > div:last-child, .audit-row > div { display: grid; gap: 2px; }
.activity-row strong, .audit-row strong { font-size: 12px; }
.activity-row span, .audit-row span, .audit-row time { color: var(--muted); font-size: 11px; }
.audit-row time { margin-left: auto; }
.check-list { display: grid; gap: 12px; }
.check-list span { display: flex; align-items: center; gap: 9px; color: #344054; font-size: 13px; }
.check-list b { width: 23px; height: 23px; border-radius: 50%; display: grid; place-items: center; background: #ecfdf3; color: #067647; font-size: 11px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 11px 13px; color: var(--muted); font-weight: 750; font-size: 12px; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--text); border-color: var(--text); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; padding: 10px 10px; border-bottom: 1px solid var(--line); }
td { padding: 13px 10px; border-bottom: 1px solid #eef0f3; font-size: 12px; vertical-align: middle; }
.person-cell { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.person-cell > div:last-child { display: grid; gap: 1px; }
.person-cell span { color: var(--muted); font-size: 10px; }
.table-select { min-height: 34px; min-width: 145px; font-size: 12px; }
.text-right { text-align: right; }
.inline-card { border: 1px solid #dbe4f0; background: #fbfdff; border-radius: 15px; padding: 18px; margin-top: 18px; }
.role-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; }
.role-card { border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; justify-content: space-between; gap: 14px; background: #fff; }
.role-card h3 { margin: 5px 0; font-size: 15px; }
.role-card p { margin: 0; font-size: 11px; color: var(--muted); line-height: 1.5; }
.count-badge { align-self: flex-start; background: #f2f4f7; color: #475467; border-radius: 999px; padding: 5px 8px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.permission-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; max-height: 310px; overflow: auto; padding: 3px; }
.permission-item { display: flex; grid-template-columns: auto 1fr; align-items: center; gap: 9px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: white; }
.permission-item input { width: 16px; min-height: 16px; }
.permission-item span { display: grid; }
.permission-item strong { font-size: 11px; }
.permission-item small { color: var(--muted); font-size: 10px; font-weight: 500; }
.empty-state, .page-loading { padding: 30px 10px; color: var(--muted); text-align: center; }
.error-panel { border-color: #fecaca; background: #fffafa; }
.mobile-only { display: none; }
.sidebar-backdrop { display: none; }

.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 8px; }
.toast { min-width: 250px; max-width: 420px; padding: 12px 14px; border-radius: 11px; color: white; box-shadow: var(--shadow); transform: translateY(12px); opacity: 0; transition: .18s ease; font-size: 12px; font-weight: 700; background: #344054; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast-success { background: #067647; }
.toast-error { background: #b42318; }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .panel-span-2 { grid-column: auto; }
  .role-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 820px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-panel { min-height: 34vh; padding: 30px; }
  .auth-copy h1 { font-size: 42px; }
  .auth-card-wrap { padding: 32px 20px; }
  .app-shell { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 20px 0 50px rgba(0,0,0,.18); }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.38); z-index: 25; }
  .sidebar-open .sidebar-backdrop { display: block; }
  .main-shell { min-width: 0; }
  .mobile-only { display: grid; place-items: center; }
  .topbar { padding: 0 14px; }
  .org-switcher span { display: none; }
  .org-switcher select { min-width: 0; width: min(42vw, 220px); }
  .user-menu > div:nth-child(2), .user-menu > b { display: none; }
  .user-popover { right: 14px; }
  .page { padding: 18px 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .role-grid, .permission-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .auth-panel { min-height: 260px; }
  .auth-copy p { display: none; }
  .auth-copy h1 { font-size: 34px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { padding: 15px; }
  .metric-card strong { font-size: 24px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .panel { padding: 15px; }
  .onboarding-card { padding: 24px 18px; }
  .onboarding-card h1 { font-size: 30px; }
}
