:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-soft: #eef2f5;
    --text: #20242a;
    --muted: #657282;
    --line: #d8e0e8;
    --primary: #c92f3b;
    --primary-dark: #a92531;
    --green: #26834f;
    --warning-bg: #fff4d8;
    --warning-text: #775400;
    --danger-bg: #ffe6e6;
    --danger-text: #9a1e1e;
    --shadow: 0 10px 28px rgba(32, 36, 42, 0.08);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: "Segoe UI", Arial, sans-serif;
}

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

button,
a {
    min-height: 38px;
    border: 0;
    border-radius: 7px;
    padding: 8px 12px;
    color: #ffffff;
    background: var(--primary);
    cursor: pointer;
    font-weight: 800;
    text-decoration: none;
}

button:hover,
a:hover {
    background: var(--primary-dark);
}

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

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 800;
}

input,
select,
textarea {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 8px 10px;
    color: var(--text);
    background: #ffffff;
}

textarea {
    min-height: 82px;
    resize: vertical;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 5px;
    font-size: clamp(1.5rem, 3vw, 2.1rem);
}

h2 {
    margin-bottom: 5px;
    font-size: 1.16rem;
}

p {
    margin-bottom: 0;
    color: var(--muted);
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 20px clamp(16px, 4vw, 44px);
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.brand {
    display: flex;
    align-items: center;
    gap: 18px;
}

.brand img {
    width: min(300px, 26vw);
    height: auto;
    flex: 0 0 auto;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-shell {
    width: min(1480px, 100%);
    margin: 0 auto;
    padding: 22px clamp(12px, 3vw, 34px) 42px;
}

.panel,
.metric {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel {
    min-width: 0;
    margin-bottom: 16px;
    padding: 17px;
}

.panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
}

.section-kicker {
    display: inline-block;
    margin-bottom: 4px;
    color: var(--primary);
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
}

.login-panel {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(280px, 0.8fr);
    gap: 18px;
    align-items: end;
}

.login-form {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto;
    gap: 10px;
    align-items: end;
}

.mfa-setup-panel,
.recovery-codes-panel {
    grid-column: 1 / -1;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    background: var(--surface-soft);
}

.mfa-setup-panel h3,
.recovery-codes-panel h3 {
    margin: 0 0 6px;
}

.mfa-setup-panel p,
.recovery-codes-panel p {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 0.9rem;
}

.mfa-qr-code {
    width: 220px;
    max-width: 100%;
    aspect-ratio: 1;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
}

.mfa-qr-code svg {
    display: block;
    width: 100%;
    height: 100%;
}

.manual-key {
    display: grid;
    gap: 4px;
    margin: 10px 0;
}

.manual-key span {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 900;
    text-transform: uppercase;
}

.manual-key code,
.recovery-codes-panel pre {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    margin: 0;
    border-radius: 6px;
    padding: 10px;
    background: #fff;
    border: 1px solid var(--border);
    font: 0.9rem/1.45 Consolas, "Courier New", monospace;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.metric {
    min-height: 112px;
    padding: 15px;
}

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

.metric strong {
    display: block;
    margin: 7px 0 3px;
    font-size: 2rem;
    line-height: 1;
}

.metric small {
    color: var(--muted);
    font-weight: 700;
}

.tab-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.tabs,
.toolbar,
.form-actions,
.row-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.tab-button {
    color: var(--text);
    border: 1px solid var(--line);
    background: #ffffff;
}

.tab-button.is-active {
    color: #ffffff;
    border-color: var(--primary);
    background: var(--primary);
}

.secondary-button {
    color: var(--text);
    border: 1px solid var(--line);
    background: #ffffff;
}

.secondary-button:hover {
    background: var(--surface-soft);
}

.ghost-button {
    color: var(--muted);
    background: transparent;
}

.ghost-button:hover {
    color: var(--text);
    background: var(--surface-soft);
}

.view {
    display: none;
}

.view.is-active {
    display: block;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
    gap: 16px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
}

.quick-onboarding-panel {
    border-color: rgba(201, 47, 59, 0.38);
}

.quick-onboarding-panel .panel-heading h2 {
    font-size: 1.28rem;
}

.quick-onboarding-panel .form-actions button {
    min-width: 260px;
}

.full-field {
    grid-column: 1 / -1;
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px;
    background: #fbfcfd;
}

.branding-color-grid {
    grid-template-columns: repeat(2, minmax(390px, 1fr));
}

.feature-grid label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--text);
}

.branding-color-grid label {
    display: grid;
    align-items: stretch;
    min-width: 0;
}

.branding-color-grid .hex-input {
    min-width: 260px;
    min-height: 54px;
    font-family: Consolas, "Courier New", monospace;
    font-size: 1.18rem;
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
    border-left: 18px solid var(--hex-preview-color, var(--line));
}

.color-control-label,
.wide-branding-control {
    min-width: 0;
}

.color-control {
    display: grid;
    grid-template-columns: 76px minmax(260px, 1fr);
    gap: 10px;
    align-items: stretch;
}

.color-control input[type="color"] {
    width: 76px;
    min-height: 54px;
    padding: 3px;
    cursor: pointer;
}

.wide-branding-control input {
    min-height: 56px;
    font-size: 1.14rem;
    font-weight: 800;
}

.upload-field {
    display: grid;
    grid-template-columns: minmax(220px, 0.7fr) minmax(220px, 1fr);
    gap: 10px 14px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #fbfcfd;
}

.upload-heading {
    display: grid;
    gap: 2px;
}

.upload-heading strong {
    color: var(--text);
    font-weight: 900;
}

.upload-heading span,
.asset-preview span {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.asset-preview span.is-error {
    color: var(--danger-text);
}

.asset-preview span.is-warning {
    color: var(--warning-text);
}

.file-upload {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    justify-self: start;
    min-height: 40px;
    border-radius: 7px;
    padding: 8px 12px;
    color: #ffffff;
    background: var(--primary);
    cursor: pointer;
    font-weight: 900;
}

.file-upload:hover {
    background: var(--primary-dark);
}

.file-upload input {
    display: none;
}

.asset-preview {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
}

.asset-preview img {
    width: 100%;
    max-width: 110px;
    max-height: 68px;
    object-fit: contain;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px;
    background: #ffffff;
}

.feature-grid input,
.check-label input,
.permission-item input {
    width: 18px;
    min-height: 18px;
}

.branding-color-grid .color-control input[type="color"] {
    width: 76px;
    min-height: 54px;
}

.branding-color-grid .color-control .hex-input {
    width: 100%;
    min-width: 260px;
    min-height: 54px;
}

.branding-color-grid .wide-branding-control input {
    width: 100%;
    min-height: 56px;
    padding: 12px 14px;
}

.branding-color-grid .wide-branding-control {
    grid-column: auto;
}

.field-title {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 900;
    text-transform: uppercase;
}

.license-policy-note {
    display: grid;
    gap: 6px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f4f6f8;
    color: var(--text);
}

.license-policy-note strong {
    font-size: 0.82rem;
}

.license-policy-note span {
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.45;
}

.check-label {
    display: inline-flex;
    align-items: center;
    align-self: end;
    min-height: 38px;
    gap: 8px;
    color: var(--text);
}

.permission-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.permission-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    column-gap: 9px;
    row-gap: 2px;
    min-height: 68px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    color: var(--text);
    background: #fbfcfd;
}

.permission-item input {
    grid-row: 1 / span 2;
    margin-top: 2px;
}

.permission-item span {
    font-weight: 900;
}

.permission-item small {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.form-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
}

.admin-dialog {
    width: min(940px, calc(100vw - 28px));
    max-height: calc(100vh - 28px);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 18px;
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.admin-dialog::backdrop {
    background: rgba(15, 23, 42, 0.42);
}

.admin-dialog form {
    display: grid;
    gap: 12px;
}

.admin-dialog textarea {
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.9rem;
}

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

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

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 10px 9px;
    text-align: left;
    vertical-align: top;
}

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

td {
    color: var(--text);
    font-size: 0.92rem;
    overflow-wrap: anywhere;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border-radius: 999px;
    padding: 4px 9px;
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 0.78rem;
    font-weight: 900;
}

.badge.is-active,
.badge.is-trial,
.badge.is-ok,
.badge.is-trusted,
.badge.is-sent,
.badge.is-booked,
.badge.is-approved {
    color: var(--green);
    background: #e5f7ec;
}

.badge.is-paused,
.badge.is-pending,
.badge.is-prospect,
.badge.is-invited,
.badge.is-required,
.badge.is-setup_required,
.badge.is-requested,
.badge.is-prepared,
.badge.is-unconfigured {
    color: var(--warning-text);
    background: var(--warning-bg);
}

.badge.is-blocked,
.badge.is-expired,
.badge.is-archived,
.badge.is-revoked,
.badge.is-missing,
.badge.is-failed,
.badge.is-rejected,
.badge.is-inactive {
    color: var(--danger-text);
    background: var(--danger-bg);
}

.status-text {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

.status-text.is-ready {
    color: var(--green);
}

.status-text.is-warning {
    color: var(--warning-text);
}

.status-text.is-error {
    color: var(--danger-text);
}

.compact-list {
    display: grid;
    gap: 9px;
}

.compact-item,
.backup-details dl {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px;
    background: #fbfcfd;
}

.compact-item strong,
.compact-item span {
    display: block;
}

.compact-item span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.88rem;
}

.backup-details dl {
    display: grid;
    grid-template-columns: minmax(160px, 0.4fr) minmax(0, 1fr);
    gap: 8px 14px;
    margin: 0;
}

.backup-details dt {
    color: var(--muted);
    font-weight: 900;
}

.backup-details dd {
    margin: 0;
    overflow-wrap: anywhere;
}

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

@media (max-width: 1050px) {
    .admin-header,
    .brand,
    .tab-panel,
    .panel-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .brand img {
        width: min(280px, 72vw);
    }

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

    .dashboard-grid,
    .login-panel {
        grid-template-columns: 1fr;
    }

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

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

    .branding-color-grid {
        grid-template-columns: repeat(2, minmax(280px, 1fr));
    }

    .upload-field,
    .asset-preview {
        grid-template-columns: 1fr;
    }

    .file-upload {
        justify-self: stretch;
    }
}

@media (max-width: 760px) {
    .branding-color-grid,
    .color-control {
        grid-template-columns: 1fr;
    }

    .branding-color-grid .wide-branding-control {
        grid-column: auto;
    }

    .color-control input[type="color"] {
        width: 100%;
    }
}

@media (max-width: 680px) {
    .admin-shell {
        padding: 14px 10px 32px;
    }

    .header-actions,
    .tabs,
    .toolbar,
    .login-form,
    .form-grid,
    .feature-grid,
    .permission-grid,
    .summary-grid {
        grid-template-columns: 1fr;
        width: 100%;
    }

    .login-form,
    .form-grid,
    .feature-grid,
    .permission-grid {
        display: grid;
    }

    button,
    a {
        width: 100%;
        text-align: center;
    }

    .backup-details dl {
        grid-template-columns: 1fr;
    }
}
