:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-strong: #eef3f8;
    --line: #d7dee9;
    --text: #101827;
    --muted: #667085;
    --cyan: #0e9384;
    --green: #16803f;
    --amber: #f7c948;
    --pink: #d9468a;
    --danger: #d92d20;
    --lead: #465467;
    --body-secondary: #344054;
    --panel-bg: rgba(255, 255, 255, 0.94);
    --panel-border: rgba(16, 24, 40, 0.12);
    --metric-bg: rgba(255, 255, 255, 0.84);
    --input-bg: #ffffff;
    --button-bg: #ffffff;
    --primary-text: #061014;
    --danger-text: #b42318;
    --table-text: #243044;
    --code-text: #0b6b63;
    --code-bg: rgba(14, 147, 132, 0.08);
    --code-border: rgba(14, 147, 132, 0.22);
    --alert-error-text: #b42318;
    --alert-success-text: #027a48;
    --alert-warning-text: #8a5a00;
    --shadow: 0 24px 70px rgba(16, 24, 40, 0.12);
    --body-background:
        linear-gradient(120deg, rgba(14, 147, 132, 0.1), transparent 34%),
        linear-gradient(240deg, rgba(217, 70, 138, 0.08), transparent 36%),
        repeating-linear-gradient(90deg, rgba(16, 24, 40, 0.035) 0 1px, transparent 1px 96px),
        var(--bg);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #07080c;
    --surface: #10131a;
    --surface-strong: #171b24;
    --line: #2a3140;
    --text: #eef3ff;
    --muted: #9aa7ba;
    --cyan: #38d6cf;
    --green: #6ee787;
    --amber: #f7c948;
    --pink: #ff5c8a;
    --danger: #ff5b61;
    --lead: #cad4e6;
    --body-secondary: #cad4e6;
    --panel-bg: rgba(16, 19, 26, 0.9);
    --panel-border: rgba(255, 255, 255, 0.12);
    --metric-bg: rgba(16, 19, 26, 0.72);
    --input-bg: #090b11;
    --button-bg: #121722;
    --primary-text: #061014;
    --danger-text: #ffd6d8;
    --table-text: #dce5f4;
    --code-text: #bdf9f4;
    --code-bg: rgba(56, 214, 207, 0.1);
    --code-border: rgba(56, 214, 207, 0.2);
    --alert-error-text: #ffd9dc;
    --alert-success-text: #ddffe4;
    --alert-warning-text: #fff2bc;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
    --body-background:
        linear-gradient(120deg, rgba(56, 214, 207, 0.14), transparent 32%),
        linear-gradient(240deg, rgba(255, 92, 138, 0.12), transparent 36%),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 96px),
        var(--bg);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

body {
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
    background: var(--body-background);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea,
select {
    font: inherit;
}

.topbar {
    width: min(1180px, calc(100% - 32px));
    min-height: 72px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-logo {
    width: 104px;
    height: 36px;
    object-fit: contain;
    object-position: left center;
}

.brand strong,
.brand small {
    display: block;
    line-height: 1.05;
    overflow-wrap: anywhere;
}

.brand small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.76rem;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.nav-links a {
    color: var(--muted);
    font-size: 0.95rem;
}

.nav-links a:hover {
    color: var(--text);
}

.nav-links form {
    margin: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    min-width: 0;
}

.theme-toggle {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    border-color: var(--line);
    border-radius: 8px;
    background: var(--button-bg);
}

.theme-toggle svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.page {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 36px 0 64px;
}

.auth-page {
    min-height: calc(100vh - 72px);
    display: grid;
    align-items: center;
}

.center-page {
    min-height: calc(100vh - 72px);
    display: grid;
    place-items: center;
}

.auth-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 430px);
    gap: clamp(28px, 5vw, 76px);
    align-items: center;
}

.auth-copy {
    min-width: 0;
    padding-bottom: 28px;
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--cyan);
    font-size: 0.76rem;
    font-weight: 800;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
    line-height: 1.05;
    letter-spacing: 0;
}

h1 {
    font-size: clamp(2.1rem, 7vw, 5.2rem);
}

h2 {
    font-size: 1.45rem;
}

.lead {
    max-width: 680px;
    margin: 24px 0 0;
    color: var(--lead);
    font-size: clamp(1.05rem, 2vw, 1.28rem);
    line-height: 1.55;
}

.metric {
    min-width: 0;
    min-height: 92px;
    padding: 16px;
    border: 1px solid var(--line);
    background: var(--metric-bg);
    border-radius: 8px;
}

.metric span {
    display: block;
    color: var(--muted);
    font-size: 0.76rem;
    text-transform: uppercase;
}

.metric strong {
    display: block;
    margin-top: 10px;
    overflow-wrap: anywhere;
}

.panel {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: var(--panel-bg);
    box-shadow: var(--shadow);
}

.auth-form,
.narrow-form,
.enrollment {
    padding: clamp(22px, 4vw, 34px);
}

.narrow-form {
    max-width: 440px;
}

.enrollment {
    max-width: 760px;
}

.panel-heading {
    margin-bottom: 24px;
}

.panel-logo {
    display: block;
    width: min(168px, 100%);
    height: auto;
    margin-bottom: 18px;
}

.panel-heading .muted {
    margin: 12px 0 0;
    line-height: 1.45;
}

.panel-heading h1 {
    font-size: clamp(1.8rem, 5vw, 3rem);
}

label {
    display: grid;
    gap: 8px;
    margin-bottom: 18px;
    color: var(--muted);
    font-size: 0.9rem;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text);
    padding: 12px 14px;
    outline: none;
}

input,
select {
    min-height: 46px;
}

textarea {
    min-height: 92px;
    resize: vertical;
    line-height: 1.45;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px rgba(56, 214, 207, 0.16);
}

.password-field {
    position: relative;
}

.password-field input {
    padding-right: 48px;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.icon-button:hover {
    color: var(--text);
}

.icon-button:focus-visible {
    border-color: var(--cyan);
    outline: none;
    box-shadow: 0 0 0 3px rgba(56, 214, 207, 0.16);
}

.password-toggle {
    position: absolute;
    right: 7px;
    top: 50%;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    transform: translateY(-50%);
}

.password-toggle svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.code-input {
    font-size: 1.6rem;
    text-align: center;
    font-weight: 800;
}

.check-row {
    grid-template-columns: 20px minmax(0, 1fr);
    align-items: start;
    color: var(--body-secondary);
    line-height: 1.4;
}

.check-row input {
    width: 18px;
    min-height: 18px;
    margin-top: 2px;
    accent-color: var(--cyan);
}

.button {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--button-bg);
    color: var(--text);
    padding: 10px 16px;
    cursor: pointer;
    white-space: nowrap;
}

.button:hover {
    border-color: rgba(56, 214, 207, 0.65);
}

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

.button.primary {
    border-color: rgba(56, 214, 207, 0.65);
    background: linear-gradient(135deg, #2fd0c6, #7b6cff 58%, #ff5c8a);
    color: var(--primary-text);
    font-weight: 800;
}

.button.ghost {
    background: transparent;
}

.button.danger {
    border-color: rgba(255, 91, 97, 0.55);
    color: var(--danger-text);
}

.button.compact {
    min-height: 34px;
    padding: 7px 12px;
}

.button.wide {
    width: 100%;
}

.button-group {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.alert {
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: 8px;
    line-height: 1.4;
}

.alert.error {
    border: 1px solid rgba(255, 91, 97, 0.55);
    background: rgba(255, 91, 97, 0.1);
    color: var(--alert-error-text);
}

.alert.success {
    border: 1px solid rgba(110, 231, 135, 0.5);
    background: rgba(110, 231, 135, 0.1);
    color: var(--alert-success-text);
}

.alert.warning {
    border: 1px solid rgba(247, 201, 72, 0.55);
    background: rgba(247, 201, 72, 0.1);
    color: var(--alert-warning-text);
}

.helper-link {
    margin: 18px 0 0;
    color: var(--muted);
    text-align: center;
    font-size: 0.9rem;
}

.helper-link a {
    color: var(--cyan);
    font-weight: 700;
}

.authenticator-help {
    display: grid;
    gap: 18px;
    margin: 0 0 24px;
    padding: 18px 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.authenticator-help h2 {
    margin: 0;
    font-size: 1.05rem;
}

.authenticator-help .muted {
    margin: 6px 0 0;
    line-height: 1.45;
}

.download-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
}

.store-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.store-button {
    min-width: 168px;
    font-weight: 800;
}

.setup-steps ol {
    margin: 10px 0 0;
    padding-left: 22px;
    color: var(--body-secondary);
    line-height: 1.5;
}

.setup-steps li + li {
    margin-top: 6px;
}

.qr-wrap {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 20px;
    align-items: center;
    margin-bottom: 24px;
}

.qr-wrap img {
    width: 180px;
    height: 180px;
    padding: 10px;
    border-radius: 8px;
    background: #fff;
}

code {
    display: inline-block;
    max-width: 100%;
    overflow-wrap: anywhere;
    color: var(--code-text);
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: 6px;
    padding: 4px 6px;
}

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

.stack-form {
    margin: 0;
}

.inline-form {
    margin: 12px 0 0;
}

.settings-panel {
    padding: 22px;
}

.recovery-list {
    display: grid;
    gap: 14px;
    margin-bottom: 20px;
}

.recovery-list div {
    border-top: 1px solid var(--line);
    padding-top: 14px;
}

.recovery-list div:first-child {
    border-top: 0;
    padding-top: 0;
}

.recovery-list strong,
.recovery-list span {
    display: block;
}

.recovery-list span {
    margin-top: 5px;
    color: var(--muted);
    line-height: 1.45;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.secret-field {
    position: relative;
    display: block;
}

.secret-field input {
    padding-right: 174px;
}

.field-actions {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 6px;
}

.field-actions .button.compact {
    min-height: 32px;
    padding: 6px 10px;
    border-radius: 6px;
}

.field-note {
    color: var(--muted);
    line-height: 1.35;
}

.field-note.error {
    color: var(--alert-error-text);
}

.settings-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 2px 0 18px;
}

.settings-options .check-row {
    margin-bottom: 0;
}

.advanced-settings {
    margin: 4px 0 20px;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    padding: 14px 0;
}

.advanced-settings summary {
    cursor: pointer;
    color: var(--cyan);
    font-weight: 800;
    text-transform: uppercase;
    font-size: 0.78rem;
}

.advanced-settings label:first-of-type {
    margin-top: 18px;
}

.page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

.page-heading h1 {
    font-size: clamp(2rem, 5vw, 3.4rem);
}

.content-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.content-grid .panel,
.page > .panel {
    padding: 22px;
}

.table-list {
    display: grid;
    gap: 10px;
}

.table-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    padding: 14px 0;
    border-top: 1px solid var(--line);
}

.table-row:first-child {
    border-top: 0;
}

.table-row strong,
.table-row span {
    display: block;
    min-width: 0;
    overflow-wrap: anywhere;
}

.table-row span {
    margin-top: 5px;
    color: var(--muted);
    font-size: 0.86rem;
}

.sso-client-list {
    margin-bottom: 0;
}

.sso-client-row {
    align-items: start;
}

.row-actions {
    align-items: flex-start;
}

.row-actions form {
    margin: 0;
}

.form-actions {
    justify-content: flex-start;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.metric strong {
    color: var(--green);
    font-size: 2rem;
}

.data-table-wrap {
    width: 100%;
    overflow-x: auto;
}

.grid-shell {
    display: grid;
    gap: 14px;
}

.grid-toolbar {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) 132px;
    gap: 12px;
    align-items: end;
}

.grid-search,
.grid-page-size {
    margin-bottom: 0;
}

.grid-search span,
.grid-page-size span {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.grid-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.grid-count {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.grid-pagination {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 0.9rem;
}

.grid-pagination .button {
    width: auto;
}

.audit-event-cell {
    font-weight: 700;
    color: var(--text);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--muted);
    background: var(--surface-strong);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.status-pill.success {
    color: var(--alert-success-text);
    border-color: rgba(22, 128, 63, 0.32);
    background: rgba(22, 128, 63, 0.1);
}

.status-pill.failed {
    color: var(--alert-error-text);
    border-color: rgba(217, 45, 32, 0.32);
    background: rgba(217, 45, 32, 0.1);
}

.status-pill.running {
    color: var(--alert-warning-text);
    border-color: rgba(247, 201, 72, 0.42);
    background: rgba(247, 201, 72, 0.14);
}

table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
}

th,
td {
    padding: 12px 10px;
    border-top: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    color: var(--table-text);
    font-size: 0.92rem;
}

th {
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
}

td form {
    margin: 0;
}

.page > .panel + .panel {
    margin-top: 18px;
}

@media (max-width: 920px) {
    .auth-layout,
    .content-grid {
        grid-template-columns: 1fr;
    }

    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 620px) {
    .topbar,
    .page {
        width: min(100% - 20px, 1180px);
    }

    .topbar {
        align-items: flex-start;
        padding-top: 12px;
        flex-direction: column;
    }

    .nav-links {
        width: 100%;
        justify-content: flex-start;
    }

    .topbar-actions {
        width: 100%;
        align-items: flex-start;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .metric-grid,
    .qr-wrap,
    .page-heading,
    .grid-toolbar,
    .download-row {
        grid-template-columns: 1fr;
    }

    .store-buttons {
        justify-content: stretch;
    }

    .store-button {
        width: 100%;
        min-width: 0;
    }

    .qr-wrap img {
        justify-self: center;
    }

    .page-heading {
        display: grid;
    }

    .table-row {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .settings-grid,
    .settings-options {
        grid-template-columns: 1fr;
    }

    .secret-field {
        display: block;
    }

    .secret-field input {
        padding-right: 146px;
    }

    .field-actions {
        right: 5px;
        gap: 4px;
        display: flex;
    }

    .field-actions .button.compact {
        min-height: 30px;
        padding: 5px 8px;
        font-size: 0.82rem;
    }

    .button {
        width: 100%;
    }

    .theme-toggle {
        width: 40px;
    }

    .secret-field .button {
        width: auto;
    }

    .grid-pagination {
        width: 100%;
        justify-content: space-between;
    }

    .button-group {
        width: 100%;
    }
}
