:root {
  --bg: #F5F6F7;
  --surface: #FFFFFF;
  --surface-soft: #FAFAFA;
  --neutral-200: #BFBFBF;
  --neutral-700: #4C4C4C;
  --text: #2B2B2B;
  --text-inverse: #E9EAEB;
  --muted: #6F7479;
  --line: #E0E2E4;
  --line-strong: #C9CDD1;
  --brand-dark: #BC3210;
  --brand: #FE5B20;
  --brand-soft: #F38C72;
  --brand-pale: #FFF0EA;
  --brand-pale-strong: #FFD1C2;
  --success: #247A4D;
  --success-bg: #EAF7F0;
  --warning: #92500C;
  --warning-bg: #FFF3E3;
  --danger-bg: #FFF1ED;
  --focus: 0 0 0 3px rgba(254, 91, 32, .20);
  --shadow: 0 8px 28px rgba(43, 43, 43, .055);
  --radius: 10px;
  --radius-sm: 6px;
  --container: 1280px;
  --header-height: 64px;
}

* { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.48 "Segoe UI", Inter, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { color: var(--brand); }

.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.skip-link:focus { top: 12px; }

.ui-icon {
  display: block;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--neutral-700);
  color: var(--text-inverse);
  border-bottom: 3px solid var(--brand);
  box-shadow: 0 3px 14px rgba(0, 0, 0, .16);
}
.topbar-inner {
  width: min(100%, var(--container));
  height: 100%;
  min-height: var(--header-height);
  margin: 0 auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: stretch;
}
.brand {
  min-width: 176px;
  padding-right: 22px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  white-space: nowrap;
}
.brand:hover { color: #fff; }
.brand-logo { display: block; width: 132px; height: 24px; flex: 0 0 auto; }
.brand-product {
  padding-left: 10px;
  border-left: 1px solid rgba(255,255,255,.24);
  color: var(--brand-soft);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.main-nav {
  min-width: 0;
  display: flex;
  align-items: stretch;
}
.main-nav > a {
  min-width: 104px;
  padding: 0 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--text-inverse);
  border-left: 1px solid rgba(255,255,255,.045);
  border-bottom: 3px solid transparent;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.main-nav > a:hover,
.main-nav > a.is-active {
  color: #fff;
  background: var(--text);
  border-bottom-color: var(--brand);
}
.main-nav > a.nav-cta,
.main-nav > a.nav-cta:hover,
.main-nav > a.nav-cta.is-active {
  color: #fff;
  background: var(--brand);
  border-bottom-color: var(--brand-dark);
}
.main-nav > a.nav-cta:hover { background: var(--brand-dark); }
.account-nav {
  padding-left: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.account-summary {
  max-width: 220px;
  margin-right: 4px;
  display: grid;
  line-height: 1.2;
  text-align: right;
}
.account-summary strong {
  overflow: hidden;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-summary span { margin-top: 3px; color: var(--neutral-200); font-size: 11px; }
.account-action,
.logout-form button,
.menu-toggle {
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.20);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #fff;
  cursor: pointer;
}
.account-action:hover,
.logout-form button:hover,
.menu-toggle:hover { border-color: var(--brand); background: var(--brand); color: #fff; }
.logout-form { margin: 0; display: flex; }
.menu-toggle { display: none; }

/* Main layout */
.container {
  width: min(calc(100% - 40px), var(--container));
  margin: 0 auto;
  padding: 30px 0 54px;
  flex: 1 0 auto;
}
.site-footer { margin-top: auto; border-top: 1px solid var(--line); background: #F0F1F2; color: var(--muted); }
.site-footer-inner {
  width: min(calc(100% - 40px), var(--container));
  min-height: 48px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  font-size: 12px;
}

h1, h2, h3 { color: var(--text); line-height: 1.2; }
h1 { margin: 0; font-size: clamp(27px, 2.7vw, 38px); font-weight: 750; letter-spacing: -.018em; }
h2 { margin: 0; font-size: 21px; font-weight: 720; }
h3 { margin: 0; font-size: 17px; font-weight: 710; }
p { margin: 0; }
.muted { color: var(--muted); }
.mono, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
code { font-size: 12px; overflow-wrap: anywhere; }
.eyebrow {
  margin-bottom: 7px;
  color: var(--brand-dark);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.page-head {
  margin-bottom: 22px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 22px;
}
.page-head h1 { margin-bottom: 7px; }
.page-head-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }

/* Cards and grids */
.card {
  min-width: 0;
  margin-bottom: 20px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  margin-bottom: 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.card-header h2, .card-header h3 { margin: 0; }
.card-subtitle { margin-top: 5px; color: var(--muted); font-size: 13px; }
.narrow { max-width: 850px; margin-left: auto; margin-right: auto; }
.resource-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 350px);
  gap: 24px;
  align-items: start;
}
.resource-main { min-width: 0; }
.resource-aside {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}
.resource-aside h2 { margin-bottom: 8px; font-size: 18px; }
.resource-aside > .muted { margin-bottom: 16px; font-size: 13px; }
.stats {
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}
.stat {
  min-height: 108px;
  padding: 18px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.stat::after {
  content: "";
  position: absolute;
  right: -28px;
  bottom: -32px;
  width: 82px;
  height: 82px;
  border: 17px solid var(--brand-pale-strong);
  border-radius: 50%;
  opacity: .6;
}
.stat strong { display: block; margin-bottom: 9px; font-size: 31px; line-height: 1; }
.stat span { color: var(--muted); font-size: 13px; }

/* Forms */
.form-grid { display: grid; gap: 17px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field, label.field {
  min-width: 0;
  display: grid;
  gap: 7px;
  color: var(--text);
  font-weight: 680;
}
.field.is-disabled { opacity: .58; }
.field-hint { color: var(--muted); font-size: 12px; font-weight: 400; line-height: 1.4; }
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--surface);
  color: var(--text);
  transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
}
textarea { min-height: 112px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: var(--focus); }
input:disabled, select:disabled, textarea:disabled { background: #ECEEEF; color: var(--muted); cursor: not-allowed; }
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px #fff inset;
}
.checkbox-field {
  min-height: 44px;
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 680;
  cursor: pointer;
}
.checkbox-field input[type="checkbox"] {
  appearance: none;
  width: 20px;
  height: 20px;
  margin: 0;
  display: grid;
  place-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #fff;
}
.checkbox-field input[type="checkbox"]::after {
  content: "";
  width: 10px;
  height: 6px;
  margin-top: -2px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) scale(0);
  transition: transform .1s ease;
}
.checkbox-field input[type="checkbox"]:checked { border-color: var(--brand); background: var(--brand); }
.checkbox-field input[type="checkbox"]:checked::after { transform: rotate(-45deg) scale(1); }
.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Buttons */
.button,
button[type="submit"]:not(.menu-toggle) {
  min-height: 42px;
  padding: 9px 17px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 710;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .14s ease, border-color .14s ease, color .14s ease, transform .05s ease;
}
.button:hover,
button[type="submit"]:not(.menu-toggle):hover { background: var(--brand-dark); color: #fff; }
.button:active,
button[type="submit"]:not(.menu-toggle):active { transform: translateY(1px); }
.button.secondary,
button.secondary { background: var(--neutral-700); color: #fff; }
.button.secondary:hover,
button.secondary:hover { background: var(--text); }
.button.soft,
button.soft { border-color: var(--brand-pale-strong); background: var(--brand-pale); color: var(--brand-dark); }
.button.soft:hover,
button.soft:hover { background: var(--brand-pale-strong); color: var(--brand-dark); }
.button.danger,
button.danger { background: var(--brand-dark); color: #fff; }
.button.danger:hover,
button.danger:hover { background: #8D250C; }
.button.small,
button.small { min-height: 34px; padding: 6px 10px; font-size: 12px; }
button[disabled], .button[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.logout-form button { min-height: 36px; padding: 0; border-color: rgba(255,255,255,.20); background: transparent; }
.logout-form button:hover { background: var(--brand); }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { width: 100%; min-width: 680px; border-collapse: collapse; background: #fff; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th {
  background: #FAFAFA;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: .055em;
  text-transform: uppercase;
}
tbody tr:hover { background: #FFF8F5; }
tbody tr:last-child td { border-bottom: 0; }
.actions-cell { width: 1%; text-align: right; white-space: nowrap; }
.table-empty { padding: 30px; color: var(--muted); text-align: center; }

/* Badges */
.badge {
  min-height: 25px;
  padding: 4px 9px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 760;
  letter-spacing: .025em;
  white-space: nowrap;
}
.badge.active, .badge.status-published { background: var(--success-bg); color: var(--success); }
.badge.inactive, .badge.status-revoked { background: #ECEEEF; color: #62676D; }
.badge.status-draft { background: var(--warning-bg); color: var(--warning); }
.badge.role-superadmin { background: var(--danger-bg); color: var(--brand-dark); }
.badge.role-admin { background: #F0EDF8; color: #51456F; }
.badge.role-internal { background: #EAF3F8; color: #35627B; }
.badge.role-customer { background: #EDF7F0; color: #32603F; }

/* Alerts and details */
.alert { margin-bottom: 18px; padding: 13px 15px; border: 1px solid; border-radius: var(--radius); font-weight: 620; }
.alert.error { border-color: #F1B4A6; background: var(--danger-bg); color: #92280F; }
.alert.info { border-color: var(--brand-pale-strong); background: #FFF7F3; color: #6B3425; }
.help-note { padding: 16px; border-left: 4px solid var(--brand); border-radius: var(--radius-sm); background: var(--brand-pale); color: var(--text); }
.details { margin: 0; display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 11px 22px; }
.details dt { color: var(--muted); font-weight: 650; }
.details dd { margin: 0; }
.customer-hero {
  margin-bottom: 20px;
  padding: 28px;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: linear-gradient(112deg, var(--neutral-700), var(--text));
  color: var(--text-inverse);
}
.customer-hero::after {
  content: "";
  position: absolute;
  right: -55px;
  top: -90px;
  width: 220px;
  height: 220px;
  border: 34px solid rgba(254,91,32,.42);
  border-radius: 50%;
}
.customer-hero .eyebrow, .customer-hero h1, .customer-hero p { position: relative; z-index: 1; }
.customer-hero h1 { color: #fff; margin-bottom: 7px; }
.customer-hero p { color: var(--text-inverse); }

/* Login */
.login-shell { min-height: calc(100vh - 178px); padding: 34px 0; display: grid; place-items: center; }
.login-card { width: min(100%, 510px); padding: 32px; }
.login-mark { width: 54px; height: 5px; margin-bottom: 21px; background: var(--brand); }
.login-card h1 { margin-bottom: 8px; font-size: 30px; }
.login-card .form-grid { margin-top: 22px; }

/* Destructive and share areas */
.danger-zone {
  max-width: 850px;
  margin: 20px auto;
  padding: 20px;
  border: 1px solid #E9A895;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #FFFDFC, #FFF7F4);
}
.danger-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px 22px;
}
.danger-action + .danger-action {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #E9B8AA;
}
.danger-action h2, .danger-action h3 { margin-bottom: 4px; color: var(--brand-dark); }
.danger-action p { max-width: 650px; color: var(--muted); font-size: 13px; }
.danger-action form { justify-self: end; }
.share-result {
  margin-bottom: 20px;
  padding: 18px;
  border: 1px solid var(--brand-pale-strong);
  border-left: 5px solid var(--brand);
  border-radius: var(--radius);
  display: grid;
  gap: 8px;
  background: #FFF7F3;
}
.share-result-row { margin-top: 4px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }

/* Pagination */
.pagination { margin-top: 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.pagination-list { display: flex; align-items: center; gap: 5px; }
.pagination-list a, .pagination-list .page-current {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: var(--text);
  font-weight: 650;
}
.pagination-list a:hover { border-color: var(--brand); color: var(--brand-dark); }
.pagination-list .page-current { border-color: var(--brand); background: var(--brand); color: #fff; }

@media (max-width: 1100px) {
  .topbar-inner { padding: 0 16px; }
  .brand { min-width: 150px; padding-right: 15px; }
  .brand-product { display: none; }
  .main-nav > a { min-width: auto; padding: 0 12px; }
  .account-summary { display: none; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .resource-layout { grid-template-columns: 1fr; }
  .resource-aside { max-width: none; }
}

@media (max-width: 820px) {
  :root { --header-height: 60px; }
  .topbar { height: auto; min-height: var(--header-height); }
  .topbar-inner {
    min-height: var(--header-height);
    grid-template-columns: auto 1fr auto;
    position: relative;
  }
  .brand { min-width: 0; height: var(--header-height); }
  .brand-logo { width: 122px; height: 22px; }
  .account-nav { grid-column: 3; padding-left: 8px; }
  .menu-toggle { display: inline-flex; }
  .main-nav {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    display: none;
    flex-direction: column;
    align-items: stretch;
    background: var(--neutral-700);
    border-top: 1px solid rgba(255,255,255,.12);
    box-shadow: 0 10px 18px rgba(0,0,0,.15);
  }
  .main-nav.is-open { display: flex; }
  .main-nav > a {
    min-height: 46px;
    padding: 0 18px;
    justify-content: flex-start;
    border-left: 4px solid transparent;
    border-bottom: 0;
  }
  .main-nav > a.is-active { border-left-color: var(--brand); }
  .account-action { display: none; }
  .container { width: min(calc(100% - 24px), var(--container)); padding-top: 22px; }
  .site-footer-inner { width: min(calc(100% - 24px), var(--container)); }
  .page-head { flex-direction: column; }
  .page-head-actions { justify-content: flex-start; }
  .form-grid.cols-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .details { grid-template-columns: 1fr; gap: 3px; }
  .details dd { margin-bottom: 9px; }
  .danger-action { grid-template-columns: 1fr; align-items: start; }
  .danger-action form { justify-self: start; }
  .share-result-row { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .topbar-inner { padding: 0 12px; }
  .brand-logo { width: 112px; height: 21px; }
  .container { width: min(calc(100% - 20px), var(--container)); }
  .card { padding: 18px; }
  .stats { grid-template-columns: 1fr; }
  .form-actions, .page-head-actions { width: 100%; flex-direction: column; align-items: stretch; }
  .form-actions .button, .form-actions button, .page-head-actions .button { width: 100%; }
  .site-footer-inner { width: min(calc(100% - 20px), var(--container)); min-height: 62px; flex-direction: column; justify-content: center; align-items: flex-start; gap: 3px; }
  .pagination { align-items: flex-start; flex-direction: column; }
}
