:root {
  --ink: #0d0d11;
  --dark: #121217;
  --soft: #f5f2ed;
  --panel: #fff;
  --orange: #f78030;
  --orange-dark: #d96a20;
  --orange-soft: #fff4e8;
  --slate: #5d6c7b;
  --muted: #758696;
  --line: #d8d8d2;
  --danger: #754047;
  --danger-soft: #f8eeee;
  font-family: "Satoshi", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--soft);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--soft); font-weight: 500; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.suite-shell { min-height: 100vh; background: var(--soft); }
.suite-shell.authenticated { display: grid; grid-template-columns: 256px minmax(0, 1fr); }
.suite-main { min-width: 0; max-width: 100%; }
.suite-sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 18px; background: var(--dark); color: #fff; border-right: 1px solid #ffffff1f; display: flex; flex-direction: column; gap: 28px; }
.sidebar-brand { display: grid; gap: 8px; min-height: 54px; padding: 0 10px; }
.sidebar-brand img { display: block; width: 144px; height: auto; }
.sidebar-brand span { color: #f5f2ed9e; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.sidebar-nav { display: grid; gap: 8px; }
.sidebar-heading { margin: 0 11px 2px; color: #f5f2ed75; font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.sidebar-nav-link { width: 100%; min-height: 40px; border: 0; border-radius: 999px; padding: 9px 12px; background: transparent; color: #f5f2edc7; text-align: left; font-size: 14px; font-weight: 700; transition: background .15s, color .15s; }
.sidebar-nav-link:hover { background: #ffffff14; color: #fff; }
.sidebar-nav-link.active { background: var(--orange-soft); color: var(--orange-dark); }
.sidebar-nav-link:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
.sidebar-note { margin: auto 10px 0; padding-top: 16px; border-top: 1px solid #ffffff24; color: #f5f2ed8f; font-size: 12px; line-height: 1.5; }

.topbar { position: sticky; top: 0; z-index: 10; height: 64px; background: #121217f0; color: #fff; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 0 28px; border-bottom: 1px solid #ffffff1f; backdrop-filter: blur(14px); }
.brand { display: flex; align-items: center; gap: 18px; }
.brand img { display: block; width: 144px; height: auto; }
.suite-shell.authenticated .topbar .brand { display: none; }
.current-section { min-width: 0; flex: 1; color: #f5f2edb8; font-size: 13px; font-weight: 700; }
.suite-shell:not(.authenticated) .current-section { display: none; }
.account { display: flex; align-items: center; gap: 16px; min-height: 40px; }

.portal-content { width: min(1280px, calc(100% - 56px)); margin: 0 auto; padding: 34px 0 72px; }
.portal-content:has(#sign-in:not(.hidden)) { padding-bottom: 24px; }
.eyebrow { margin: 0 0 8px; color: var(--orange-dark); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, h3 { margin-top: 0; letter-spacing: -.025em; }
h1 { font-size: clamp(34px, 5vw, 48px); line-height: 1.05; margin-bottom: 12px; }
h2 { font-size: 28px; line-height: 1.15; }
h3 { font-size: 20px; line-height: 1.25; }
.muted { color: var(--slate); }

.sign-in { max-width: 620px; margin: 9vh auto 0; text-align: center; }
/* Clerk's mountSignIn() overwrites this element's className with its own
   (cl-rootBox etc.), so a class selector here would never match once Clerk
   mounts — target the id, which Clerk leaves alone, and center via margin
   since Clerk's own box is display:block, not a flex item. */
#sign-in-control { margin: 0 auto; }
/* Clerk's default 36px title wraps to two lines at its card's fixed 400px
   width for "Sign in to Carbitex AI" — right at the wrap threshold, so it
   rendered as one line or two seemingly at random depending on font timing.
   Pin it smaller so it's always one line. */
#sign-in-control .cl-headerTitle { font-size: 22px; }
.workspace-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 32px; }
.workspace-heading p { margin: 0; }
.actions, .admin-header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.button { border: 1px solid transparent; border-radius: 8px; padding: 11px 16px; font-weight: 800; line-height: 1.2; transition: background .15s, border-color .15s, transform .15s; }
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--orange); color: var(--ink); }
.button-primary:hover { background: var(--orange-dark); color: #fff; }
.button-secondary { background: var(--panel); border-color: var(--line); color: var(--ink); }
.button-secondary:hover { border-color: var(--orange); background: var(--orange-soft); }
.button-danger { background: var(--danger-soft); border-color: #e4cfd1; color: var(--danger); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 270px), 1fr)); gap: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 24px; box-shadow: 0 4px 12px -2px #15151514, 0 2px 4px -2px #1515150d; }
.app-card { min-height: 210px; display: flex; flex-direction: column; }
.app-card h2 { margin-bottom: 8px; }
.app-card .button { margin-top: auto; align-self: flex-start; }
.app-kicker { color: var(--orange-dark); font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; margin: 0 0 28px; }
.empty-state { grid-column: 1/-1; padding: 42px; text-align: center; border: 1px dashed var(--line); border-radius: 8px; background: #ffffff75; }
.empty-state h2 { font-size: 22px; margin-bottom: 8px; }
.empty-state p { margin: 0; }

.admin-panel { margin-top: 4px; }
.admin-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 32px; margin-bottom: 34px; }
.admin-header h1 { font-size: 42px; margin-bottom: 10px; }
.admin-header p { max-width: 650px; margin: 0; font-size: 16px; }
.admin-header-actions { align-items: center; padding-top: 21px; }
.admin-tabs { display: flex; gap: 30px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.admin-tab { display: flex; align-items: center; gap: 8px; position: relative; border: 0; background: transparent; color: var(--slate); padding: 0 1px 15px; font-weight: 800; }
.admin-tab::after { content: ""; position: absolute; height: 3px; left: 0; right: 0; bottom: -1px; background: transparent; border-radius: 3px 3px 0 0; }
.admin-tab.active { color: var(--ink); }
.admin-tab.active::after { background: var(--orange); }
.tab-count { display: inline-grid; place-items: center; min-width: 23px; height: 23px; padding: 0 7px; border-radius: 999px; background: #e9e6e0; color: var(--slate); font-size: 12px; }
.admin-tab.active .tab-count { background: var(--orange-soft); color: var(--orange-dark); }

.directory-panel { overflow: hidden; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px -18px #15151542; }
.directory-toolbar { min-height: 74px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.member-search { display: block; width: min(390px, 100%); }
.member-search input { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 8px; background: #fbfaf8; padding: 9px 13px; color: var(--ink); outline: none; }
.member-search input:focus { border-color: var(--orange); box-shadow: 0 0 0 3px #f7803026; background: #fff; }
.directory-summary { display: flex; gap: 20px; color: var(--slate); font-size: 13px; }
.directory-summary strong { color: var(--ink); }
.directory-columns, .member-summary { display: grid; grid-template-columns: minmax(260px, 1.25fr) minmax(150px, .6fr) minmax(210px, .8fr) 24px; align-items: center; column-gap: 24px; }
.directory-columns { min-height: 42px; padding: 0 22px; color: var(--muted); background: #fbfaf8; border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.member-directory { display: grid; }
.member-row { border-bottom: 1px solid var(--line); background: #fff; }
.member-row:last-child { border-bottom: 0; }
.member-summary { min-height: 88px; padding: 15px 22px; list-style: none; cursor: pointer; transition: background .15s; }
.member-summary::-webkit-details-marker { display: none; }
.member-summary:hover { background: #fbfaf8; }
.member-row[open] > .member-summary { background: var(--orange-soft); border-bottom: 1px solid #efdfce; }
.member-identity { display: flex; align-items: center; min-width: 0; gap: 13px; }
.member-initials { flex: 0 0 auto; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--dark); color: #fff; font-size: 12px; font-weight: 800; letter-spacing: .03em; }
.member-identity-copy { display: grid; min-width: 0; gap: 2px; }
.member-identity-copy strong, .member-identity-copy p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-identity-copy p { margin: 0; font-size: 13px; }
.badge { display: inline-flex; align-items: center; width: max-content; border-radius: 999px; padding: 5px 9px; background: var(--orange-soft); color: #a65f20; font-size: 12px; font-weight: 800; }
.organization-badge { background: #f1efeb; color: #4f5c68; }
.product-summary { color: var(--slate); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.disclosure { width: 9px; height: 9px; border-right: 2px solid var(--slate); border-bottom: 2px solid var(--slate); transform: rotate(45deg) translateY(-2px); justify-self: end; transition: transform .15s; }
.member-row[open] .disclosure { transform: rotate(225deg) translate(-2px, -2px); }
.member-details { display: grid; grid-template-columns: minmax(220px, .58fr) minmax(0, 1.42fr); background: #fbfaf8; }
.member-control-section { padding: 18px 20px; }
.organization-controls { border-right: 1px solid var(--line); }
.control-heading { display: grid; gap: 3px; margin-bottom: 12px; }
.control-heading strong { font-size: 15px; }
.control-heading span { color: var(--slate); font-size: 12px; line-height: 1.45; }
.member-actions { display: flex; align-items: stretch; gap: 7px; flex-wrap: wrap; }
.member-actions select, .membership-row select { min-height: 40px; border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; background: #fff; }
.member-actions .button, .membership-row .button { min-height: 40px; padding: 9px 12px; font-size: 12px; }
.member-actions .button-danger { flex-basis: 100%; width: max-content; margin-top: 4px; }
.product-controls { display: grid; gap: 0; }
.membership-row { display: grid; grid-template-columns: minmax(170px, 1fr) minmax(120px, auto) auto; align-items: end; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.membership-row:first-of-type { border-top: 0; padding-top: 0; }
.membership-row label { display: grid; gap: 5px; font-size: 12px; font-weight: 800; color: #3f4a55; }
.fixed-role { display: flex; align-items: center; min-height: 40px; width: max-content; border-radius: 999px; padding: 6px 11px; background: #f1efeb; color: #4f5c68; font-size: 12px; font-weight: 800; }
.role-help { grid-column: 1 / -1; color: var(--slate); font-size: 12px; line-height: 1.35; }
.action-warning { grid-column: 1 / -1; width: 100%; margin: 4px 0 0; border-left: 3px solid var(--orange); padding: 8px 10px; background: var(--orange-soft); color: #70441f; font-size: 12px; line-height: 1.45; }

.invitation-list { display: grid; }
.invitation-card { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 20px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.invitation-card:last-child { border-bottom: 0; }
.list-card-header { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.list-card-header p { margin: 4px 0 0; font-size: 13px; }
.empty-list { padding: 48px 24px; color: var(--slate); text-align: center; }

.invite-dialog { width: min(720px, calc(100% - 32px)); max-height: min(88vh, 780px); padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); box-shadow: 0 28px 70px -20px #0009; }
.invite-dialog::backdrop { background: #0d0d11a8; backdrop-filter: blur(2px); }
.dialog-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding: 26px 28px 20px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin-bottom: 7px; }
.dialog-header p { margin-bottom: 0; }
.dialog-close { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--slate); font-size: 24px; line-height: 1; }
.invite-dialog form { padding: 24px 28px 28px; }
.form-grid { display: grid; grid-template-columns: 1fr 210px; gap: 18px; }
.field { display: grid; gap: 7px; }
.field label, .field-label { font-size: 13px; font-weight: 800; color: #3f4a55; }
.field input, .field select, .role-fields select { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); padding: 9px 12px; outline: none; }
.field input:focus, .field select:focus, .role-fields select:focus { border-color: var(--orange); box-shadow: 0 0 0 3px #f7803026; }
.product-picker { border: 0; padding: 0; margin: 26px 0 0; }
.product-picker legend { padding: 0; margin-bottom: 4px; font-size: 16px; font-weight: 800; }
.form-help { margin: 0 0 14px; font-size: 14px; }
.product-options { display: grid; gap: 12px; }
.product-option { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: start; border: 1px solid var(--line); border-radius: 8px; padding: 16px; background: #fff; transition: border-color .15s, background .15s; }
.product-option:has(input:checked) { border-color: var(--orange); background: var(--orange-soft); }
.product-option > input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--orange); }
.product-copy { display: grid; gap: 3px; }
.product-copy strong { font-size: 16px; }
.product-copy small { color: var(--slate); font-size: 13px; }
.role-fields { grid-column: 2; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 10px; }
.role-fields label { display: grid; gap: 6px; font-size: 12px; font-weight: 800; color: #3f4a55; }
.role-fields .role-help { margin: 0; }
.automatic-role { grid-column: 2; margin-top: 8px; color: #4f5c68; font-size: 12px; font-weight: 700; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

#status { position: fixed; right: 24px; bottom: 24px; max-width: min(420px, calc(100% - 48px)); min-height: 0; margin: 0; padding: 0; z-index: 5; }
#status:not(:empty) { background: var(--dark); color: #fff; border-left: 4px solid var(--orange); border-radius: 7px; padding: 14px 18px; box-shadow: 0 12px 28px -6px #1515153d; }

@media (max-width: 900px) {
  .suite-shell.authenticated { display: block; }
  .suite-sidebar { display: none; }
  .suite-shell.authenticated .topbar .brand { display: flex; }
  .current-section { display: none; }
  .directory-columns, .member-summary { grid-template-columns: minmax(220px, 1fr) 150px 24px; }
  .directory-columns span:nth-child(3), .product-summary { display: none; }
  .member-details { grid-template-columns: 1fr; }
  .organization-controls { border-right: 0; border-bottom: 1px solid var(--line); }
}

@media (max-width: 680px) {
  .topbar { height: auto; min-height: 68px; padding: 14px 20px; }
  .brand img { width: 120px; }
  .suite-label { display: none; }
  .account { gap: 8px; }
  .portal-content { width: min(100% - 28px, 1280px); padding: 38px 0 56px; }
  .workspace-heading, .admin-header { align-items: flex-start; flex-direction: column; }
  .admin-header-actions { width: 100%; padding: 0; }
  .admin-header-actions .button { flex: 1; }
  .admin-tabs { gap: 18px; overflow-x: auto; }
  .admin-tab { white-space: nowrap; }
  .directory-toolbar { align-items: stretch; flex-direction: column; gap: 12px; }
  .member-search { width: 100%; }
  .directory-summary { justify-content: space-between; }
  .directory-columns { display: none; }
  .member-summary { grid-template-columns: 1fr 24px; gap: 14px; min-height: 82px; padding: 14px 16px; }
  .organization-badge { grid-row: 2; grid-column: 1; margin-left: 53px; }
  .disclosure { grid-column: 2; grid-row: 1 / span 2; }
  .member-control-section { padding: 20px 16px; }
  .member-actions, .membership-row { display: flex; align-items: stretch; flex-direction: column; }
  .member-actions > *, .membership-row > * { width: 100%; }
  .member-actions .button-danger { width: 100%; }
  .invitation-card { grid-template-columns: 1fr; }
  .list-card-header { align-items: flex-start; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .role-fields, .automatic-role { grid-column: 1; }
  .role-fields { grid-template-columns: 1fr; }
  .dialog-header, .invite-dialog form { padding-left: 20px; padding-right: 20px; }
  .dialog-actions .button { flex: 1; }
  .button { min-height: 44px; }
}
