/* Production bridge — maps the existing admin console's classes onto the
   approved Admin Portal design system. Loaded after admin.css and portal.css. */

:root {
  --font: var(--font-ui);
  --line: var(--rule);
  --line-strong: var(--rule-strong);
  --brand: var(--accent);
  --brand-strong: var(--accent-strong);
  --brand-soft: var(--accent-soft);
  --nav: var(--rail);
  --nav-2: var(--rail-2);
  --nav-ink: var(--rail-ink);
  --nav-muted: var(--rail-muted);
  --radius: 2px;
  --radius-sm: 1px;
  --shadow-sm: none;
  --shadow: 0 18px 44px rgba(10, 21, 31, 0.16);
  --shadow-lg: 0 28px 70px rgba(10, 21, 31, 0.28);
}

html[data-theme="dark"] {
  --line: var(--rule);
  --line-strong: var(--rule-strong);
  --brand: var(--accent);
  --brand-strong: var(--accent-strong);
  --brand-soft: var(--accent-soft);
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.42);
  --shadow-lg: 0 28px 70px rgba(0, 0, 0, 0.55);
}

body { font-size: 13px; background: var(--bg); }
button, input, select, textarea { font-family: var(--font-ui); }

/* ---------- shell ---------- */

.app { background: var(--bg); }
.rail-brand-icon { width: 27px; height: 27px; object-fit: contain; flex: none; }
.rail-brand .rail-collapse { margin-left: auto; flex: none; }
.rail-brand .rail-close { margin-left: auto; }
body.nav-collapsed .rail-brand .rail-collapse { margin-left: 0; }
.rail {
  box-shadow:
    18px 0 44px rgba(4, 10, 18, 0.22),
    4px 0 12px rgba(4, 10, 18, 0.14),
    inset -1px 0 0 rgba(255, 255, 255, 0.07);
}
html[data-theme="dark"] .rail {
  box-shadow:
    18px 0 46px rgba(0, 0, 0, 0.52),
    4px 0 14px rgba(0, 0, 0, 0.3),
    inset -1px 0 0 rgba(255, 255, 255, 0.07);
}

.nav-items { display: flex; flex-direction: column; gap: 1px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 29px;
  padding: 0 8px 0 10px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: #c6d3de;
  font-size: 12.5px;
  font-weight: 400;
  text-align: left;
  text-decoration: none;
}
.nav-link .icon { width: 15px; height: 15px; color: var(--rail-muted); }
.nav-link > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-link > em {
  margin-left: auto;
  color: var(--rail-muted);
  font: 400 10.5px/1 var(--font-mono);
  font-style: normal;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.055); color: #fff; text-decoration: none; }
.nav-link:hover .icon { color: #fff; }
.nav-link.active,
.nav-link[aria-current="page"] {
  background: rgba(255, 255, 255, 0.075);
  color: #fff;
  box-shadow: inset 2px 0 0 var(--accent-on-rail);
}
.nav-link.active .icon,
.nav-link[aria-current="page"] .icon { color: var(--accent-on-rail); }
.nav-link.active > em,
.nav-link[aria-current="page"] > em { color: #c7d6e4; }
.nav-link .nav-lock { margin-left: auto; color: var(--warn); }
.nav-link .nav-lock .icon { width: 11px; height: 11px; color: var(--warn); }
.nav-link[hidden] { display: none !important; }
.nav-item.rail-settings { width: 100%; margin: 0 0 5px; color: var(--rail-muted); font-size: 12px; }
.nav-item.rail-settings .icon { width: 15px; height: 15px; color: var(--rail-muted); }
.nav-item.rail-settings:hover { color: #fff; }
.nav-item.rail-settings:hover .icon { color: #fff; }
.rail-user .avatar { width: 26px; height: 26px; font-size: 9.5px; }

.nav-group[hidden] { display: none !important; }
.nav-group { margin-bottom: 6px; }
.nav-group-btn { height: 26px; }
.nav-flyout .nav-item { min-height: 31px; }
.nav-flyout .nav-items { padding: 0; }
.nav-flyout-empty { padding: 18px 12px; color: var(--rail-muted); font-size: 11px; text-align: center; }

body.nav-collapsed .app { grid-template-columns: 96px minmax(0, 1fr); }
@media (max-width: 980px) {
  .rail { width: 258px; }
  .rail.open, #sidebar.open { transform: translateX(0); }
  body.nav-collapsed .app { grid-template-columns: minmax(0, 1fr); }
  body.nav-collapsed .rail { width: 258px; }
  body.nav-collapsed .rail-brand-copy { display: flex; }
  body.nav-collapsed .nav-items { display: flex !important; }
  body.nav-collapsed .nav-group-label { display: block; flex: 1; width: auto; white-space: nowrap; font-size: 10.5px; }
  body.nav-collapsed .nav-group-btn { flex-direction: row; align-items: center; min-height: 25px; height: 25px; padding: 0 8px; font-size: 10.5px; }
  body.nav-collapsed .nav-group-icon { width: 14px; height: 14px; }
  body.nav-collapsed .rail-settings { flex-direction: row; min-height: 29px; padding: 0 8px; margin-bottom: 0; font-size: 12px; }
  body.nav-collapsed .rail-settings span { display: inline; width: auto; text-align: left; }
  body.nav-collapsed .rail-user { justify-content: flex-start; padding: 4px 4px 8px; }
  body.nav-collapsed .rail-user-copy, body.nav-collapsed .rail-user .icon-btn { display: flex; }
  .nav-scrim.open { display: block; }
}

/* ---------- topbar and page frame ---------- */

.topbar { padding: 0 20px; position: sticky; top: 0; }
.scope-org { font-size: 12.5px; }
.scope-path .status-dot { flex: none; }
.plan-badge {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--ink-2);
  background: var(--surface);
  font: 500 10px/1 var(--font-mono);
  text-transform: capitalize;
  white-space: nowrap;
}
.plan-badge.is-community { color: var(--muted); }
.language-select.select { width: 180px; height: 30px; font-size: 11px; padding: 0 24px 0 7px; background-repeat: no-repeat; background-position: right 9px center; background-size: auto; }
html[data-theme="dark"] .language-select.select { background-color: var(--surface); color: var(--ink); }
html[data-theme="dark"] .language-select.select option { background: var(--surface); color: var(--ink); }
.top-actions .icon-btn { width: 30px; height: 30px; }
.top-actions .icon-button { width: 30px; height: 30px; border: 1px solid transparent; border-radius: 2px; background: transparent; color: var(--ink-2); display: inline-grid; place-items: center; }
.top-actions .icon-button:hover { background: var(--surface-2); border-color: var(--rule); color: var(--ink); }
.mobile-search { display: none; }
.systembar .sys-link { border: 0; background: none; padding: 0; font: inherit; cursor: pointer; }
.systembar .sys-link:hover { text-decoration: underline; }

#viewRoot { padding: 22px 24px 44px; width: 100%; max-width: 1560px; margin: 0 auto; }
#viewRoot:focus { outline: none; }
.view-head { align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 15px; }
.view-head h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.025em; line-height: 1.15; margin-bottom: 4px; }
.view-head p { font-size: 12.5px; line-height: 1.5; color: var(--muted); max-width: 760px; }
.view-head .eyebrow { color: var(--muted); }
.view-actions { padding-top: 2px; }
.view-head-with-back { gap: 10px; }

.page-purpose {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.45;
}
.page-purpose .icon-sm { flex: none; margin-top: 1px; color: var(--muted); }

/* ---------- controls ---------- */

.btn.secondary { background: var(--surface); border-color: var(--rule-strong); color: var(--ink); }
.btn.secondary:hover { background: var(--surface-2); border-color: var(--ink-2); }
.btn.small { height: 28px; padding: 0 9px; font-size: 12px; border-radius: 2px; }
.btn.primary .icon { color: var(--on-accent); }
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  color: var(--ink-2);
}
.icon-button:hover { background: var(--surface-2); border-color: var(--rule); color: var(--ink); }
.icon-button .icon { width: 17px; height: 17px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 11px; }
.field > span {
  display: block;
  color: var(--muted);
  font: 500 10px/1.25 var(--font-mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.field input, .field select, .field textarea, .input, .select {
  width: 100%;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
  outline: none;
}
.field textarea { height: auto; min-height: 76px; padding: 8px 9px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field > .field-hint { display: block; margin-top: 1px; color: var(--muted); font-family: var(--font-ui); font-size: 10.5px; font-weight: 400; letter-spacing: 0; text-transform: none; line-height: 1.45; }
.detail-list > .mini-section { display: block; border: 0; padding: 0; justify-content: flex-start; }
.detail-list > .mini-section:first-child { margin-top: 0; }
.copy-box { border-radius: 2px; border-style: solid; border-color: var(--rule); padding: 7px 9px; }
.field-hint.error { color: var(--danger); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.form-error { border-radius: 2px; border-color: color-mix(in srgb, var(--danger) 30%, transparent); padding: 8px 10px; font-size: 11.5px; }
.email-builder { border-radius: 2px; }
.email-builder select { height: 32px; width: 190px; max-width: 190px; }
.email-at { font-family: var(--font-mono); }
select.language-select { height: 30px; }
.switch { width: 34px; height: 20px; }
.switch::after { width: 16px; height: 16px; }
.switch[aria-checked="true"]::after { transform: translateX(14px); }

/* ---------- surfaces ---------- */

.card { border: 1px solid var(--rule); border-radius: 2px; box-shadow: none; background: var(--surface); }
.card-pad { padding: 14px 16px; }
.card-head { padding: 13px 16px 0; }
.card-head h2, .card-head h3 { font-size: 13px; font-weight: 600; }
.card-head p { font-size: 10.5px; }
.stat-grid { gap: 0; border: 1px solid var(--rule); background: var(--surface); margin-bottom: 16px; }
.stat-card { border: 0; border-right: 1px solid var(--rule); border-radius: 0; padding: 10px 13px; background: transparent; box-shadow: none; }
.stat-card:last-child { border-right: 0; }
.stat-card::after { display: none; }
.stat-label { font: 500 10px/1.2 var(--font-mono); letter-spacing: 0.04em; color: var(--muted); }
.stat-value { font-size: 22px; margin: 6px 0 2px; font-weight: 600; letter-spacing: -0.02em; }
.stat-meta { font-size: 10px; }
.dashboard-grid { gap: 16px; }
.policy-ring { padding: 14px 16px; }
.ring { border-radius: 50%; }
.quick-grid { padding: 12px 16px 16px; gap: 6px; }
.quick-action { border-radius: 2px; padding: 9px 10px; background: var(--surface); }
.quick-action small { font-size: 9.5px; }
.audit-mini-item { padding: 9px 16px; }
.audit-mini-icon { border-radius: 2px; }
.bulk-bar { border-radius: 2px; }
.table-wrap { border-radius: 0; box-shadow: none; border: 1px solid var(--rule); background: var(--surface); }
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 12px; }
table.data th {
  padding: 7px 10px;
  border-bottom: 1px solid var(--rule-strong);
  background: var(--surface-2);
  color: var(--muted);
  font: 500 10px/1.2 var(--font-mono);
  letter-spacing: 0.045em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
}
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr.clickable { cursor: pointer; }
table.data .cell-sub { font-family: var(--font-mono); font-size: 10px; color: var(--muted); }
.mini-identity { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.mini-identity > span:last-child { min-width: 0; }
.mini-identity b, .mini-identity small { display: block; }
.mini-identity b { font-weight: 500; font-size: 12px; }
.mini-identity small { font-family: var(--font-mono); font-size: 10px; color: var(--muted); }
.user-dash-grid .user-panel { background: var(--surface); border: 1px solid var(--rule); padding: 12px 14px; }
.health-lead .eyebrow, .page-head .eyebrow, .view-head .eyebrow { color: var(--muted); }
.user-cell b { font-weight: 500; font-size: 12px; }
.user-cell small { font-family: var(--font-mono); font-size: 10px; }
.user-cell .avatar { width: 27px; height: 27px; font-size: 10px; }
.pagination { padding: 8px 11px; background: var(--surface); font-size: 10.5px; }
.row-actions .icon-button { width: 25px; height: 25px; }
.row-actions .icon-button .icon { width: 14px; height: 14px; }

.badge {
  border-radius: 2px;
  padding: 2px 5px;
  font: 500 9.5px/1.25 var(--font-mono);
  letter-spacing: 0.02em;
  text-transform: none;
  border: 1px solid var(--rule);
  background: var(--surface-2);
  color: var(--ink-2);
}
.badge.active, .badge.good { background: var(--good-soft); color: var(--good); border-color: color-mix(in srgb, var(--good) 28%, transparent); }
.badge.suspended, .badge.danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }
.badge.invited, .badge.pending, .badge.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 28%, transparent); }
.badge.system { background: var(--accent-soft); color: var(--accent-text); border-color: color-mix(in srgb, var(--accent) 22%, transparent); }
.badge.neutral { background: var(--surface-3); color: var(--muted); border-color: var(--rule); }
.badge.verified { background: var(--good-soft); color: var(--good); border-color: transparent; }

.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--rule); margin: 0 0 14px; }
.tabs button {
  border: 0;
  background: none;
  padding: 8px 11px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  border-radius: 0;
}
.tabs button.active { color: var(--accent-text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.detail-list { gap: 0; }
.detail-row { padding: 7px 0; border-bottom: 1px solid var(--rule); font-size: 11.5px; }
.detail-row span { color: var(--muted); }
.detail-row b { font-weight: 500; color: var(--ink-2); }
.mini-section h3 { font-family: var(--font-mono); letter-spacing: 0.04em; }
.group-role-notice { border-radius: 2px; }
.permission-check, .role-card, .entity-card, .check-pill, .bulk-bar, .policy-save { border-radius: 2px; }
.policy-save { box-shadow: var(--shadow); }
.policy-nav button { border-radius: 2px; }
.empty { padding: 42px 20px; }
.empty .icon { width: 26px; height: 26px; }
.empty h3 { font-size: 13px; font-weight: 600; }
.entity-icon { border-radius: 2px; }
.check-dot { border-radius: 50%; }

/* ---------- modals and drawers ---------- */

.modal-backdrop { background: rgba(8, 15, 23, 0.5); backdrop-filter: none; }
.modal {
  border-radius: 2px;
  border: 1px solid var(--rule-strong);
  box-shadow: var(--shadow-overlay);
  background: var(--surface);
}
.modal-head { padding: 12px 16px 10px; border-bottom: 1px solid var(--rule); background: var(--surface-2); }
.modal-title h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.modal-title p { font-size: 10.5px; }
.modal-body { padding: 13px 16px; }
.modal-foot { background: var(--surface-2); border-radius: 0; padding: 10px 16px 14px; }
.modal-close { width: 26px; height: 26px; }
.drawer-backdrop { background: rgba(8, 15, 23, 0.42); }
.drawer { border-radius: 0; }
.drawer-head { padding: 13px 16px; }
.drawer-head h2 { font-size: 15px; font-weight: 600; }
.drawer-body { padding: 12px 16px 22px; }
.drawer-foot { border-radius: 0; }
.toast { border-radius: 2px; border: 1px solid var(--rule-strong); background: var(--surface); box-shadow: var(--shadow); color: var(--ink); font-size: 11.5px; }
.toast.error { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }

/* ---------- old-specific components ---------- */

.migration-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--rule); margin-bottom: 12px; }
.migration-tab { border: 0; border-bottom: 2px solid transparent; background: none; padding: 8px 12px; color: var(--muted); font-size: 11.5px; margin-bottom: -1px; }
.migration-tab.active { color: var(--accent-text); border-bottom-color: var(--accent); font-weight: 600; }
.migration-tab span { font-family: var(--font-mono); font-size: 9.5px; margin-left: 3px; }
.migration-progress { height: 4px; background: var(--surface-3); overflow: hidden; min-width: 80px; }
.migration-progress span { display: block; height: 100%; background: var(--accent); }
.group-toolbar { gap: 7px; }
.toolbar { gap: 7px; margin-bottom: 12px; }
.toolbar .search-box { border-radius: 2px; background: var(--surface); }
.toolbar-search { position: relative; display: flex; align-items: center; flex: 0 1 320px; }
.toolbar-search > .icon { position: absolute; left: 9px; width: 14px; height: 14px; color: var(--muted); pointer-events: none; }
.toolbar .search-box { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 9px; border: 1px solid var(--rule); border-radius: 2px; background: var(--surface); min-width: 220px; }
.toolbar .search-box .icon { width: 14px; height: 14px; color: var(--muted); flex: none; }
.toolbar .search-box input { flex: 1; min-width: 0; height: 30px; padding: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 11.5px; }
.toolbar .search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.toolbar .toolbar-search > .input { padding-left: 31px; }
.toolbar select, .toolbar .input { border-radius: 2px; height: 30px; padding: 0 8px; font-size: 11.5px; }
.input-group .input { border-radius: 2px; }
.tag-input { border-radius: 2px; }

.license-gate-card, .error-panel { border-radius: 2px; }
.license-gate-icon { border-radius: 2px; }
.code, code, kbd { font-family: var(--font-mono); }

/* ---------- login ---------- */

.login-help { margin: 16px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.login-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 22px; padding-top: 10px; border-top: 1px solid var(--rule); color: var(--muted); font: 400 9.5px/1.4 var(--font-mono); }
.login-card h2 { font-weight: 600; }
.login-card .login-sub { font-size: 12px; }
.login-language .field > span { display: block; }
.login-form { margin-top: 2px; }
.login-card .form-error { margin: 0; }
.login-lang-select { height: 24px; }
.link-quiet { border: 0; background: none; padding: 0; color: var(--muted); font-size: 11px; cursor: pointer; }
.link-quiet:hover { color: var(--ink); }
#mfaStep .link-quiet { margin-bottom: 16px; }
#useRecoveryBtn { display: block; margin: 13px auto 0; }

/* ---------- responsive ---------- */

@media (max-width: 1320px) {
  .plan-badge { display: none; }
}
@media (max-width: 1180px) {
  .language-select.select { width: 92px; }
}
@media (max-width: 1100px) {
  .language-select.select { display: none; }
}
@media (max-width: 980px) {
  #viewRoot { padding: 18px 18px 36px; }
  .topbar { padding: 0 14px; }
  .topbar-search { display: none; }
  .mobile-search { display: inline-grid; }
  .view-head { flex-direction: column; gap: 10px; }
  .view-head h1 { font-size: 23px; }
  .view-actions { width: 100%; }
  .scope-path .scope-label, .scope-path .slash, .env-tag { display: none; }
  .modal { width: calc(100vw - 20px); }
  .field-row { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-card:nth-child(2) { border-right: 0; }
  .stat-card:nth-child(-n+2) { border-bottom: 1px solid var(--rule); }
}
@media (max-width: 720px) {
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .page-head .head-actions { width: 100%; padding-top: 0; }
  .page-head .head-actions .btn { flex: 1; }
  .work-table th:nth-child(2), .work-table td:nth-child(2),
  .work-table th:nth-child(3), .work-table td:nth-child(3),
  .risk-table th:nth-child(2), .risk-table td:nth-child(2),
  .risk-table th:nth-child(3), .risk-table td:nth-child(3) { display: none; }
  .work-title, .risk-line b { white-space: normal; }
  .systembar { gap: 8px; justify-content: space-between; }
  .systembar .sys-item { gap: 5px; }
  .systembar .sys-item:nth-of-type(4) { display: none; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .scope-org span { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
  .systembar { gap: 10px; font-size: 10px; }
  .systembar .hide-mobile { display: none; }
  .icon-button, .icon-btn { width: 28px; height: 28px; }
  .view-head .view-actions .btn { flex: 1; }
  .table-wrap { overflow-x: auto; }
  .modal-foot .btn { flex: 1; }
}

/* ---------- RTL ---------- */
[dir="rtl"] .rail { border-right: 0; border-left: 1px solid rgba(255,255,255,0.06); border-radius: 8px 0 0 8px; box-shadow: -18px 0 44px rgba(4,10,18,0.22), -4px 0 12px rgba(4,10,18,0.14), inset 1px 0 0 rgba(255,255,255,0.07); }
[dir="rtl"] .nav-link.active, [dir="rtl"] .nav-link[aria-current="page"] { box-shadow: inset -2px 0 0 var(--accent-on-rail); }
[dir="rtl"] .nav-item.rail-settings, [dir="rtl"] .nav-link { text-align: right; }
[dir="rtl"] .table th, [dir="rtl"] table.data th { text-align: right; }
[dir="rtl"] .nav-flyout { /* positioned by the shell */ }
[dir="rtl"] .scope-path, [dir="rtl"] .systembar, [dir="rtl"] .topbar { direction: rtl; }
