/* SafeOp Admin & Dealer Portal theme.
   Its own look, deliberately different from the customer app (§5.1 asks for
   "a slightly different visual treatment ... but the same SafeOp
   branding"): SafeOp's logo and green, on a light, minimal layout with ink
   text and Plus Jakarta Sans. */

:root {
  --ink: #0f1b2d;          /* text, primary buttons */
  --ink-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e7ebf0;
  --line-strong: #d7dde5;
  --canvas: #f6f7f9;       /* page background */
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --brand: #3cb183;        /* SafeOp logo green */
  --brand-ink: #1f7a59;
  --brand-soft: #e8f6f0;
  --focus: rgba(60, 177, 131, 0.28);
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 27, 45, 0.04);
  --shadow: 0 1px 2px rgba(15, 27, 45, 0.04), 0 4px 16px -6px rgba(15, 27, 45, 0.08);
  --sidebar-width: 248px;

  --bs-body-font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --bs-body-font-size: 0.9375rem;
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--canvas);
  --bs-border-color: var(--line);
  --bs-link-color: var(--ink);
  --bs-link-color-rgb: 15, 27, 45;
  --bs-link-hover-color: var(--brand-ink);
  --bs-link-hover-color-rgb: 31, 122, 89;
  --bs-secondary-color: var(--muted);
  --bs-emphasis-color: var(--ink);
}

body { font-weight: 450; min-height: 100vh; -webkit-font-smoothing: antialiased; letter-spacing: -0.003em; }
h1, h2, h3, h4, h5, h6 { color: var(--ink); font-weight: 700; letter-spacing: -0.02em; }
h1 { font-size: 1.6rem; }
.text-secondary { color: var(--muted) !important; }
a { text-underline-offset: 3px; }
.code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.88em; letter-spacing: 0; }

/* ---------- Buttons ---------- */
.btn { border-radius: 8px; font-weight: 600; font-size: 0.875rem; padding: 0.5rem 0.95rem; letter-spacing: -0.005em; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-primary {
  --bs-btn-bg: var(--ink); --bs-btn-border-color: var(--ink);
  --bs-btn-hover-bg: #1d2b40; --bs-btn-hover-border-color: #1d2b40;
  --bs-btn-active-bg: #000; --bs-btn-active-border-color: #000;
  --bs-btn-disabled-bg: var(--faint); --bs-btn-disabled-border-color: var(--faint);
  --bs-btn-focus-shadow-rgb: 60, 177, 131;
  box-shadow: 0 1px 2px rgba(15, 27, 45, 0.18);
}
.btn-outline-secondary {
  --bs-btn-color: var(--ink); --bs-btn-bg: var(--surface); --bs-btn-border-color: var(--line-strong);
  --bs-btn-hover-color: var(--ink); --bs-btn-hover-bg: var(--surface-2); --bs-btn-hover-border-color: var(--faint);
  --bs-btn-active-color: var(--ink); --bs-btn-active-bg: var(--canvas); --bs-btn-active-border-color: var(--faint);
}
.btn-outline-danger { --bs-btn-color: #b42318; --bs-btn-border-color: #f1c4bf; --bs-btn-hover-bg: #fef3f2; --bs-btn-hover-color: #b42318; --bs-btn-hover-border-color: #e5a29a; --bs-btn-bg: var(--surface); }
.btn-danger { --bs-btn-bg: #c0392b; --bs-btn-border-color: #c0392b; --bs-btn-hover-bg: #a93226; --bs-btn-hover-border-color: #a93226; }
.btn-link { color: var(--muted); }
.btn i { margin-right: 0.35rem; }
.btn-group > .btn { border-radius: 8px; }
.btn-group > .btn:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.btn-group > .btn:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }

/* ---------- Layout ---------- */
.portal-sidebar {
  width: var(--sidebar-width);
  background: var(--surface) !important;
  border-right: 1px solid var(--line);
  padding: 1.25rem 0.85rem 1rem;
}
@media (min-width: 992px) {
  .portal-sidebar { position: fixed; top: 0; bottom: 0; left: 0; overflow-y: auto; }
  .dev-banner ~ .d-flex .portal-sidebar { top: 28px; }
  .portal-content { margin-left: var(--sidebar-width); }
}
.portal-content { min-width: 0; min-height: 100vh; }
.portal-sidebar__brand { display: flex; align-items: center; justify-content: space-between; padding: 0.15rem 0.6rem 1.35rem; }
.portal-sidebar__brand img { height: 36px; width: auto; }
.portal-sidebar__area {
  display: flex; align-items: center; gap: 0.5rem;
  margin: 0 0.25rem 1rem; padding: 0.55rem 0.7rem;
  background: var(--canvas); border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 0.8rem; font-weight: 600; color: var(--ink-2);
}
.portal-sidebar__area .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); flex: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.portal-sidebar__area span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.portal-nav .nav-link {
  position: relative; display: flex; align-items: center; gap: 0.7rem;
  color: var(--ink-2); font-weight: 550; font-size: 0.875rem;
  border-radius: 8px; padding: 0.5rem 0.65rem; margin-bottom: 2px;
}
.portal-nav .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; color: var(--faint); transition: color .15s; }
.portal-nav .nav-link:hover { background: var(--canvas); color: var(--ink); }
.portal-nav .nav-link:hover i { color: var(--ink-2); }
.portal-nav .nav-link.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 650; }
.portal-nav .nav-link.active i { color: var(--brand); }
.portal-nav .nav-section {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--faint); padding: 1.1rem 0.65rem 0.4rem;
}
.portal-sidebar__foot { margin-top: auto; padding: 1rem 0.6rem 0; font-size: 0.75rem; color: var(--faint); }

.portal-topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(246, 247, 249, 0.85); backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--line); min-height: 60px;
}
.portal-topbar__title { font-weight: 600; font-size: 0.875rem; color: var(--muted); }
.portal-topbar__title strong { color: var(--ink); font-weight: 650; }
.portal-user { display: flex; align-items: center; gap: 0.55rem; padding: 0.25rem 0.6rem 0.25rem 0.25rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.portal-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.75rem;
}

.portal-main { padding: 1.75rem 1.25rem 3rem; max-width: 1240px; }
@media (min-width: 992px) { .portal-main { padding: 2.25rem 2.75rem 3.5rem; } }

.portal-logo { height: 40px; width: auto; align-self: flex-start; }

/* ---------- Page header ---------- */
.page-header { margin-bottom: 1.75rem; }
.page-header h1 { margin-bottom: 0.3rem; }
.page-header p { font-size: 0.9rem; }
.page-back { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--muted); text-decoration: none; font-size: 0.8rem; font-weight: 600; margin-bottom: 0.6rem; }
.page-back:hover { color: var(--ink); }
.page-eyebrow { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--brand-ink); margin-bottom: 0.35rem; }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); background: var(--surface); }
.card > .table-responsive:first-child, .card > .table-responsive:first-child .table { border-top-left-radius: var(--radius-lg); border-top-right-radius: var(--radius-lg); }
.card-footer { background: var(--surface-2) !important; border-top: 1px solid var(--line); border-bottom-left-radius: var(--radius-lg) !important; border-bottom-right-radius: var(--radius-lg) !important; }
.card-section-title { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.stat-card { padding: 1.1rem 1.25rem; }
.stat-card .label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.stat-card .value { font-size: 1.75rem; font-weight: 750; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.link-card { display: flex; gap: 0.9rem; align-items: flex-start; padding: 1.15rem 1.25rem; text-decoration: none; color: var(--ink); transition: border-color .15s, transform .15s; }
.link-card:hover { border-color: var(--line-strong); transform: translateY(-1px); color: var(--ink); }
.link-card .icon { width: 38px; height: 38px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-ink); display: inline-flex; align-items: center; justify-content: center; font-size: 1.15rem; flex: none; }
.link-card .title { font-weight: 700; }
.link-card .text { font-size: 0.83rem; color: var(--muted); }

/* ---------- Tables ---------- */
.table { --bs-table-bg: transparent; margin-bottom: 0; font-size: 0.875rem; }
.table > :not(caption) > * > * { padding: 0.8rem 1rem; border-bottom-color: var(--line); }
.table > thead th {
  background: var(--surface-2); color: var(--muted); font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.07em; white-space: nowrap; padding-top: 0.65rem; padding-bottom: 0.65rem;
}
.table > tbody > tr:last-child > * { border-bottom: 0; }
.table > tbody > tr { transition: background .12s; }
.table > tbody > tr:hover { background: var(--surface-2); }
.table td { vertical-align: middle; }
.table a.row-link { color: var(--ink); font-weight: 650; text-decoration: none; }
.table a.row-link:hover { color: var(--brand-ink); }
.cell-sub { font-size: 0.78rem; color: var(--muted); }

/* ---------- Forms ---------- */
.form-label { font-weight: 600; font-size: 0.83rem; color: var(--ink-2); margin-bottom: 0.35rem; }
.form-control, .form-select {
  border-radius: 8px; border-color: var(--line-strong); padding: 0.55rem 0.8rem; font-size: 0.9rem;
  box-shadow: var(--shadow-sm); background-color: var(--surface);
}
.form-control::placeholder { color: var(--faint); }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: var(--brand); box-shadow: 0 0 0 0.22rem var(--focus); }
.form-text { font-size: 0.78rem; color: var(--muted); }
.form-check-input { border: 1.5px solid var(--faint); width: 1.15em; height: 1.15em; }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.invalid-feedback { font-size: 0.78rem; }
.form-section { padding-top: 1.25rem; margin-top: 1.25rem; border-top: 1px dashed var(--line-strong); }
.form-section:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }

/* ---------- Detail lists ---------- */
.detail-row { padding: 0.65rem 0; }
.detail-row + .detail-row { border-top: 1px solid var(--line); }
.detail-row dt { font-size: 0.83rem; }
.detail-row dd { font-size: 0.875rem; font-weight: 500; }

/* ---------- Alerts ---------- */
.alert { border-radius: var(--radius); border: 1px solid; font-size: 0.875rem; padding: 0.75rem 1rem; }
.alert-success { background: var(--brand-soft); border-color: #c6e9da; color: #155e43; }
.alert-danger { background: #fef3f2; border-color: #f6cfca; color: #9b2c22; }
.alert-warning { background: #fffaeb; border-color: #f5dfa2; color: #7a5300; }
.alert-info { background: #f0f6ff; border-color: #cfe0fb; color: #1e4b8f; }

/* ---------- Status badges: a dot + label, one colour per kind of state ---------- */
.status-badge {
  display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.2rem 0.6rem 0.2rem 0.5rem;
  border-radius: 999px; font-size: 0.75rem; font-weight: 650; white-space: nowrap;
  background: #f1f4f7; color: var(--ink-2); border: 1px solid transparent;
}
.status-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.status-invited, .status-pending { background: #fff7e6; color: #946200; }
.status-account_created, .status-agreement_signed, .status-training_outstanding { background: #eef4ff; color: #2952a3; }
.status-active, .status-accepted { background: var(--brand-soft); color: var(--brand-ink); }
.status-suspended, .status-expired, .status-revoked { background: #fef1f0; color: #b42318; }
/* Agreement status (§7.1) */
.status-signed { background: var(--brand-soft); color: var(--brand-ink); }
.status-not_signed { background: #f1f4f7; color: var(--ink-2); }
.status-out_of_date { background: #fff7e6; color: #946200; }

/* ---------- Filter chips (segmented) ---------- */
.filter-chips { display: inline-flex; flex-wrap: wrap; gap: 0.25rem; padding: 0.25rem; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-sm); }
.filter-chip { border-radius: 7px; padding: 0.35rem 0.7rem; font-size: 0.8rem; font-weight: 600; color: var(--muted); text-decoration: none; }
.filter-chip span { color: var(--faint); margin-left: 0.25rem; font-variant-numeric: tabular-nums; }
.filter-chip:hover { color: var(--ink); background: var(--canvas); }
.filter-chip.active { background: var(--ink); color: #fff; }
.filter-chip.active span { color: rgba(255, 255, 255, 0.6); }

/* ---------- Tabs (underline) ---------- */
.nav-tabs { border-bottom: 1px solid var(--line); gap: 1.25rem; }
.nav-tabs .nav-link { border: 0; border-bottom: 2px solid transparent; padding: 0.6rem 0.1rem; color: var(--muted); font-weight: 600; font-size: 0.875rem; background: none; margin-bottom: -1px; }
.nav-tabs .nav-link:hover { color: var(--ink); border-bottom-color: var(--line-strong); }
.nav-tabs .nav-link.active { color: var(--ink); border-bottom-color: var(--ink); background: none; }
.nav-tabs .nav-link .count { display: inline-block; min-width: 1.4rem; padding: 0 0.35rem; margin-left: 0.3rem; border-radius: 999px; background: #eef1f5; color: var(--ink-2); font-size: 0.72rem; text-align: center; }

/* ---------- Empty states ---------- */
.empty-state { padding: 3.25rem 1.5rem; text-align: center; }
.empty-state .icon { width: 48px; height: 48px; margin: 0 auto 0.9rem; border-radius: 14px; background: var(--brand-soft); color: var(--brand-ink); display: flex; align-items: center; justify-content: center; font-size: 1.35rem; }
.empty-state .title { font-weight: 700; font-size: 1rem; margin-bottom: 0.3rem; }
.empty-state p { max-width: 440px; margin-left: auto; margin-right: auto; font-size: 0.875rem; }

/* ---------- Public pages (invitation, waiting, suspended, errors) ---------- */
.public-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2.5rem 1rem;
  background: radial-gradient(1200px 500px at 50% -10%, var(--brand-soft), transparent 60%), var(--canvas); }
.public-card { width: 100%; max-width: 480px; padding: 2.25rem; }
.public-card h1 { font-size: 1.4rem; }

/* ---------- Onboarding (§5.1) ---------- */
.onboarding-top { background: var(--surface); border-bottom: 1px solid var(--line); }
.onboarding-top .meta { font-size: 0.8rem; color: var(--muted); }
.onboarding-steps { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.4rem; list-style: none; padding: 0; margin: 0; }
.onboarding-steps li { font-size: 0.72rem; font-weight: 600; color: var(--faint); }
.onboarding-steps li .bar { display: block; height: 4px; border-radius: 99px; background: var(--line); margin-bottom: 0.45rem; }
.onboarding-steps li.done { color: var(--muted); }
.onboarding-steps li.done .bar { background: var(--brand); }
.onboarding-steps li.current { color: var(--ink); }
.onboarding-steps li.current .bar { background: var(--ink); }
.onboarding-steps li .num { font-variant-numeric: tabular-nums; margin-right: 0.25rem; opacity: 0.7; }
@media (max-width: 575px) { .onboarding-steps li .label { display: none; } }
.tutorial-num {
  width: 32px; height: 32px; border-radius: 9px; background: var(--brand-soft); color: var(--brand-ink);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 750; font-size: 0.85rem;
}
.tutorial-card { box-shadow: var(--shadow-sm); }
/* Blocking pop-up (re-acceptance, §4.2): dims the whole portal behind it. */
.blocking-backdrop { position: fixed; inset: 0; background: rgba(15, 27, 45, 0.45); backdrop-filter: blur(2px); z-index: 1040; }
.blocking-dialog { position: relative; z-index: 1050; max-width: 880px; margin: 0 auto; box-shadow: 0 24px 60px -12px rgba(15, 27, 45, 0.35); }
.agreement-viewer { border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface-2); }
.agreement-viewer iframe { display: block; width: 100%; height: 62vh; min-height: 420px; border: 0; }

/* ---------- Local demo bar ---------- */
.dev-banner { background: #111827; color: #cbd5e1; font-size: 0.75rem; letter-spacing: 0.01em; }
.dev-banner a { color: #fff; }
