:root {
    color-scheme: light;
    --bg: #f7f9f8;
    --surface: #ffffff;
    --surface-2: #eef5f3;
    --text: #12201d;
    --muted: #5c6d68;
    --line: #d7e2de;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --accent: #2563eb;
    --warning: #b45309;
    --shadow: 0 14px 36px rgba(18, 32, 29, 0.10);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

body.portal-body {
    min-height: 100vh;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    letter-spacing: 0;
}

a {
    color: var(--primary-dark);
}

.portal-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 60px;
    padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
    background: rgba(255, 255, 255, 0.95);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.portal-brand,
.portal-header-link,
.portal-card-link,
.portal-nav-item,
.portal-button {
    text-decoration: none;
}

.portal-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    color: var(--text);
    font-weight: 800;
}

.portal-brand-mark {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
}

.portal-header-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 12px;
    color: var(--primary-dark);
    font-weight: 700;
}

.portal-shell {
    width: 100%;
    padding: 18px 16px 104px;
}

.portal-main {
    width: min(100%, 760px);
    margin: 0 auto;
}

.portal-stack,
.portal-form,
.portal-detail {
    display: grid;
    gap: 18px;
}

.portal-hero {
    display: grid;
    gap: 14px;
    padding: 26px 0 18px;
}

.portal-hero h1,
.portal-stack h1,
.portal-section-heading h1,
.portal-detail-header h1 {
    margin: 0;
    font-size: 2rem;
    line-height: 1.08;
}

.portal-hero p,
.portal-stack p,
.portal-panel p,
.portal-empty-card p,
.portal-request-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.45;
}

.portal-kicker {
    margin: 0 0 4px;
    color: var(--warning);
    font-size: 0.9rem;
    font-weight: 800;
    text-transform: uppercase;
}

.portal-muted {
    color: var(--muted);
}

.portal-actions,
.portal-inline-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.portal-link-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 12px;
    min-height: 44px;
}

.portal-link-row a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    font-weight: 800;
}

.portal-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 18px;
    border: 0;
    border-radius: 8px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.portal-button.primary {
    background: var(--primary);
    color: #fff;
}

.portal-button.secondary {
    background: var(--surface-2);
    color: var(--primary-dark);
    border: 1px solid var(--line);
}

.portal-button.compact {
    min-width: 56px;
    min-height: 44px;
    background: var(--primary);
    color: #fff;
}

.portal-button.full {
    width: 100%;
}

.portal-button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

.portal-panel,
.portal-empty-card,
.portal-request-card,
.portal-object-card,
.portal-upload-stub,
.portal-alert {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.portal-panel,
.portal-empty-card {
    display: grid;
    gap: 10px;
    padding: 18px;
}

.portal-panel h2,
.portal-empty-card h2,
.portal-empty-card h3,
.portal-request-card h2,
.portal-request-card h3 {
    margin: 0;
    font-size: 1.1rem;
}

.portal-section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 8px 0 14px;
}

.portal-section-heading h2 {
    margin: 0;
    font-size: 1.25rem;
}

.portal-card-list {
    display: grid;
    gap: 12px;
}

.portal-card-link {
    color: inherit;
}

.portal-request-card {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    min-height: 104px;
    padding: 16px;
    box-shadow: 0 2px 0 rgba(18, 32, 29, 0.03);
}

.portal-object-card {
    display: grid;
    gap: 14px;
    min-height: 132px;
    padding: 16px;
    box-shadow: 0 2px 0 rgba(18, 32, 29, 0.03);
}

.portal-object-card h3 {
    margin: 0 0 6px;
}

.portal-object-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.4;
}

.portal-card-actions {
    display: grid;
    gap: 10px;
}

.portal-request-card time,
.portal-detail-header time,
.portal-message time {
    color: var(--muted);
    font-size: 0.9rem;
}

.portal-status {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    margin-bottom: 8px;
    padding: 0 10px;
    border-radius: 999px;
    background: #dbeafe;
    color: #1e40af;
    font-size: 0.85rem;
    font-weight: 800;
}

.portal-form {
    padding-bottom: 18px;
}

.portal-field {
    display: grid;
    gap: 8px;
}

.portal-field span,
.portal-choice-group legend {
    color: var(--text);
    font-weight: 800;
}

.portal-field input,
.portal-field textarea,
.portal-field select {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.portal-field textarea {
    resize: vertical;
}

.portal-choice-group {
    display: grid;
    gap: 10px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.portal-choice-card {
    display: grid;
    grid-template-columns: 28px 1fr;
    align-items: start;
    gap: 12px;
    min-height: 72px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
}

.portal-choice-card:has(input:checked) {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.portal-choice-card input {
    width: 22px;
    height: 22px;
    margin-top: 2px;
    accent-color: var(--primary);
}

.portal-choice-card span {
    display: grid;
    gap: 4px;
}

.portal-choice-card small {
    color: var(--muted);
    line-height: 1.35;
}

.portal-form-step {
    display: grid;
    gap: 14px;
}

.portal-upload-stub {
    display: grid;
    gap: 4px;
    padding: 16px;
    color: var(--muted);
}

.portal-upload-stub strong {
    color: var(--text);
}

.portal-alert,
.portal-validation {
    padding: 14px 16px;
    color: #7c2d12;
    background: #ffedd5;
    border-color: #fed7aa;
    border-radius: 8px;
}

.portal-detail-header {
    display: grid;
    gap: 8px;
}

.portal-message {
    display: grid;
    gap: 6px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.portal-message:first-of-type {
    border-top: 0;
}

.portal-definition-list {
    display: grid;
    gap: 10px;
    margin: 0;
}

.portal-definition-list div,
.portal-diagnostic-row {
    display: grid;
    gap: 4px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.portal-definition-list div:first-child,
.portal-diagnostic-row:first-child {
    border-top: 0;
}

.portal-definition-list dt {
    color: var(--muted);
    font-weight: 700;
}

.portal-definition-list dd {
    margin: 0;
    font-weight: 800;
}

.portal-diagnostic-list {
    display: grid;
}

.portal-diagnostic-row span {
    color: var(--muted);
}

.portal-bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-height: 72px;
    padding: 6px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 30px rgba(18, 32, 29, 0.08);
}

.portal-nav-item {
    display: grid;
    place-items: center;
    gap: 2px;
    min-height: 58px;
    padding: 4px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 800;
    text-align: center;
}

.portal-nav-item.is-active {
    background: var(--surface-2);
    color: var(--primary-dark);
}

.portal-nav-icon {
    font-size: 1.25rem;
    line-height: 1;
}

[data-master-key-section][hidden] {
    display: none;
}

@media (min-width: 680px) {
    .portal-shell {
        padding-top: 28px;
    }

    .portal-hero h1,
    .portal-stack h1,
    .portal-section-heading h1,
    .portal-detail-header h1 {
        font-size: 2.4rem;
    }

    .portal-bottom-nav {
        right: 50%;
        left: 50%;
        width: min(760px, calc(100% - 32px));
        transform: translateX(-50%);
        bottom: 16px;
        border: 1px solid var(--line);
        border-radius: 12px;
        box-shadow: var(--shadow);
    }
}
