:root {
    --portal-sidebar: 248px;
    --portal-topbar: 76px;
}

.portal-body { min-height: 100vh; margin: 0; background: #f6f8fb; color: var(--ink); }
.portal-body a { text-underline-offset: 3px; }
.portal-topbar { position: fixed; inset: 0 0 auto; z-index: 1000; height: var(--portal-topbar); display: flex; align-items: center; justify-content: space-between; padding: 0 28px; border-bottom: 1px solid var(--line-soft); background: #fff; }
.portal-logo { display: inline-flex; align-items: center; gap: 12px; color: var(--ink); font-weight: 700; text-decoration: none; }
.portal-logo img { width: 162px; height: 30px; }
.portal-logo span { padding-left: 12px; border-left: 1px solid var(--line); color: var(--primary); font-size: 0.86rem; }
.portal-user { display: grid; text-align: right; line-height: 1.25; }
.portal-user span { font-weight: 700; }
.portal-user small { color: var(--muted); }
.portal-menu-button { display: none; min-width: 48px; min-height: 44px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; font-weight: 700; cursor: pointer; }
.portal-sidebar { position: fixed; z-index: 900; inset: var(--portal-topbar) auto 0 0; width: var(--portal-sidebar); display: flex; flex-direction: column; justify-content: space-between; padding: 30px 18px 22px; border-right: 1px solid #1d2939; background: #101828; }
.portal-sidebar nav { display: grid; gap: 6px; }
.portal-sidebar nav a { min-height: 46px; display: flex; align-items: center; padding: 0 15px; border-radius: 9px; color: #b9c3d0; font-weight: 600; text-decoration: none; }
.portal-sidebar nav a:hover, .portal-sidebar nav a.active { color: #fff; background: #1d2939; }
.portal-sidebar nav a.active { box-shadow: inset 3px 0 #53b1fd; }
.portal-sidebar-foot { display: grid; gap: 5px; padding-top: 18px; border-top: 1px solid #344054; }
.portal-sidebar-foot a, .portal-sidebar-foot button { width: 100%; min-height: 40px; display: flex; align-items: center; padding: 0 14px; border: 0; color: #98a2b3; background: transparent; font-weight: 600; text-decoration: none; cursor: pointer; }
.portal-sidebar-foot a:hover, .portal-sidebar-foot button:hover { color: #fff; }
.portal-main { min-height: 100vh; margin-left: var(--portal-sidebar); padding: calc(var(--portal-topbar) + 46px) 42px 70px; }
.portal-main > * { width: min(1240px, 100%); margin-inline: auto; }
.portal-alert { margin-bottom: 22px; padding: 14px 17px; border: 1px solid; border-radius: var(--radius-sm); font-weight: 600; }
.portal-alert.success { border-color: #abefc6; color: #067647; background: #ecfdf3; }
.portal-alert.error { border-color: #fecdca; color: #b42318; background: #fef3f2; }

.portal-page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; margin-bottom: 32px; }
.portal-page-heading h1 { max-width: 800px; font-size: 2.5rem; }
.portal-page-heading > div > p:last-child:not(.portal-eyebrow) { max-width: 720px; margin-top: 10px; color: var(--muted); }
.portal-eyebrow { margin-bottom: 9px; color: var(--primary); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.portal-button { min-height: 46px; display: inline-flex; align-items: center; justify-content: center; padding: 0 18px; border: 1px solid transparent; border-radius: 9px; font-weight: 700; text-decoration: none; cursor: pointer; transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition); }
.portal-button:hover { transform: translateY(-1px); }
.portal-button.primary { color: #fff; background: var(--primary); }
.portal-button.primary:hover { color: #fff; background: var(--primary-dark); }
.portal-button.secondary { color: var(--ink); border-color: var(--line); background: #fff; }
.portal-button.secondary:hover { color: var(--primary); border-color: var(--primary); }

.portal-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.portal-metrics.two { grid-template-columns: repeat(2, minmax(220px, 1fr)); max-width: 720px; margin-inline: 0; }
.portal-metrics article { padding: 22px; border: 1px solid var(--line-soft); border-radius: 14px; background: #fff; box-shadow: var(--shadow-sm); }
.portal-metrics span { display: block; margin-bottom: 15px; color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.portal-metrics strong { font-family: 'Space Grotesk', sans-serif; font-size: 1.75rem; }
.portal-section, .portal-panel { padding: 26px; border: 1px solid var(--line-soft); border-radius: 16px; background: #fff; box-shadow: var(--shadow-sm); }
.portal-section-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.portal-section-head h2, .portal-panel > h2 { font-size: 1.25rem; }
.portal-section-head > span { color: var(--muted); font-size: 0.82rem; }
.portal-project-list { display: grid; }
.portal-project-list > a { display: flex; align-items: center; justify-content: space-between; gap: 26px; padding: 20px 4px; border-top: 1px solid var(--line-soft); color: var(--ink); text-decoration: none; }
.portal-project-list > a:hover h3 { color: var(--primary); }
.portal-project-list > a > div:first-child > span { color: var(--primary); font-size: 0.72rem; font-weight: 700; }
.portal-project-list h3 { margin: 3px 0; font-size: 1.05rem; }
.portal-project-list p { color: var(--muted); font-size: 0.84rem; }
.portal-project-progress { min-width: 310px; display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 12px; }
.portal-project-progress > progress, .portal-progress progress { width: 100%; height: 8px; border: 0; border-radius: 99px; overflow: hidden; background: #eaecf0; }
progress::-webkit-progress-bar { background: #eaecf0; border-radius: 99px; }
progress::-webkit-progress-value { background: var(--primary); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--primary); border-radius: 99px; }

.portal-status { width: fit-content; display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 999px; color: #344054; background: #f2f4f7; font-size: 0.7rem; font-weight: 700; white-space: nowrap; }
.status-active, .status-completed, .status-paid, .status-success, .status-owner { color: #067647; background: #ecfdf3; }
.status-awaiting_deposit, .status-pending, .status-submitted, .status-accrued { color: #b54708; background: #fffaeb; }
.status-approved, .status-review, .status-ready, .status-affiliate { color: #175cd3; background: #eff8ff; }
.status-on_hold, .status-cancelled, .status-reversed, .status-refunded, .status-suspended { color: #b42318; background: #fef3f2; }
.status-in_progress, .status-admin { color: #6941c6; background: #f4f3ff; }

.portal-empty { padding: 54px 22px; text-align: center; }
.portal-empty h2 { font-size: 1.25rem; }
.portal-empty p { max-width: 540px; margin: 10px auto 22px; color: var(--muted); }
.portal-filter { display: flex; justify-content: flex-end; margin-bottom: 18px; }
.portal-filter label { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.portal-filter select { min-height: 42px; padding: 0 36px 0 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.portal-table-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: 14px; background: #fff; }
.portal-table { width: 100%; min-width: 780px; border-collapse: collapse; }
.portal-table th { padding: 13px 18px; color: var(--muted); background: #f9fafb; font-size: 0.72rem; text-align: left; text-transform: uppercase; }
.portal-table td { padding: 16px 18px; border-top: 1px solid var(--line-soft); vertical-align: middle; }
.portal-table td > a { display: grid; color: var(--ink); text-decoration: none; }
.portal-table td > a:hover strong { color: var(--primary); }
.portal-table td span:not(.portal-status) { display: block; color: var(--muted); font-size: 0.78rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

.portal-editor-form { display: grid; gap: 22px; }
.portal-editor-form > section { padding: 30px; border: 1px solid var(--line-soft); border-radius: 16px; background: #fff; }
.portal-editor-form h2 { margin-bottom: 22px; font-size: 1.3rem; }
.portal-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.portal-form-grid .span-2 { grid-column: 1 / -1; }
.portal-form-card, .portal-compact-form, .portal-inline-form, .portal-ledger-action { display: grid; gap: 15px; }
.portal-form-card label, .portal-form-grid label, .portal-compact-form label { display: grid; gap: 7px; color: var(--ink-soft); font-size: 0.83rem; font-weight: 700; }
.portal-form-card small, .portal-form-grid small, .portal-compact-form small { color: var(--muted); font-weight: 500; }
.portal-form-card input, .portal-form-card select, .portal-form-card textarea,
.portal-form-grid input, .portal-form-grid select, .portal-form-grid textarea,
.portal-compact-form input, .portal-compact-form select, .portal-compact-form textarea,
.portal-inline-form input, .portal-inline-form select,
.portal-ledger-action input, .portal-ledger-action select { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.portal-form-card textarea, .portal-form-grid textarea, .portal-compact-form textarea { resize: vertical; }
.portal-form-note { margin-top: 18px; color: var(--muted); font-size: 0.84rem; }
.portal-checkbox { grid-template-columns: auto 1fr !important; align-items: center; }
.portal-checkbox input { width: 18px; min-height: 18px; }

.portal-project-summary { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 22px; }
.portal-project-summary article { min-height: 102px; display: flex; flex-direction: column; justify-content: space-between; padding: 18px; border: 1px solid var(--line-soft); border-radius: 12px; background: #fff; }
.portal-project-summary article > span:first-child { color: var(--muted); font-size: 0.74rem; font-weight: 600; }
.portal-project-summary strong { font-size: 1rem; }
.portal-project-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 0.8fr); align-items: start; gap: 22px; }
.portal-project-primary, .portal-project-aside { display: grid; gap: 22px; }
.portal-timeline { list-style: none; }
.portal-timeline > li { display: grid; grid-template-columns: 38px 1fr; gap: 16px; padding: 20px 0; border-top: 1px solid var(--line-soft); }
.portal-timeline-marker { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--primary); background: var(--surface-blue); font-size: 0.78rem; font-weight: 700; }
.portal-timeline-head { display: flex; justify-content: space-between; gap: 16px; }
.portal-timeline h3 { font-size: 1.02rem; }
.portal-timeline p { margin: 8px 0; color: var(--muted); font-size: 0.9rem; }
.portal-timeline small { color: var(--muted); }
.portal-progress { display: grid; grid-template-columns: 1fr 42px; align-items: center; gap: 12px; margin: 12px 0; }
.portal-inline-form { grid-template-columns: 1fr 90px auto; align-items: center; margin-top: 12px; }
.portal-inline-form button, .portal-ledger-action button { min-height: 42px; border: 0; border-radius: 8px; color: #fff; background: var(--ink); font-weight: 700; cursor: pointer; }
.portal-updates { display: grid; margin-top: 22px; }
.portal-updates article { padding: 20px 0; border-top: 1px solid var(--line-soft); }
.portal-updates article > div { display: flex; justify-content: space-between; gap: 20px; }
.portal-updates article span { color: var(--muted); font-size: 0.76rem; }
.portal-updates article p { margin-top: 9px; color: var(--ink-soft); }
.portal-updates article > small { display: block; margin-top: 8px; color: var(--primary); }
.portal-invoice { display: grid; gap: 14px; padding: 17px 0; border-top: 1px solid var(--line-soft); }
.portal-invoice > div { display: flex; justify-content: space-between; gap: 12px; }
.portal-invoice span:not(.portal-status) { display: block; color: var(--muted); font-size: 0.76rem; }
.portal-people { margin: 14px 0 20px; }
.portal-people > div { display: grid; grid-template-columns: 70px 1fr; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line-soft); }
.portal-people dt { color: var(--muted); font-size: 0.76rem; }
.portal-people dd { margin: 0; font-weight: 600; }
.portal-people small { display: block; margin-top: 2px; color: var(--muted); font-weight: 400; }
.admin-panel { border-color: #b2ddff; background: #f5faff; }
.admin-panel details { margin-top: 16px; border-top: 1px solid #b2ddff; }
.admin-panel summary { padding: 15px 0; font-weight: 700; cursor: pointer; }
.portal-muted { color: var(--muted); }
.portal-ledger-action { min-width: 190px; }
.simulator { max-width: 620px; }
.simulator dl > div { display: flex; justify-content: space-between; gap: 20px; padding: 13px 0; border-bottom: 1px solid var(--line-soft); }
.simulator dt { color: var(--muted); }
.simulator dd { margin: 0; font-weight: 700; text-align: right; }
.simulator form { margin-top: 22px; }

.portal-public { background: #fff; }
.portal-public-header { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 0 max(24px, calc((100vw - 1180px) / 2)); border-bottom: 1px solid var(--line-soft); background: #fff; }
.portal-public-header nav { display: flex; align-items: center; gap: 24px; }
.portal-public-header nav a { color: var(--ink-soft); font-weight: 600; text-decoration: none; }
.portal-public-header .portal-header-cta { min-height: 42px; display: inline-flex; align-items: center; padding: 0 16px; border-radius: 999px; color: #fff; background: var(--ink); }
.portal-public-main { width: min(1180px, calc(100% - 40px)); margin-inline: auto; }
.portal-landing-hero { min-height: 680px; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(330px, 0.65fr); align-items: center; gap: 90px; padding: 80px 0; }
.portal-landing-hero h1 { font-size: 4rem; }
.portal-landing-hero > div > p:not(.portal-eyebrow) { max-width: 720px; margin-top: 22px; color: var(--muted); font-size: 1.12rem; }
.portal-landing-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 30px; }
.portal-landing-hero aside { padding: 30px; border-radius: 20px; color: #fff; background: var(--ink); }
.portal-landing-hero aside > p { padding-bottom: 16px; border-bottom: 1px solid #344054; color: #84caff; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; }
.portal-landing-hero ol { list-style: none; }
.portal-landing-hero li { display: grid; grid-template-columns: 34px 1fr; gap: 12px; padding: 16px 0; border-bottom: 1px solid #344054; color: #d0d5dd; }
.portal-landing-hero li:last-child { border-bottom: 0; }
.portal-landing-hero li span { color: #5fe9d0; font-size: 0.75rem; font-weight: 700; }
.portal-landing-section { display: grid; grid-template-columns: 0.75fr 1.25fr; gap: 70px; padding: 90px 0; border-top: 1px solid var(--line-soft); }
.portal-landing-section h2 { font-size: 2.4rem; }
.portal-feature-grid { display: grid; gap: 14px; }
.portal-feature-grid article { padding: 22px 0; border-bottom: 1px solid var(--line-soft); }
.portal-feature-grid article:first-child { padding-top: 0; }
.portal-feature-grid strong { font-size: 1.05rem; }
.portal-feature-grid p { margin-top: 6px; color: var(--muted); }
.portal-auth { min-height: calc(100vh - 76px); display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(360px, 0.55fr); align-items: center; gap: 100px; padding: 70px 0; }
.portal-auth > div h1 { font-size: 3.4rem; }
.portal-auth > div > p:last-child { max-width: 570px; margin-top: 18px; color: var(--muted); font-size: 1.05rem; }
.portal-form-card { padding: 32px; border: 1px solid var(--line-soft); border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.portal-form-card > p { color: var(--muted); font-size: 0.84rem; text-align: center; }

@media (max-width: 1100px) {
    .portal-project-summary { grid-template-columns: repeat(3, 1fr); }
    .portal-project-layout { grid-template-columns: 1fr; }
    .portal-project-aside { grid-template-columns: repeat(2, 1fr); }
    .portal-project-aside .admin-panel { grid-column: 1 / -1; }
    .portal-metrics { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 820px) {
    .portal-topbar { padding: 0 15px; }
    .portal-menu-button { display: block; }
    .portal-topbar .portal-logo span { display: none; }
    .portal-user span { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .portal-sidebar { width: min(300px, 86vw); transform: translateX(-105%); transition: transform var(--transition); }
    .portal-sidebar.active { transform: translateX(0); box-shadow: 20px 0 50px rgba(16,24,40,.25); }
    .portal-main { margin-left: 0; padding: calc(var(--portal-topbar) + 30px) 20px 55px; }
    .portal-page-heading { align-items: flex-start; flex-direction: column; }
    .portal-page-heading h1 { font-size: 2.05rem; }
    .portal-project-progress { min-width: 240px; }
    .portal-public-header { padding: 18px 20px; }
    .portal-public-header nav a:first-child { display: none; }
    .portal-landing-hero, .portal-landing-section, .portal-auth { grid-template-columns: 1fr; gap: 45px; }
    .portal-landing-hero { padding: 70px 0; }
    .portal-landing-hero h1, .portal-auth > div h1 { font-size: 2.75rem; }
}

@media (max-width: 580px) {
    .portal-topbar .portal-logo img { width: 132px; height: auto; }
    .portal-user small { display: none; }
    .portal-metrics, .portal-metrics.two, .portal-project-summary, .portal-form-grid, .portal-project-aside { grid-template-columns: 1fr; }
    .portal-form-grid .span-2, .portal-project-aside .admin-panel { grid-column: auto; }
    .portal-project-list > a { align-items: flex-start; flex-direction: column; }
    .portal-project-progress { width: 100%; min-width: 0; }
    .portal-section, .portal-panel, .portal-editor-form > section { padding: 21px; }
    .portal-inline-form { grid-template-columns: 1fr; }
    .portal-updates article > div, .portal-timeline-head { align-items: flex-start; flex-direction: column; }
    .portal-public-header .portal-logo span, .portal-public-header nav > a:not(.portal-header-cta) { display: none; }
    .portal-public-header .portal-header-cta { font-size: 0.8rem; }
    .portal-public-main { width: min(100% - 30px, 1180px); }
    .portal-landing-hero h1, .portal-auth > div h1 { font-size: 2.25rem; }
    .portal-landing-actions, .portal-landing-actions .portal-button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .portal-sidebar, .portal-button { transition: none; }
}
