html {
    background: #283651;
    min-height: 100%;
    height: auto;
    width: 100%;
}

.client-portal {
    color: #1f2328;
    line-height: 1.6;
    padding: 32px 24px 64px;
}

.client-portal div,
.client-portal section,
.client-portal span,
.client-portal p,
.client-portal td,
.client-portal th,
.client-portal dd,
.client-portal dt {
    user-select: text;
}

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

/* Header */
.portal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
    color: #fff;
}

.portal-brand {
    color: #fff;
    font-size: 20px;
    font-weight: 600;
    flex-shrink: 0;
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.portal-brand span {
    font-size: 13px;
    font-weight: 400;
    color: #b9c8dc;
}

.portal-header nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 20px;
}

.portal-header nav a {
    color: #e2e8f0;
    font-size: 14px;
    transition: color 0.15s ease;
}

.portal-header nav a:hover {
    color: #fff;
}

.portal-user {
    color: #9fb3c8;
    font-size: 13px;
    padding-left: 16px;
    border-left: 1px solid rgba(255, 255, 255, 0.18);
}

/* Main Panel */
.portal-panel {
    background: #fff;
    padding: 32px 36px;
    border-radius: 12px;
    box-shadow: none;
}

/* Headings */
.page-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
}

h1 {
    font-size: 22px;
    line-height: 1.4;
    font-weight: 600;
    color: #111827;
    overflow-wrap: anywhere;
}

h2 {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 12px;
}

h3,
strong {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
}

.page-heading p {
    color: #6b7280;
    font-size: 14px;
    margin-top: 4px;
}

/* Buttons - Flat & Clean */
.kn-btn {
    height: 38px;
    padding: 0 18px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    background-color: #3e9cfc;
    box-shadow: none;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background-color 0.15s ease;
}

.kn-btn:hover {
    background-color: #2b8df2;
    box-shadow: none;
}

.kn-btn:disabled {
    background-color: #9ca3af;
    box-shadow: none;
}

.secondary-button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 0 16px;
    height: 38px;
    min-height: 38px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    color: #374151;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.secondary-button:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.secondary-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.danger-text {
    color: #dc2626;
    border-color: #fca5a5;
}

.danger-text:hover {
    background: #fef2f2;
    border-color: #ef4444;
}

/* Inputs & Filters */
.kn-input {
    display: block;
    width: 100%;
    height: 36px;
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    color: #111827;
    font-size: 14px;
    transition: border-color 0.15s ease;
}

.kn-input::placeholder {
    color: #9ca3af;
}

.kn-input:focus {
    border-color: #2563eb;
}

.portal-filters {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin: 0 0 20px;
}

.portal-filters input[type=text],
.portal-filters input:not([type]) {
    width: 260px;
}

.portal-filters select {
    width: 140px;
}

.check-label {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    white-space: nowrap;
    cursor: pointer;
    color: #374151;
}

input[type=checkbox] {
    width: 15px;
    height: 15px;
    accent-color: #2563eb;
    flex-shrink: 0;
    cursor: pointer;
}

/* Table */
.table-scroller {
    width: 100%;
    overflow-x: auto;
}

.portal-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.portal-table th {
    color: #6b7280;
    font-size: 13px;
    font-weight: 500;
    background: #f9fafb;
    white-space: nowrap;
    border-top: 1px solid #e5e7eb;
    border-bottom: 1px solid #e5e7eb;
    padding: 11px 14px;
}

.portal-table td {
    padding: 14px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: top;
    min-width: 100px;
    color: #1f2937;
}

.portal-table tbody tr:hover {
    background-color: #fafafa;
}

.portal-table td:first-child {
    min-width: 220px;
    max-width: 420px;
    overflow-wrap: anywhere;
}

.app-link {
    font-weight: 500;
    color: #111827;
}

.app-link:hover,
.back-link:hover,
.row-actions a:hover,
.pagination a:hover {
    color: #2563eb;
}

.back-link {
    display: inline-block;
    margin-bottom: 18px;
    color: #6b7280;
    font-size: 13px;
}

.row-actions {
    white-space: nowrap;
}

.row-actions a {
    color: #2563eb;
}

.row-actions a + a {
    margin-left: 14px;
}

.secondary-line {
    display: block;
    color: #6b7280;
    font-size: 12px;
    margin-top: 3px;
}

.muted,
.field-help {
    color: #6b7280;
    font-size: 13px;
}

.field-help {
    margin: 6px 0 0;
}

/* Status Badges */
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    color: #4b5563;
    background: #f3f4f6;
}

.status-normal {
    background: #ecfdf5;
    color: #047857;
}

.status-need_approve,
.pending-label {
    color: #b45309;
}

.status-need_approve {
    background: #fffbeb;
}

.pending-label {
    font-weight: 500;
}

.status-rejected {
    background: #fef2f2;
    color: #b91c1c;
}

/* Pagination & Empty State */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    color: #6b7280;
    font-size: 13px;
    padding-top: 18px;
}

.pagination a {
    color: #374151;
}

.pagination a + a {
    margin-left: 16px;
}

.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: #6b7280;
}

.empty-state h2 {
    color: #374151;
    margin-bottom: 6px;
}

/* Notices & Errors */
.notice {
    padding: 10px 14px;
    margin-bottom: 20px;
    border-radius: 6px;
    border: 1px solid #dbeafe;
    background: #eff6ff;
    color: #1e40af;
}

.form-error {
    padding: 10px 14px;
    border-radius: 6px;
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #b91c1c;
    margin-bottom: 20px;
    overflow-wrap: anywhere;
}

/* Forms */
.form-panel {
    max-width: 720px;
    margin: 0 auto;
}

.portal-fields label:not(.check-label) {
    display: block;
    font-weight: 500;
    color: #374151;
    margin: 18px 0 6px;
}

.portal-fields label:first-of-type {
    margin-top: 0;
}

textarea.kn-input {
    height: auto;
    min-height: 104px;
    padding: 8px 12px;
    resize: vertical;
    line-height: 1.6;
}

.redirect-editor [hidden] {
    display: none;
}

.redirect-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.redirect-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.redirect-row .kn-input {
    flex: 1;
    min-width: 0;
}

.redirect-remove {
    width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    flex-shrink: 0;
    font-size: 18px;
    color: #6b7280;
}

.redirect-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
}

.redirect-controls .field-help {
    margin: 0;
}

.redirect-add {
    color: #2563eb;
}

.form-actions,
.detail-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 24px;
}

.detail-actions {
    margin: 0 0 24px;
}

.portal-fields textarea.kn-input {
    margin-bottom: 0;
}

/* Admin Form & Grants */
.admin-base-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 36px;
}

.pkce-label {
    margin: 20px 0 12px;
    white-space: normal;
}

.login-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.owner-picker {
    position: relative;
}

.owner-options {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 10;
    max-height: 224px;
    overflow-y: auto;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    padding: 4px;
}

.owner-options[hidden] {
    display: none;
}

.owner-option {
    display: block;
    width: 100%;
    padding: 8px 10px;
    text-align: left;
    border-radius: 4px;
    background: transparent;
    color: #374151;
    cursor: pointer;
    overflow-wrap: anywhere;
}

.owner-option:hover,
.owner-option[aria-selected='true'] {
    background: #eff6ff;
    color: #2563eb;
}

.owner-message {
    padding: 8px 10px;
    color: #6b7280;
}

.grant-section,
.detail-section,
.reject-form {
    border-top: 1px solid #e5e7eb;
    padding-top: 24px;
    margin-top: 24px;
}

.grant-group {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    margin-top: 12px;
}

.grant-group summary {
    padding: 12px 16px;
    cursor: pointer;
    list-style: none;
    background: #f9fafb;
    border-radius: 6px;
}

.grant-group[open] summary {
    border-bottom: 1px solid #e5e7eb;
    border-radius: 6px 6px 0 0;
}

.grant-group summary::-webkit-details-marker {
    display: none;
}

.grant-group summary .check-label {
    width: 100%;
}

.grant-group summary .muted {
    margin-left: auto;
}

.scope-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px 18px;
    padding: 16px;
}

.scope-option {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    cursor: pointer;
    line-height: 1.45;
}

.scope-option input {
    margin-top: 3px;
}

.scope-option code {
    display: block;
    color: #6b7280;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.reject-form textarea {
    margin: 8px 0 12px;
}

/* Detail Lists & Credentials */
.detail-list {
    display: grid;
    grid-template-columns: 130px minmax(0, 1fr);
    gap: 12px 20px;
}

.detail-list dt {
    color: #6b7280;
}

.detail-list dd,
.uri,
pre,
code {
    user-select: text;
    overflow-wrap: anywhere;
}

.uri,
code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 13px;
}

.uri + .uri {
    margin-top: 4px;
}

.multiline,
pre {
    white-space: pre-wrap;
}

.credential-box {
    padding: 14px 16px;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    margin-top: 20px;
    border-radius: 6px;
}

.credential-box summary {
    cursor: pointer;
    color: #374151;
    font-weight: 500;
}

.credential-box code {
    display: block;
    margin: 10px 0;
    padding: 8px 10px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
}

.grant-summary {
    margin-top: 14px;
}

.scope-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.scope-tags span {
    padding: 2px 8px;
    background: #f3f4f6;
    color: #374151;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
    user-select: text;
}

/* Home & Error Panels */
.error-panel {
    max-width: 560px;
    margin: 72px auto;
}

.error-panel h1 {
    margin-bottom: 16px;
}

.home-panel {
    max-width: 600px;
    margin: 72px auto;
}

.home-panel p {
    color: #6b7280;
    margin: 12px 0 24px;
}

:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

@media (max-width: 720px) {
    .client-portal {
        padding: 20px 12px 36px;
    }

    .portal-header {
        display: block;
    }

    .portal-header nav {
        justify-content: flex-start;
        gap: 12px 16px;
        margin-top: 12px;
    }

    .portal-user {
        padding-left: 0;
        border-left: none;
    }

    .portal-panel {
        padding: 24px 18px;
    }

    .page-heading {
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 14px;
    }

    h1 {
        font-size: 20px;
    }

    .portal-filters input:not([type]),
    .portal-filters input[type=text] {
        width: 100%;
    }

    .portal-filters select {
        flex: 1;
    }

    .admin-base-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .scope-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }

    .grant-group summary .muted {
        display: none;
    }

    .detail-list {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .detail-list dd {
        margin-bottom: 10px;
    }
}

@media (max-width: 400px) {
    .scope-list {
        grid-template-columns: 1fr;
    }
}
