:root.portal-document {
  --portal-rail: #133d31;
  --portal-rail-ink: #f7fbf5;
  --portal-rail-muted: #c5d6cb;
  --portal-rail-active: #ffffff1c;
  --portal-highlight: #ccdf82;
  --library-surface: var(--portal-rail);
  --font-ui: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;
  --heading-weight: 800;
  --heading-tracking: -.04em;
  --subheading-tracking: -.025em;
  --radius-control: 9px;
  --radius-card: 15px;
  --radius-dialog: 17px;
  --radius-brand: 9px;
  --avatar-ink: var(--violet-dark);
  --delegated-line: var(--line);
  --delegated-text: var(--violet-dark);
  --list-hover: var(--hover);
  --search-line: var(--control-line);
  accent-color: var(--violet);
}

:root.portal-document:where(:not([data-color-mode="dark"])) {
  --text: #152c22;
  --muted: #53665b;
  --page: #f5f7f2;
  --surface: #fff;
  --surface-alt: #f0f4ee;
  --line: #dce5dc;
  --control-line: #becdc1;
  --violet: #16644c;
  --violet-dark: #104b38;
  --soft: #e7f1e9;
  --hover: #f0f5ee;
  --focus: #277854;
  --overlay: #0c2a20a3;
  --delegated-bg: #e9f2e7;
  --popover-shadow: 0 12px 28px #132f2422;
  --dialog-shadow: 0 22px 58px #0d281d36;
}

:root.portal-document[data-color-mode="dark"] {
  --portal-rail: #172c23;
  --portal-rail-ink: var(--text);
  --portal-rail-muted: var(--muted);
  --portal-rail-active: #294338;
  --library-surface: #1b382b;
  --auth-cover-shade: #0b2117d9;
  --auth-cover-fade: 48%;
}

.portal-document ::selection { background: var(--soft); color: var(--violet-dark); }
.portal-document input { caret-color: var(--violet); }
.portal-document input::placeholder { color: var(--muted); opacity: 1; }
.portal-document :is(.primary, .secondary, .row-link) { transition: background-color 150ms, color 150ms, border-color 150ms; }
.portal-document :is(.primary, .secondary):disabled { cursor: default; opacity: .55; }
.portal-document :is(.primary, .secondary):active:not(:disabled) { filter: brightness(.94); }

.portal .portal-frame {
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
  align-items: start;
  min-height: 100svh;
}

.portal-content { min-width: 0; }
.portal-content:focus { outline: none; }
.portal-skip { position: fixed; z-index: 10; top: 8px; left: 8px; transform: translateY(-160%); padding: 12px 16px; background: var(--surface); color: var(--text); border-radius: var(--radius-control); }
.portal-skip:focus { transform: translateY(0); }

.portal-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  z-index: 5;
  height: 100svh;
  padding: 26px 15px 18px;
  background: var(--portal-rail);
  color: var(--portal-rail-ink);
}

.portal-sidebar .brand-link { display: inline-flex; align-self: start; margin: 0 8px; border-radius: var(--radius-control); }
.portal-sidebar .brand { font-size: 1.125rem; gap: 9px; }
.portal-sidebar .brand-mark, .portal-sidebar .brand-mark i { background: var(--portal-highlight); color: #15392e; }
.portal-sidebar :focus-visible { outline-color: var(--portal-highlight); }
.portal-nav { display: grid; gap: 4px; margin-top: 44px; }
.portal-nav a, .portal-sidebar .appearance-trigger {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--portal-rail-muted);
  font-size: .875rem;
  font-weight: 650;
  text-align: left;
}
.portal-nav a .icon { order: -1; }
.portal-nav a:hover, .portal-sidebar .appearance-trigger:is(:hover, [aria-pressed="true"]), .portal-nav a[aria-current] { background: var(--portal-rail-active); color: var(--portal-rail-ink); }
.portal-nav a[aria-current] .icon, .portal-sidebar .appearance-trigger[aria-pressed="true"] .appearance-icon { color: var(--portal-highlight); }
.appearance-trigger { white-space: nowrap; }
.appearance-icon, .appearance-icon svg { display: block; flex: none; width: 16px; height: 16px; }
.portal-sidebar-tools { display: grid; gap: 8px; margin-top: auto; min-width: 0; }
.portal-sidebar .account { margin: 0; padding-top: 11px; border-top: 1px solid #ffffff28; }
.portal-sidebar .account summary { border-radius: 9px; min-height: 50px; padding: 7px; }
.portal-sidebar .account summary:hover, .portal-sidebar .account[open] summary { background: var(--portal-rail-active); }
.portal-sidebar .account summary .avatar { width: 34px; height: 34px; background: #dceadf; color: #15392e; }
.portal-sidebar .account summary strong { max-width: 106px; }
.portal-sidebar .account small { color: var(--portal-rail-muted); font-size: .75rem; }
.portal-sidebar .account .chevron { margin-left: auto; border-color: var(--portal-rail-muted); }
.portal-sidebar .account-menu { inset: auto 0 calc(100% - 5px) auto; min-width: 100%; margin: 0; }
.portal-sidebar .account-menu a[aria-current] { color: var(--violet-dark); font-weight: 700; }
.portal-sidebar .account-menu :focus-visible { outline-color: var(--focus); }
.portal-public .portal-sidebar { position: static; height: auto; padding: 16px max(20px, calc((100% - 1200px) / 2)); flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
.portal-public .portal-sidebar-tools { margin: 0; }

.portal-document .shell {
  width: min(1200px, calc(100% - 88px));
  margin: 50px auto 0;
  padding-bottom: 66px;
}
.portal-document .shell h1 { font-size: 2.375rem; line-height: 1.13; }
.portal-document .shell h2, .portal-document dialog h2 { font-size: 1.375rem; }
.portal-document .lead { margin-top: 9px; }
.portal .delegated-access > div { width: min(1200px, calc(100% - 88px)); }
.portal-page-heading { display: flex; align-items: end; justify-content: space-between; gap: 22px; margin-bottom: 29px; }
.portal-page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.portal-document .section-head { align-items: center; min-height: 44px; margin-bottom: 13px; }
.portal-document .section-head p { font-size: .875rem; }
.portal-document .section-actions { gap: 8px; }
.portal-document .search { width: min(256px, 100%); }
.portal-document .back { margin: 0 0 18px; }

.portal-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0 0 36px; border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface); overflow: hidden; }
.portal-summary > div { display: flex; align-items: baseline; flex-wrap: wrap; justify-content: space-between; column-gap: 12px; row-gap: 6px; min-width: 0; padding: 20px 24px; }
.portal-summary > div + div { border-left: 1px solid var(--line); }
.portal-summary > div:first-child { background: var(--soft); color: var(--violet-dark); }
.portal-summary dt { color: var(--muted); font-size: .875rem; font-weight: 650; }
.portal-summary dd { margin: 0; font-size: 1.75rem; line-height: 1; letter-spacing: -.035em; font-weight: 800; font-variant-numeric: tabular-nums; }

.portal .portal-table td, .portal .portal-table th { padding: 15px 19px; }
.portal .portal-table th { padding-block: 11px; font-size: .8125rem; }
.portal .portal-table td { font-size: .875rem; font-variant-numeric: tabular-nums; }
.portal .portal-table :is(td, th).end { width: 62px; }
.portal .portal-table .identity { min-width: 0; overflow-wrap: anywhere; }
.portal .portal-table .identity small { margin-top: 3px; }
.portal .portal-table tbody tr:hover { background: var(--hover); }
.portal .portal-table tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius-card); }
.portal .portal-table tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius-card); }
.portal .directory > .empty { padding: 38px 18px; border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface); }
.portal .user-menu { min-width: 224px; }

.library-intro {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, .77fr);
  align-items: center;
  min-height: 253px;
  padding: 34px 44px;
  border-radius: 18px;
  background: var(--library-surface);
  color: var(--portal-rail-ink);
}
.library-intro h1 { max-width: 16ch; text-wrap: balance; }
.library-lead { max-width: 39ch; margin-top: 11px; color: var(--portal-rail-muted); line-height: 1.6; }
.library-intro .primary { margin-top: 20px; background: var(--portal-highlight); color: #203a26; }
.library-intro .primary:hover { background: #ddeca6; }
.library-intro .primary:focus-visible { outline-color: var(--portal-highlight); }
.map-illustration { position: relative; justify-self: end; width: min(100%, 330px); height: 170px; }
.map-illustration::before { content: ''; position: absolute; inset: -45px -75px; z-index: -1; background: radial-gradient(circle, #cde9d443 1px, transparent 1.25px) 0 0 / 16px 16px; mask-image: radial-gradient(ellipse, #000 25%, transparent 72%); }
.idea-root, .idea-branch { position: absolute; z-index: 1; display: grid; place-items: center; height: 34px; border-radius: 6px; padding-inline: 10px; font-size: .75rem; font-weight: 750; white-space: nowrap; }
.idea-root { width: 38%; height: 46px; top: calc(50% - 23px); left: 0; background: #eaf0df; color: #254638; }
.idea-branch { width: 34%; left: 66%; color: #f7fbf5; border: 1px solid #96c7a6; background: #2b5945; }
.idea-top { top: 11px; }
.idea-middle { top: calc(50% - 17px); background: #dbeb9a; color: #254638; border: 0; }
.idea-bottom { bottom: 11px; }
.idea-wire { position: absolute; left: 38%; width: 28%; border: 1px solid #9bc3a499; border-right: 0; }
.wire-middle { top: 50%; border-width: 1px 0 0; }
.wire-top { top: 28px; height: 58px; border-bottom: 0; border-radius: 23px 0 0; }
.wire-bottom { bottom: 28px; height: 57px; border-top: 0; border-radius: 0 0 0 23px; }

.portal .map-library { width: 100%; margin: 32px 0 0; }
.portal .map-library h2 { margin: 0; }
.library-count { color: var(--muted); font-size: .875rem; white-space: nowrap; }
.portal .map-list { border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface); }
.portal .map-list li:first-child .map-row { border-start-start-radius: var(--radius-card); border-start-end-radius: var(--radius-card); }
.portal .map-list li:last-child .map-row { border-end-start-radius: var(--radius-card); border-end-end-radius: var(--radius-card); }
.portal .map-row { min-height: 77px; padding-inline: 18px; }
.portal .map-row > .icon { margin-left: 4px; }
.portal .maps-empty { background: var(--surface); padding: 40px 16px; }
.portal .map-icon .icon { transform: scale(1.12); }
.diagram-kinds { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.diagram-kind {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 6px 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-size: .875rem;
  font-weight: 650;
  cursor: pointer;
}
.diagram-kind:hover { background: var(--hover); }
.diagram-kind:has(:checked) { background: var(--soft); border-color: var(--line); }
.diagram-kind input { flex: none; margin: 0; accent-color: var(--violet-dark); }
.diagram-kind > span { display: flex; align-items: center; gap: 5px; }
.diagram-kind svg { flex: none; }
@media (max-width: 420px) {
  .diagram-kind > span :is(.icon, svg) { display: none; }
}

.account-settings { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); align-items: start; gap: 20px; max-width: 900px; }
.account-profile, .account-security { padding: 25px; border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface); }
.account-profile { display: flex; align-items: start; gap: 12px; }
.account-profile > div { min-width: 0; overflow-wrap: anywhere; }
.account-profile p, .account-security > p { margin-top: 6px; color: var(--muted); font-size: .875rem; line-height: 1.5; }
.account-profile small { display: block; margin-top: 13px; color: var(--muted); font-weight: 650; }
.account-security h2 { margin-bottom: 16px; }
.account-security .primary { justify-self: start; }
.portal-error .secondary { margin-top: 20px; }

.auth-page { background: var(--surface); }
.auth-layout {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, min(48%, 760px)) minmax(0, 1fr);
  gap: 24px;
  padding: 18px;
}
.auth-cover {
  position: relative;
  display: flex;
  align-items: end;
  min-height: 560px;
  overflow: hidden;
  border-radius: 16px;
  color: #f5f9ef;
  background: linear-gradient(0deg, var(--auth-cover-shade, #112e21db), #112e2100 var(--auth-cover-fade, 42%)), url('/login-cover.webp') center 34% / cover no-repeat, #173b2a;
}
.auth-cover-copy { padding: 36px 40px; }
.auth-cover-copy p { max-width: 15ch; font-size: 2.625rem; line-height: 1.08; font-weight: 800; letter-spacing: -.04em; text-wrap: balance; }
.auth-main { display: grid; grid-template-rows: auto 1fr; align-items: center; min-width: 0; padding: 12px 20px 55px 4px; }
.auth-header { display: flex; justify-content: space-between; align-items: center; min-width: 0; gap: 12px; }
.auth-header .brand { letter-spacing: -.035em; }
.auth-header .appearance-trigger { display: inline-flex; align-items: center; gap: 7px; min-height: 36px; border: 1px solid var(--control-line); border-radius: var(--radius-control); padding: 0 10px; background: var(--surface); color: var(--muted); font-size: .8125rem; font-weight: 700; }
.auth-header .appearance-trigger:hover { background: var(--hover); color: var(--violet-dark); }
.auth-header .appearance-trigger[aria-pressed="true"] { background: var(--soft); color: var(--violet-dark); }
.auth-content { width: min(100%, 388px); justify-self: center; padding: 32px 0; }
.auth-content h1 { font-size: 2.375rem; line-height: 1.12; }
.auth-content > .lead { margin-bottom: 27px; }
.auth-form { gap: 15px; }
.auth-form .field { gap: 7px; }
.auth-form .field input, .auth-password input { min-height: 48px; }
.auth-password { position: relative; margin-top: -8px; }
.auth-password input { width: 100%; border: 1px solid var(--control-line); border-radius: var(--radius-compact); padding: 8px 48px 8px 10px; background: var(--surface); color: var(--text); }
.password-toggle { position: absolute; inset: 4px 4px 4px auto; width: 40px; display: grid; place-items: center; border: 0; border-radius: 6px; background: transparent; color: var(--muted); }
.password-toggle[hidden], .auth-password input[type="password"] ~ button .eye-slash { display: none; }
.password-toggle:hover { background: var(--hover); color: var(--violet-dark); }
.auth-form .primary { min-height: 48px; margin-top: 5px; }
.account-choices { display: grid; gap: 8px; }
.account-choice { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--surface); color: var(--text); text-align: start; overflow-wrap: anywhere; }
.account-choice:hover { background: var(--hover); border-color: var(--control-line); }
.account-choice small { display: block; margin-top: 3px; color: var(--muted); }
.auth-return { display: inline-block; margin-top: 18px; color: var(--violet-dark); font-size: .875rem; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

@media (max-width: 1080px) {
  .portal-document .shell, .portal .delegated-access > div { width: calc(100% - 56px); }
  .library-intro { padding-inline: 30px; }
  .portal-summary > div { padding-inline: 16px; }
}

@media (max-width: 850px) {
  .portal .portal-frame { display: block; }
  .portal-sidebar {
    position: relative;
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px 12px;
    padding: 10px 16px 7px;
  }
  .portal-sidebar .brand-link { margin: 0; align-self: center; }
  .portal-nav { grid-row: 2; grid-column: 1 / -1; display: flex; flex-wrap: wrap; margin: 0; }
  .portal-nav a { min-height: 40px; padding: 0 9px; gap: 7px; }
  .portal-sidebar-tools { display: flex; align-items: center; gap: 6px; margin: 0; }
  .portal-sidebar .appearance-trigger { min-height: 40px; gap: 5px; padding: 0 7px; }
  .portal-sidebar .account { border: 0; padding: 0; }
  .portal-sidebar .account summary { min-height: 40px; padding: 3px; }
  .portal-sidebar .account-menu { inset: calc(100% + 4px) 0 auto auto; min-width: 176px; }
  .portal-sidebar .account summary > span:nth-child(2), .portal-sidebar .account .chevron { display: none; }
  .portal-document .shell { margin-top: 32px; }
  .auth-cover-copy { padding: 24px; }
  .auth-cover-copy p { font-size: 2.125rem; }
  .auth-main { padding-right: 6px; }
}

@media (max-width: 650px) {
  .portal-document .shell, .portal .delegated-access > div { width: calc(100% - 32px); }
  .portal-document .shell { padding-bottom: 42px; }
  .portal-document .shell h1, .auth-content h1 { font-size: 1.875rem; }
  .portal-page-heading { align-items: start; flex-direction: column; gap: 14px; margin-bottom: 23px; }
  .portal-summary { margin-bottom: 25px; }
  .portal-summary > div { flex-direction: column-reverse; align-items: start; padding: 13px 9px; }
  .portal-summary dt { font-size: .6875rem; overflow-wrap: anywhere; }
  .portal-summary dd { font-size: 1.5rem; }
  .portal-document .section-head { flex-direction: row; flex-wrap: wrap; }
  .portal-document .section-actions { width: 100%; justify-content: start; }
  .portal-document .section-actions .search { width: auto; max-width: 256px; }
  .portal .table-wrap { overflow: visible; }
  .portal .table-wrap:has(.user-actions[open]) { padding-bottom: 0; }
  .portal .portal-table, .portal .portal-table tbody { display: block; min-width: 0; }
  .portal .portal-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .portal .portal-table tbody tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 9px 5px; padding: 12px; }
  .portal .portal-table tbody tr + tr { border-top: 1px solid var(--line); }
  .portal .portal-table td { width: auto; padding: 0; border: 0; }
  .portal .portal-table td:first-child { grid-column: 1 / -2; }
  .portal .portal-table td.end { grid-column: -2; grid-row: 1; align-self: center; width: auto; }
  .portal .portal-table td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 3px; color: var(--muted); font-weight: 650; font-size: .6875rem; }
  .portal .portal-table tbody tr:hover { background: var(--surface); }
  .portal .workspace-directory .portal-table tbody tr { grid-template-columns: repeat(2, minmax(0, 1fr)) auto; }
  .library-intro { grid-template-columns: 1fr; min-height: 0; gap: 20px; padding: 24px; }
  .library-intro .map-illustration { justify-self: start; width: min(100%, 285px); height: 128px; }
  .map-illustration .idea-wire:is(.wire-top, .wire-bottom) { height: 37px; }
  .portal .map-library { margin-top: 25px; }
  .portal .map-row { padding-inline: 12px; }
  .account-settings { grid-template-columns: 1fr; gap: 12px; }

  .auth-layout { grid-template-columns: 1fr; gap: 0; padding: 0; align-content: start; }
  .auth-main { grid-row: 1; padding: 18px 20px 23px; }
  .auth-content { padding: 40px 0 16px; }
  .auth-content > .lead { margin-bottom: 20px; }
  .auth-cover { min-height: 280px; margin: 0 12px 12px; background-position: center 37%; }
  .auth-cover-copy { padding: 16px; }
  .auth-cover-copy p { font-size: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  .portal-document :is(.primary, .secondary, .row-link) { transition: none; }
}
