/* ================================================
   Dock — Design System
   Inter font, Lucide icons, clean SaaS look
   ================================================ */

/* Impersonation Banner */
#impersonation-banner {
  height: 44px; background: linear-gradient(90deg, #7C3AED, #6D28D9);
  color: #FFF; display: flex; align-items: center; gap: 10px;
  padding: 0 20px; font-size: 13px; font-weight: 500;
  box-shadow: 0 2px 8px rgba(109,40,217,.4); flex-shrink: 0;
}
body.has-impersonation .app-layout {
  height: calc(100vh - 44px); height: calc(100dvh - 44px);
}

:root {
  --bg: #FFF;
  --surface: #EEF2F7;
  --surface-2: #E2E8F0;
  --surface-3: #CBD5E1;
  --border: #D1D9E3;
  --border-strong: #B0BCCB;
  --text: #0F172A;
  --muted: #4A5568;
  --subtle: #7A8CA0;
  --primary: #1E40AF;
  --primary-2: #2563EB;
  --primary-light: #EFF6FF;
  --grad: linear-gradient(135deg, #1E40AF, #2563EB);
  --danger: #EF4444;
  --success: #10B981;
  --warning: #F59E0B;
  --sh-xs: 0 1px 2px rgba(15,23,42,.04);
  --sh-sm: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --sh-md: 0 4px 12px rgba(15,23,42,.06), 0 2px 4px rgba(15,23,42,.04);
  --sh-lg: 0 10px 30px rgba(15,23,42,.08), 0 4px 10px rgba(15,23,42,.04);
  --sh-xl: 0 24px 60px rgba(15,23,42,.14), 0 8px 20px rgba(15,23,42,.06);
  --r-card: 12px;
  --r-btn: 8px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px; line-height: 1.5; color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; }
a { color: inherit; text-decoration: none; }
svg { display: block; }

/* Icons (Lucide) */
.icon, .icon-sm, .icon-xs, .icon-lg {
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0;
}
.icon { width: 22px; height: 22px; }
.icon-sm { width: 16px; height: 16px; }
.icon-xs { width: 14px; height: 14px; }
.icon-lg { width: 28px; height: 28px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 36px; padding: 0 14px; border-radius: var(--r-btn);
  font-size: 13px; font-weight: 500; color: var(--text);
  background: #FFF; border: 1px solid var(--border);
  transition: all .15s; white-space: nowrap; cursor: pointer;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-p {
  background: var(--grad); color: #FFF; border: none;
  box-shadow: 0 2px 6px rgba(30,64,175,.2);
}
.btn-p:hover { box-shadow: 0 4px 14px rgba(30,64,175,.32); transform: translateY(-1px); }
.btn-p:disabled { opacity: .6; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-block { width: 100%; min-height: 44px; font-size: 15px; }
.btn-danger { background: #FEF2F2; color: #991B1B; border-color: #FECACA; }
.btn-danger:hover { background: #FEE2E2; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 12px; }

/* ── Inputs ── */
.fi {
  width: 100%; height: 44px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--r-btn);
  font-size: 14px; color: var(--text); background: #FFF; transition: all .15s;
}
.fi:focus { outline: none; border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.fi::placeholder { color: var(--subtle); }
.fl { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.ff { margin-bottom: 16px; }
.fi-error { border-color: var(--danger); }
.fi-error:focus { box-shadow: 0 0 0 3px rgba(239,68,68,.12); }
.error-text { font-size: 12px; color: var(--danger); margin-top: 4px; }

/* ── Pills/Badges ── */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 500; padding: 3px 9px; border-radius: 999px;
}
.p-new { background: #DBEAFE; color: #1E40AF; }
.p-open { background: #FEF3C7; color: #92400E; }
.p-ans { background: #D1FAE5; color: #065F46; }
.p-arch { background: #F1F5F9; color: #64748B; }
.p-active { background: #D1FAE5; color: #065F46; }
.p-danger { background: #FEE2E2; color: #991B1B; }

/* ── Panels/Cards ── */
.panel { background: #FFF; border: 1px solid var(--border); border-radius: var(--r-card); overflow: hidden; }
.p-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.p-title { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.p-body { padding: 20px; }

/* ── KPI Cards ── */
.kgrid { display: grid; gap: 14px; }
.kgrid.c4 { grid-template-columns: repeat(4, 1fr); }
.kgrid.c3 { grid-template-columns: repeat(3, 1fr); }
.kpi {
  background: #FFF; border: 1px solid var(--border); border-radius: var(--r-card);
  padding: 18px; position: relative; overflow: hidden; transition: all .18s;
}
.kpi:hover { transform: translateY(-1px); box-shadow: var(--sh-md); border-color: var(--border-strong); }
.kpi::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 48px; background: var(--tint); z-index: 0; }
.kpi > * { position: relative; z-index: 1; }
.kpi-val { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.kpi-lbl { font-size: 12px; font-weight: 500; color: var(--muted); margin-top: 3px; }
.k-blue { --tint: #EFF6FF; --kcol: var(--primary); }
.k-amber { --tint: #FEF3C7; --kcol: #B45309; }
.k-green { --tint: #ECFDF5; --kcol: #047857; }
.k-violet { --tint: #F5F3FF; --kcol: #6D28D9; }

/* ── Tables ── */
.dt { width: 100%; border-collapse: collapse; }
.dt thead th {
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--subtle); padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.dt tbody td {
  padding: 0 20px; height: 52px; border-bottom: 1px solid var(--border);
  vertical-align: middle; font-size: 13px;
}
.dt tbody tr { transition: background .1s; cursor: pointer; }
.dt tbody tr:hover { background: var(--surface); }

/* ── Avatars ── */
.av { border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; color: #FFF; flex-shrink: 0; }
.av-sm { width: 28px; height: 28px; font-size: 11px; }
.av-md { width: 36px; height: 36px; font-size: 13px; }
.av-lg { width: 44px; height: 44px; font-size: 15px; }
.av-blue { background: linear-gradient(135deg, #3B82F6, #1E40AF); }
.av-green { background: linear-gradient(135deg, #10B981, #047857); }
.av-amber { background: linear-gradient(135deg, #F59E0B, #B45309); }
.av-violet { background: linear-gradient(135deg, #8B5CF6, #6D28D9); }

/* ── App Shell Layout ── */
.app-layout { display: flex; height: 100vh; background: var(--surface); }

/* Rail (app switcher) */
.rail {
  width: 60px; background: #FFF; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 0; flex-shrink: 0; gap: 4px;
}
.rail-brand {
  width: 36px; height: 36px; border-radius: 10px; background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  color: #FFF; box-shadow: 0 4px 10px rgba(30,64,175,.3); margin-bottom: 8px;
}
.rail-div { width: 24px; height: 1px; background: var(--border); margin: 4px 0; }
.rail-btn {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); transition: all .15s; position: relative; cursor: pointer;
}
.rail-btn:hover { background: var(--surface-2); color: var(--text); }
.rail-btn.active { background: var(--primary-light); color: var(--primary); }
.rail-btn.active::before {
  content: ''; position: absolute; left: -14px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 22px; background: var(--primary); border-radius: 0 2px 2px 0;
}
.rail-badge {
  position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: #EF4444; color: #FFF; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; border: 2px solid #FFF;
}
.rail-tip {
  position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  background: #0F172A; color: #FFF; padding: 5px 10px; border-radius: 6px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 100;
  border: 1px solid rgba(255,255,255,.08);
}
.rail-btn:hover .rail-tip { opacity: 1; }
.rail-spacer { flex: 1; }

/* Sidebar */
.sb {
  width: 240px; background: #FFF; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sb-head { padding: 16px 18px 14px; border-bottom: 1px solid var(--border); }
.sb-app { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sb-app-ic { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.sb-app-name { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.sb-nav { flex: 1; padding: 14px 10px; overflow-y: auto; }
.nav-group + .nav-group { margin-top: 16px; }
.nav-label {
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--subtle); padding: 4px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 1px;
  border-radius: 7px; font-size: 13px; font-weight: 500; color: var(--muted);
  cursor: pointer; transition: all .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-badge {
  margin-left: auto; font-size: 10px; font-weight: 600; padding: 1px 6px;
  border-radius: 999px; background: var(--primary); color: #FFF;
}
.sb-foot { padding: 10px; border-top: 1px solid var(--border); }
.sb-user {
  padding: 8px 10px; display: flex; align-items: center; gap: 10px;
  border-radius: 7px; cursor: pointer; transition: background .12s;
}
.sb-user:hover { background: var(--surface-2); }
.sb-user-name { font-size: 12px; font-weight: 600; }
.sb-user-role { font-size: 11px; color: var(--muted); }

/* Main content */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.topbar {
  height: 56px; background: #FFF; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px; flex-shrink: 0;
}
.content { flex: 1; overflow-y: auto; min-height: 0; }
.wrap { padding: 28px 32px 40px; max-width: 1200px; margin: 0 auto; width: 100%; }
.ph { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; gap: 16px; }
.pt { font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.psub { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ── Login Page ── */
.login-bg {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 10% 10%, rgba(37,99,235,.12), transparent 55%),
              radial-gradient(ellipse at 90% 90%, rgba(30,64,175,.1), transparent 50%),
              linear-gradient(180deg, #E8EEF7, #DDE6F2);
  padding: 20px;
}
.login-card {
  background: #FFF; border-radius: 16px; box-shadow: var(--sh-xl);
  padding: 40px; width: 100%; max-width: 420px; border: 1px solid rgba(15,23,42,.08);
}
.login-logo {
  width: 48px; height: 48px; border-radius: 12px; background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  color: #FFF; margin: 0 auto 24px; box-shadow: 0 4px 12px rgba(30,64,175,.3);
}
.login-title { font-size: 22px; font-weight: 600; text-align: center; margin-bottom: 4px; letter-spacing: -.02em; }
.login-sub { font-size: 13px; color: var(--muted); text-align: center; margin-bottom: 28px; }
.login-footer { margin-top: 24px; text-align: center; font-size: 12px; color: var(--subtle); }

/* 2FA QR */
.qr-wrap { text-align: center; margin: 20px 0; }
.qr-wrap img { border-radius: 8px; border: 1px solid var(--border); }
.secret-code {
  font-family: 'JetBrains Mono', monospace; font-size: 14px; font-weight: 500;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; text-align: center; letter-spacing: .1em; margin: 12px 0;
  word-break: break-all;
}

/* Recovery codes */
.recovery-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
  margin: 16px 0; font-family: 'JetBrains Mono', monospace; font-size: 13px;
}
.recovery-code {
  padding: 8px 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; text-align: center; font-weight: 500;
}

/* ── Toast Notifications ── */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 10000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #FFF; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; box-shadow: var(--sh-lg); display: flex; align-items: center; gap: 10px;
  font-size: 13px; font-weight: 500; min-width: 280px; max-width: 420px;
  animation: toast-in .3s ease;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--primary-2); }
@keyframes toast-in { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }

/* ── Loading spinner ── */
.spinner {
  width: 20px; height: 20px; border: 2px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .6s linear infinite;
}
.spinner-white { border-color: rgba(255,255,255,.3); border-top-color: #FFF; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty states ── */
.empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty-icon { width: 48px; height: 48px; margin: 0 auto 16px; color: var(--subtle); }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-text { font-size: 13px; }

/* ── Toggle ── */
.tog {
  width: 32px; height: 18px; border-radius: 999px; background: var(--surface-3);
  position: relative; cursor: pointer; transition: background .2s; flex-shrink: 0;
}
.tog::after {
  content: ''; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: #FFF; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: left .2s;
}
.tog.on { background: var(--primary); }
.tog.on::after { left: 16px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #E2E8F0; border-radius: 999px; border: 2px solid #FFF; }
::-webkit-scrollbar-thumb:hover { background: #CBD5E1; }

/* ── Utility ── */
.hidden { display: none !important; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-14 { gap: 14px; }
.mt-16 { margin-top: 16px; }
.text-center { text-align: center; }

/* ── Responsive (base layout) ── */
@media (max-width:768px) {
  .kgrid.c4, .kgrid.c3 { grid-template-columns: repeat(2, 1fr); }
  .kpi-val { font-size: 22px; }
  .kpi { padding: 14px; }
  .dt thead th, .dt tbody td { padding: 8px 12px; font-size: 12px; }
  .dt tbody td { height: 44px; }
  .btn { padding: 7px 14px; font-size: 12px; }
  .btn-sm { padding: 5px 10px; font-size: 11px; }
  .fi, .ftx { padding: 8px 12px; font-size: 13px; }
}
@media (max-width:420px) {
  .kgrid.c4, .kgrid.c3 { grid-template-columns: 1fr; }
}
