:root {
  color-scheme: light;
  --ink: #211a23;
  --muted: #6a606c;
  --line: #ded7df;
  --paper: #ffffff;
  --canvas: #f5f3f5;
  --plum: #6e3678;
  --plum-dark: #522346;
  --orange: #f06418;
  --green: #167040;
  --green-soft: #e6f5ec;
  --amber: #965b00;
  --amber-soft: #fff1d4;
  --red: #bb281f;
  --red-soft: #ffebe9;
  --shadow: 0 12px 34px rgba(43, 27, 48, .09);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); min-height: 100vh; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.security-strip {
  min-height: 32px;
  padding: 7px 16px;
  text-align: center;
  background: #241926;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.auth-shell {
  width: min(1040px, calc(100% - 32px));
  min-height: calc(100vh - 32px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 480px);
  align-items: center;
  gap: 72px;
  padding: 48px 0;
}

.auth-brand { display: flex; align-items: center; gap: 24px; }
.auth-brand img { width: 104px; height: 104px; border-radius: 8px; box-shadow: var(--shadow); }
.auth-brand span, .eyebrow { color: var(--plum); text-transform: uppercase; font-size: 12px; font-weight: 900; letter-spacing: .1em; }
.auth-brand h1 { margin: 8px 0 10px; font-size: clamp(38px, 5vw, 64px); line-height: .98; letter-spacing: 0; }
.auth-brand p { margin: 0; max-width: 440px; color: var(--muted); font-size: 18px; line-height: 1.55; }

.auth-card, .surface, .panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.auth-card { padding: 34px; box-shadow: var(--shadow); }
.auth-card.wide { grid-column: 2; }
.auth-card h2, .panel h2 { margin: 8px 0; font-size: 28px; }
.auth-card > p { margin: 0 0 24px; color: var(--muted); line-height: 1.55; }

.form-stack { display: grid; gap: 16px; }
.form-stack.compact { margin-top: 24px; grid-template-columns: 1fr auto; align-items: end; }
label { display: grid; gap: 7px; color: #4e4351; font-size: 13px; font-weight: 800; }
input, select, textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid #cfc6d0;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 11px 13px;
  outline: none;
}
textarea { min-height: 94px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--plum); box-shadow: 0 0 0 3px rgba(110, 54, 120, .13); }

.btn {
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 11px 17px;
  font-weight: 900;
}
.btn.primary { background: linear-gradient(100deg, var(--plum), var(--orange)); color: #fff; }
.btn.secondary { background: #fff; border-color: #bfb5c1; color: var(--ink); }
.btn.danger { background: var(--red-soft); color: var(--red); border-color: #f0aaa5; }
.btn:disabled { cursor: not-allowed; opacity: .5; }
.text-btn { border: 0; background: transparent; color: var(--plum); padding: 0; font-weight: 900; }
.password-rule { padding: 11px 13px; border-left: 3px solid var(--orange); color: var(--muted); font-size: 13px; line-height: 1.45; }

.mfa-setup-grid { display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: center; }
.qr-box { aspect-ratio: 1; display: grid; place-items: center; border: 1px solid var(--line); padding: 12px; background: #fff; }
.qr-box img { width: 100%; height: 100%; image-rendering: pixelated; }
.mfa-secret { display: grid; gap: 10px; min-width: 0; }
.mfa-secret span { color: var(--muted); font-size: 13px; font-weight: 800; }
.mfa-secret code { overflow-wrap: anywhere; padding: 12px; background: #f3eef4; border: 1px solid #e1d4e3; font-weight: 900; }

.app-shell { min-height: calc(100vh - 32px); }
.app-header {
  min-height: 76px;
  padding: 12px max(24px, calc((100vw - 1380px) / 2));
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 22px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; font-weight: 950; }
.brand img { width: 48px; height: 48px; border-radius: 6px; }
.brand span { display: grid; font-size: 19px; }
.brand small { color: var(--muted); font-size: 11px; font-weight: 700; }
.admin-identity { display: grid; text-align: right; }
.admin-identity span { color: var(--muted); font-size: 12px; }
.icon-btn { width: 42px; height: 42px; border: 1px solid var(--line); background: #fff; border-radius: 6px; font-size: 22px; }

.workspace { width: min(1380px, calc(100% - 40px)); margin: 24px auto 60px; }
.tabs { display: flex; gap: 5px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tab { white-space: nowrap; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); padding: 14px 16px 12px; font-weight: 850; }
.tab.active { color: var(--plum-dark); border-bottom-color: var(--orange); }
.count { display: inline-grid; min-width: 22px; height: 22px; place-items: center; padding: 0 6px; border-radius: 11px; background: var(--amber-soft); color: var(--amber); font-size: 11px; }

.panel { display: none; border-top: 0; padding: 26px; border-radius: 0 0 8px 8px; }
.panel.active { display: block; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.panel-head h2 { margin: 5px 0 0; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpis article { min-height: 122px; border: 1px solid var(--line); padding: 20px; display: grid; align-content: space-between; border-radius: 6px; }
.kpis span { color: var(--muted); font-size: 13px; font-weight: 800; }
.kpis strong { font-size: 30px; }
.notice { display: grid; grid-template-columns: 210px 1fr; gap: 20px; margin-top: 18px; padding: 18px; background: #f1ebf2; border-left: 4px solid var(--plum); }
.notice span { color: var(--muted); line-height: 1.5; }

.split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.admins-layout { grid-template-columns: minmax(300px, .72fr) minmax(0, 1.28fr); gap: 24px; }
.surface { padding: 20px; }
.surface h3 { margin: 0 0 18px; font-size: 18px; }
.admin-access-section { min-width: 0; }
.admin-access-section h3 { margin: 0 0 18px; font-size: 18px; }
.admin-access-list { display: grid; gap: 10px; }
.admin-access-card {
  display: grid;
  grid-template-columns: minmax(190px, 1.25fr) minmax(180px, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}
.admin-access-person,
.admin-access-detail,
.admin-access-state { display: grid; align-content: center; gap: 5px; min-width: 0; }
.admin-access-person strong,
.admin-access-detail strong { line-height: 1.2; overflow-wrap: anywhere; }
.admin-access-card small { color: var(--muted); line-height: 1.35; overflow-wrap: anywhere; }
.field-label { color: var(--muted); font-size: 10px; font-weight: 900; text-transform: uppercase; }
.admin-access-state { justify-items: start; }
.admin-access-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; padding-top: 4px; border-top: 1px solid #eee8ef; }
.disabled-form { opacity: .58; pointer-events: none; }
.segmented { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; padding: 4px; background: #eee9ef; border-radius: 6px; }
.segmented label { display: block; }
.segmented input { position: absolute; width: 1px; height: 1px; min-height: 0; margin: 0; opacity: 0; pointer-events: none; }
.segmented span { display: grid; min-height: 40px; place-items: center; border-radius: 4px; }
.segmented input:checked + span { background: #fff; color: var(--plum-dark); box-shadow: 0 1px 5px rgba(0,0,0,.08); }
.target-result { min-height: 74px; padding: 14px; border: 1px dashed #c9bdcb; line-height: 1.5; }
.target-result strong, .target-result span { display: block; }
.target-result .target-option-title { display: flex; }
.target-result .target-scope { display: inline-flex; }
.target-result.selected { border-style: solid; border-color: #9bcca9; background: var(--green-soft); color: var(--ink); }
.target-directory-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; font-weight: 800; }
.target-field { display: grid; gap: 7px; min-width: 0; }
.target-combobox { position: relative; min-width: 0; }
.target-combobox input { padding-right: 48px; }
.target-combobox-toggle {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 46px;
  height: 46px;
  border: 0;
  border-left: 1px solid #e3dce4;
  border-radius: 0 5px 5px 0;
  background: #fff;
  color: var(--plum);
  font-size: 18px;
}
.target-combobox-toggle:hover, .target-combobox-toggle:focus-visible { background: #f6f1f7; outline: none; }
.target-dropdown {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 18px 38px rgba(39, 23, 42, .18);
}
.target-directory { display: grid; max-height: 286px; overflow-y: auto; }
.target-option {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 0;
  border-bottom: 1px solid #eee8ef;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  padding: 11px;
  text-align: left;
}
.target-option:last-child { border-bottom: 0; }
.target-option:hover, .target-option:focus-visible, .target-option.is-active { background: #f5eef6; outline: none; }
.target-option.is-selected { border-color: var(--green); box-shadow: inset 3px 0 0 var(--green); background: var(--green-soft); }
.target-option:disabled { cursor: not-allowed; opacity: .58; }
.target-option-copy { display: grid; gap: 4px; min-width: 0; }
.target-option-copy strong, .target-option-copy small { overflow-wrap: anywhere; }
.target-option-copy small { color: var(--muted); line-height: 1.35; }
.target-option-title { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; min-width: 0; }
.target-scope { display: inline-flex; align-items: center; min-height: 22px; padding: 3px 7px; border-radius: 11px; font-size: 10px; font-weight: 900; text-transform: uppercase; }
.target-scope.corp { background: #e5f5ea; color: #176b38; }
.target-scope.personal { background: #f0edf2; color: #6c6270; }
.target-company { color: var(--plum-dark) !important; font-weight: 800; }
.target-option-action { color: var(--plum); font-size: 12px; font-weight: 900; white-space: nowrap; }
.target-load-more { width: 100%; min-height: 38px; margin-top: 5px; border: 0; border-top: 1px solid var(--line); background: #fff; color: var(--plum); font-weight: 900; }
.target-dropdown .empty { padding: 18px 12px; border: 0; }

.record-list { display: grid; gap: 10px; }
.record { display: grid; grid-template-columns: minmax(220px, 1.5fr) repeat(3, minmax(130px, 1fr)) auto; gap: 14px; align-items: center; padding: 15px; border: 1px solid var(--line); border-radius: 6px; }
.record strong, .record span, .record small { overflow-wrap: anywhere; }
.record small { color: var(--muted); }
.record-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.compact-list .record { grid-template-columns: minmax(180px, 1fr) minmax(150px, .8fr) auto; }
.empty { padding: 26px; text-align: center; color: var(--muted); border: 1px dashed var(--line); }
.status-chip { display: inline-flex; align-items: center; min-height: 30px; padding: 5px 10px; border-radius: 15px; background: var(--green-soft); color: var(--green); font-size: 12px; font-weight: 900; }
.status-chip.pending { background: var(--amber-soft); color: var(--amber); }
.status-chip.revoked { background: var(--red-soft); color: var(--red); }

.policy-toolbar { display: grid; grid-template-columns: 220px 1fr auto; align-items: end; gap: 14px; margin-bottom: 18px; }
.policy-table { margin-bottom: 18px; overflow: hidden; }
.policy-table h3 { margin-bottom: 12px; }
.policy-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: 10px; align-items: center; border-top: 1px solid #eee8ef; padding: 9px 0; }
.package-row { border-top: 1px solid #eee8ef; padding: 14px 0; }
.package-row-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.package-row-head code { color: var(--muted); font-size: 11px; }
.package-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; align-items: end; }
.package-fields label:nth-child(2) { grid-column: span 2; }
.package-fields input { min-height: 40px; }
.package-toggle { min-height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 11px; border: 1px solid var(--line); border-radius: 5px; }
.package-toggle input { min-height: 0; width: 20px; height: 20px; }

.publication-preview { margin: 8px 0 18px; padding: 20px; border: 1px solid var(--line); background: #fbf9fb; }
.publication-preview-head, .preview-context { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.publication-preview-head h3 { margin: 4px 0 0; }
.preview-segmented { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 520px; margin: 18px 0; }
.preview-segmented button { min-height: 44px; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 900; cursor: pointer; }
.preview-segmented button.active { background: #fff; color: var(--plum); box-shadow: 0 1px 5px rgba(44, 25, 47, .08); }
.preview-canvas { min-width: 0; }
.preview-context { margin-bottom: 14px; color: var(--muted); }
.preview-context strong { color: var(--ink); }
.preview-context span { max-width: 720px; text-align: right; }
.app-package-preview, .store-product-list { display: grid; gap: 10px; }
.app-package-row { display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 14px; border: 1px solid var(--line); background: #fff; }
.app-package-row.featured { border: 2px solid var(--orange); }
.app-package-credits { width: 58px; aspect-ratio: 1; display: grid; place-items: center; background: #f1edf2; color: var(--muted); font-size: 18px; font-weight: 900; }
.app-package-row > div { display: grid; gap: 3px; }
.app-package-row small { display: block; color: var(--muted); }
.app-package-row .operation-copy { color: var(--plum); font-weight: 800; }
.app-package-row em { display: inline-block; margin-left: 6px; padding: 2px 7px; background: var(--orange); color: #fff; border-radius: 10px; font-size: 10px; font-style: normal; }
.app-package-price { text-align: right; }
.preview-table-wrap { overflow-x: auto; border: 1px solid var(--line); background: #fff; }
.preview-table { min-width: 760px; }
.preview-table td strong, .preview-table td small { display: block; }
.preview-table td small { color: var(--muted); margin-top: 3px; }
.store-product-row { display: grid; grid-template-columns: minmax(170px, 1fr) minmax(170px, .9fr) minmax(170px, .9fr) auto; gap: 12px; align-items: center; padding: 14px; border: 1px solid var(--line); background: #fff; }
.store-product-row > div { display: grid; gap: 3px; min-width: 0; }
.store-product-row small, .store-product-row span:not(.status-chip) { color: var(--muted); font-size: 11px; }
.store-product-row code { overflow-wrap: anywhere; font-size: 11px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
td { font-size: 13px; }

.dialog-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px; background: rgba(29, 19, 31, .72); }
.dialog { width: min(440px, 100%); background: #fff; border-radius: 8px; padding: 26px; box-shadow: var(--shadow); display: grid; gap: 15px; }
.dialog h2, .dialog p { margin: 0; }
.dialog p { color: var(--muted); line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 80; max-width: min(430px, calc(100% - 44px)); transform: translateY(140%); transition: transform .22s ease; padding: 15px 18px; border-radius: 6px; background: #241926; color: #fff; box-shadow: var(--shadow); font-weight: 800; }
.toast.show { transform: translateY(0); }
.toast.error { background: var(--red); }

@media (max-width: 920px) {
  .auth-shell { grid-template-columns: 1fr; gap: 28px; align-content: center; }
  .auth-card.wide { grid-column: 1; }
  .auth-brand { justify-content: center; text-align: center; }
  .auth-brand p { margin-inline: auto; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split, .admins-layout { grid-template-columns: 1fr; }
  .record, .compact-list .record { grid-template-columns: 1fr 1fr; }
  .record-actions { justify-content: flex-start; }
  .policy-toolbar { grid-template-columns: 1fr 1fr; }
  .policy-toolbar .btn { grid-column: 1 / -1; }
  .package-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .store-product-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 620px) {
  .security-strip { font-size: 10px; }
  .auth-shell { width: min(100% - 24px, 480px); padding: 26px 0; }
  .auth-brand { display: grid; gap: 14px; }
  .auth-brand img { width: 76px; height: 76px; margin: 0 auto; }
  .auth-brand h1 { font-size: 36px; }
  .auth-brand p { font-size: 15px; }
  .auth-card { padding: 22px; }
  .mfa-setup-grid { grid-template-columns: 1fr; }
  .qr-box { width: min(240px, 100%); margin: 0 auto; }
  .form-stack.compact { grid-template-columns: 1fr; }
  .app-header { grid-template-columns: 1fr auto; padding: 10px 14px; }
  .admin-identity { display: none; }
  .workspace { width: 100%; margin-top: 0; }
  .tabs { padding: 0 8px; background: #fff; }
  .tab { padding-inline: 12px; }
  .panel { padding: 18px 14px; border-inline: 0; }
  .target-option { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .target-option-action { justify-self: start; }
  .panel-head { align-items: flex-start; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpis article { min-height: 100px; padding: 14px; }
  .kpis strong { font-size: 24px; }
  .notice { grid-template-columns: 1fr; gap: 7px; }
  .record, .compact-list .record { grid-template-columns: 1fr; }
  .admin-access-card { grid-template-columns: 1fr; gap: 14px; padding: 16px; }
  .admin-access-state { padding-top: 12px; border-top: 1px solid #eee8ef; }
  .admin-access-actions { justify-content: stretch; }
  .admin-access-actions .btn { width: 100%; }
  .package-fields { grid-template-columns: 1fr; }
  .package-fields label:nth-child(2) { grid-column: auto; }
  .policy-toolbar { grid-template-columns: 1fr; }
  .policy-toolbar .btn { grid-column: 1; }
  .publication-preview { padding: 14px; margin-inline: -4px; }
  .publication-preview-head, .preview-context { display: grid; }
  .preview-context span { text-align: left; }
  .app-package-row { grid-template-columns: 48px minmax(0, 1fr); }
  .app-package-credits { width: 48px; }
  .app-package-price { grid-column: 2; text-align: left; }
  .store-product-row { grid-template-columns: 1fr; }
}
