:root {
  --blue: #1565c0;
  --blue-dark: #0d47a1;
  --slate-950: #020617;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --bg: #f8fafc;
  --emerald: #047857;
  --amber: #b45309;
  --danger: #b91c1c;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--slate-900);
}
.hidden { display: none !important; }
.muted { color: var(--slate-600); font-size: 13px; margin: 0; }
.muted-small { color: var(--slate-500); font-size: 12px; }
.center { text-align: center; }
.text-right { text-align: right; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-dark { background: var(--slate-900); color: #fff; }
.btn-dark:hover { background: var(--slate-800); }
.btn-ghost { background: #fff; color: var(--slate-800); border-color: #cbd5e1; }
.btn-ghost:hover { background: var(--slate-100); }
.btn-amber { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.btn-amber:hover { background: #fde68a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #991b1b; }

/* Public Login Layout */
.portal-public-header {
  background: #fff;
  border-bottom: 1px solid var(--slate-200);
}
.portal-public-header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand-title { font-weight: 800; font-size: 16px; color: var(--slate-900); }
.auth-stage {
  min-height: calc(100vh - 54px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.auth-split-card {
  width: 100%;
  max-width: 880px;
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  overflow: hidden;
  display: grid;
  grid-template-columns: 5fr 7fr;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
}
.auth-aside {
  background: var(--slate-900);
  color: #e2e8f0;
  padding: 32px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 28px;
}
.auth-kicker { font-size: 12px; font-weight: 700; color: #93c5fd; margin-bottom: 8px; }
.auth-aside h1 { margin: 0 0 12px; font-size: 22px; line-height: 1.3; color: #fff; }
.auth-aside p { margin: 0; font-size: 13px; line-height: 1.6; color: #cbd5e1; }
.auth-aside-list { border-top: 1px solid var(--slate-800); padding-top: 16px; font-size: 12px; }
.auth-aside-list ul { list-style: none; padding: 8px 0 0; margin: 0; color: #94a3b8; display: flex; flex-direction: column; gap: 6px; }

.auth-form-pane { padding: 32px; display: flex; flex-direction: column; gap: 16px; }
.auth-form-stack { display: flex; flex-direction: column; gap: 16px; }
.auth-form-pane h2 { margin: 0 0 4px; font-size: 19px; }
.auth-footnote { margin: 4px 0 0; padding-top: 12px; border-top: 1px solid var(--slate-100); font-size: 11px; color: var(--slate-500); }
.auth-links-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; padding-top: 4px; }
.link-btn {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--blue);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }
.link-inline { color: var(--blue); font-size: 13px; font-weight: 600; text-decoration: none; }
.link-inline:hover { text-decoration: underline; }

.token-card { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 16px; }
.token-card h1 { margin: 0; font-size: 20px; }
.token-form { display: flex; flex-direction: column; gap: 14px; }
.token-links { padding-top: 8px; border-top: 1px solid var(--slate-100); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 700; color: var(--slate-700); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--slate-900);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--blue); border-color: var(--blue); }

.alert { padding: 12px 14px; border-radius: 8px; font-size: 12px; line-height: 1.5; }
.alert-warn { background: #fffbeb; border: 1px solid #fcd34d; color: #78350f; }
.alert-danger { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; font-weight: 600; }
.alert-success { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; font-weight: 600; }
.status-danger { color: var(--danger); }

/* Portal Menu Shell */
.portal-shell { display: flex; min-height: 100vh; }
.portal-sidebar {
  width: 260px;
  background: var(--slate-900);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--slate-800);
}
.portal-brand {
  padding: 16px 18px;
  border-bottom: 1px solid var(--slate-800);
  font-weight: 800;
  font-size: 16px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.mobile-only { display: none; }
.portal-nav { padding: 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.portal-nav-btn, .portal-nav-link {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: #cbd5e1;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.portal-nav-btn:hover, .portal-nav-link:hover { background: var(--slate-800); color: #fff; }
.portal-nav-btn.active { background: var(--blue); color: #fff; }
.nav-hint { font-size: 11px; opacity: 0.75; }
.nav-sep { border-top: 1px solid var(--slate-800); margin: 8px 0; }
.portal-sidebar-foot {
  padding: 16px;
  border-top: 1px solid var(--slate-800);
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 12px;
}
.foot-email, .foot-role { color: #94a3b8; font-size: 11px; margin-top: 2px; }

.portal-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.portal-topbar {
  background: #fff;
  border-bottom: 1px solid var(--slate-200);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.portal-content { max-width: 1120px; width: 100%; margin: 0 auto; padding: 24px; }
.tab-panel { display: flex; flex-direction: column; gap: 20px; }
.section-head h1, .between-wrap h1 { margin: 0 0 4px; font-size: 22px; }
.card-title { margin: 0 0 4px; font-size: 17px; }
.between-wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.two-col-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }

/* 2FA QR Code & Recovery Codes */
.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px;
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  background: #fff;
}
.qr-box img { width: 188px; height: 188px; image-rendering: pixelated; }
.secret-code {
  display: block;
  padding: 10px 12px;
  background: var(--slate-100);
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0.08em;
  word-break: break-all;
  color: var(--slate-900);
}
.recovery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.recovery-item {
  padding: 8px 10px;
  background: var(--slate-100);
  border: 1px solid var(--slate-200);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.05em;
}

/* Audit Filter & Pagination */
.filter-bar {
  display: grid;
  grid-template-columns: 2fr 1.3fr 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}
.filter-actions { display: flex; gap: 8px; }
.audit-details {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--slate-600);
  max-width: 320px;
  word-break: break-word;
}
.pagination-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modules-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; }
.module-card {
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
}
.module-card h2 { margin: 0 0 8px; font-size: 17px; }
.module-meta { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.status-text { font-size: 12px; font-weight: 700; }
.status-ok { color: var(--emerald); }
.status-plan { color: var(--amber); }
.module-foot { padding-top: 12px; border-top: 1px solid var(--slate-100); }

.card { background: #fff; border: 1px solid var(--slate-200); border-radius: 12px; padding: 24px; }
.table-card { background: #fff; border: 1px solid var(--slate-200); border-radius: 12px; overflow-x: auto; }
.portal-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.portal-table th {
  background: #f8fafc;
  color: var(--slate-600);
  font-size: 12px;
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--slate-200);
}
.portal-table td { padding: 12px 14px; border-bottom: 1px solid var(--slate-100); vertical-align: middle; }
.portal-table tr:last-child td { border-bottom: 0; }
.actions-cell { white-space: nowrap; display: flex; justify-content: flex-end; gap: 6px; }

/* Modal & Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--slate-200);
  max-width: 500px;
  width: 100%;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 50px rgba(2, 6, 23, 0.35);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding-top: 8px; border-top: 1px solid var(--slate-100); }
.check-grid { display: flex; flex-direction: column; gap: 8px; }
.check-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.check-item-left { display: flex; align-items: center; gap: 8px; font-weight: 600; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--slate-900);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  z-index: 60;
  box-shadow: 0 10px 25px rgba(2, 6, 23, 0.35);
}

@media (max-width: 860px) {
  .auth-split-card, .two-col-grid, .filter-bar { grid-template-columns: 1fr; }
  .portal-shell { flex-direction: column; }
  .portal-sidebar { width: 100%; border-right: 0; border-bottom: 1px solid var(--slate-800); }
  .portal-nav { flex-direction: row; overflow-x: auto; }
  .portal-nav-btn, .portal-nav-link { width: auto; white-space: nowrap; }
  .portal-sidebar-foot, .nav-sep { display: none; }
  .mobile-only { display: inline-flex; }
}
