:root {
    color-scheme: light;
    --bg: #f5f7f8;
    --surface: #ffffff;
    --surface-soft: #f8faf9;
    --text: #202124;
    --muted: #66706a;
    --line: #dfe5e2;
    --primary: #087f73;
    --primary-dark: #05645b;
    --green: #24824b;
    --amber: #a46108;
    --red: #b3261e;
    --blue: #1769aa;
    --charcoal: #252927;
    --shadow: 0 4px 18px rgba(32, 33, 36, .08);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    letter-spacing: 0;
}

button,
input,
select,
textarea {
    font: inherit;
    letter-spacing: 0;
}

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

.console-appbar {
    left: 240px;
    width: auto;
    background: rgba(255, 255, 255, .97);
    color: var(--text);
    border-bottom: 1px solid var(--line);
    box-shadow: none;
    backdrop-filter: blur(10px);
}

.console-appbar .mdui-toolbar {
    height: 64px;
    min-height: 64px;
    padding: 0 28px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    color: var(--text);
    text-decoration: none;
    font-size: 16px;
    font-weight: 700;
}

.brand-mark,
.profile-mark,
.account-avatar {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    line-height: 1;
}

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 7px;
    font-size: 12px;
}

.toolbar-spacer {
    flex: 1;
}

.account-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 4px 10px;
    color: var(--text);
    text-decoration: none;
    border-radius: 6px;
}

.account-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 12px;
}

.top-logout {
    margin-left: 4px;
}

.top-logout .mdui-btn {
    color: var(--muted);
}

.menu-button {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.menu-button span {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 1px;
    background: currentColor;
}

.console-body .console-drawer {
    top: 0;
    bottom: 0;
    width: 240px;
    height: 100vh;
    background: var(--charcoal);
    color: #fff;
    border: 0;
    box-shadow: none;
    transform: translateX(0);
}

.drawer-heading {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 94px;
    padding: 20px 24px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
}

.drawer-heading span {
    font-size: 18px;
    font-weight: 700;
}

.drawer-heading small {
    margin-top: 4px;
    color: #aeb7b2;
    font-size: 11px;
    text-transform: uppercase;
}

.console-drawer .mdui-list {
    padding: 18px 12px;
}

.console-drawer .mdui-list-item {
    display: flex;
    align-items: center;
    height: 44px;
    min-height: 44px;
    margin-bottom: 4px;
    padding: 0 14px;
    border-radius: 6px;
    color: #cbd3cf;
    font-weight: 600;
}

.console-drawer .mdui-list-item:hover,
.console-drawer .mdui-list-item.active {
    background: rgba(255, 255, 255, .1);
    color: #fff;
}

.console-drawer .mdui-list-item.active {
    box-shadow: inset 3px 0 0 #50c2b4;
}

.drawer-footer {
    position: absolute;
    right: 18px;
    bottom: 20px;
    left: 18px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, .1);
}

.drawer-footer span,
.drawer-footer strong {
    display: block;
}

.drawer-footer span {
    color: #98a39d;
    font-size: 11px;
}

.drawer-footer strong {
    margin-top: 4px;
    color: #dce5e0;
    font-size: 13px;
}

.console-main {
    min-height: calc(100vh - 64px);
    padding: 28px;
}

.page-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    max-width: 1560px;
    margin: 0 auto 22px;
}

.page-heading h1 {
    margin: 3px 0 0;
    font-size: 26px;
    font-weight: 700;
    line-height: 1.25;
}

.page-kicker,
.page-heading > time {
    color: var(--muted);
    font-size: 12px;
}

.page-content {
    max-width: 1560px;
    margin: 0 auto;
}

.panel,
.card,
.filter-panel,
.overview-strip,
.login-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.panel {
    margin-bottom: 18px;
    padding: 20px;
}

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

.section-heading h2 {
    margin: 0;
    font-size: 17px;
    line-height: 1.35;
}

.section-heading p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.section-actions,
.quick-actions,
.row-actions,
.filter-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

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

.card {
    position: relative;
    min-height: 132px;
    padding: 17px 16px;
    overflow: hidden;
    color: var(--text);
    text-decoration: none;
}

.card::before {
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--primary);
    content: "";
}

.card span,
.card strong,
.card small {
    display: block;
}

.card span {
    color: var(--muted);
    font-size: 12px;
}

.card strong {
    margin: 11px 0 8px;
    font-size: 28px;
    line-height: 1;
}

.card small {
    color: var(--primary-dark);
    font-size: 11px;
}

.metric-amber::before { background: var(--amber); }
.metric-green::before { background: var(--green); }
.metric-blue::before { background: var(--blue); }
.metric-red::before { background: var(--red); }
.metric-gray::before { background: #6b716e; }

.overview-strip {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(200px, 1fr) auto;
    align-items: center;
    gap: 24px;
    margin-bottom: 18px;
    padding: 18px 20px;
}

.overview-strip > div > span,
.overview-strip > div > strong {
    display: block;
}

.overview-strip > div > span {
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 11px;
}

.overview-strip > div > strong {
    font-size: 16px;
}

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

.grid-form {
    display: grid;
    grid-template-columns: 2fr repeat(3, minmax(160px, 1fr)) auto;
    align-items: end;
    gap: 14px;
}

.stack-form {
    display: grid;
    gap: 16px;
}

.field {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 6px;
}

.field > span,
.switch-field > span {
    color: #4d5752;
    font-size: 12px;
    font-weight: 600;
}

.field input,
.field select,
.field textarea,
.compact-input {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 9px 11px;
    color: var(--text);
    background: #fff;
    border: 1px solid #cfd7d3;
    border-radius: 6px;
    outline: none;
    box-shadow: none;
}

.field textarea {
    resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.compact-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(8, 127, 115, .12);
}

.field small {
    color: var(--muted);
    font-size: 11px;
}

.field-wide {
    grid-column: span 2;
}

.input-wide {
    min-width: 280px;
}

.file-field input {
    padding: 7px;
}

.form-action {
    display: flex;
    align-items: flex-end;
    min-height: 40px;
}

.mdui-btn-raised {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 6px rgba(8, 127, 115, .24);
}

.mdui-btn-raised:hover,
.mdui-btn-raised:focus {
    background: var(--primary-dark);
    color: #fff;
}

.mdui-btn.is-loading {
    opacity: .62;
    cursor: wait;
}

.action-secondary {
    color: #59625e;
}

.switch-field {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 40px;
    cursor: pointer;
}

.switch-field input,
input.mdui-switch {
    position: relative;
    width: 38px;
    height: 22px;
    margin: 0;
    appearance: none;
    background: #aeb8b3;
    border: 0;
    border-radius: 12px;
    cursor: pointer;
}

.switch-field input::before,
input.mdui-switch::before {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .24);
    content: "";
    transition: transform .16s ease;
}

.switch-field input:checked,
input.mdui-switch:checked {
    background: var(--primary);
}

.switch-field input:checked::before,
input.mdui-switch:checked::before {
    transform: translateX(16px);
}

.filter-panel {
    margin-bottom: 18px;
    padding: 14px 16px;
}

.filter-form {
    display: grid;
    grid-template-columns: minmax(260px, 2fr) minmax(170px, 1fr) auto;
    align-items: end;
    gap: 12px;
}

.table-panel {
    padding-right: 0;
    padding-left: 0;
}

.table-panel > .section-heading {
    padding: 0 20px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 12px 13px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid #e8ecea;
    font-size: 13px;
    white-space: nowrap;
}

th {
    color: #59625e;
    background: var(--surface-soft);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

tbody tr:hover {
    background: #fafcfb;
}

tbody tr:last-child td {
    border-bottom: 0;
}

.compact-panel {
    min-width: 0;
}

.compact-panel th,
.compact-panel td {
    padding: 11px 12px;
}

.subline {
    display: block;
    max-width: 260px;
    margin-top: 4px;
    overflow: hidden;
    color: var(--muted);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.subline.good { color: var(--green); }
.subline.bad { color: var(--red); }
.subline.warn { color: var(--amber); }

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.badge.ok { color: #176b3b; background: #e7f5ec; }
.badge.warning { color: #825005; background: #fff2d8; }
.badge.danger { color: #9d211b; background: #fce9e7; }
.badge.muted { color: #59625e; background: #ecefed; }
.badge.actor { color: #155d88; background: #e7f2f8; }

.copy-value {
    max-width: 260px;
    padding: 0;
    overflow: hidden;
    color: #33413b;
    background: transparent;
    border: 0;
    cursor: pointer;
    text-overflow: ellipsis;
}

code {
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 12px;
}

.row-actions {
    min-width: 108px;
}

.inline-form {
    display: inline-flex;
    margin: 0;
}

.muted-text {
    color: #8a928e;
}

.notice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    padding: 11px 14px;
    border: 1px solid;
    border-radius: 7px;
}

.notice-success { color: #176b3b; background: #edf8f1; border-color: #b8dfc6; }
.notice-error { color: #912018; background: #fff0ee; border-color: #f0c2bd; }
.notice-warning { color: #7b4c05; background: #fff7e8; border-color: #f0d39c; }

.notice-close {
    flex: 0 0 34px;
    color: currentColor;
    font-size: 20px;
}

.empty-state {
    display: grid;
    justify-items: center;
    padding: 34px 20px;
    color: var(--muted);
    text-align: center;
}

.empty-state strong {
    margin-top: 9px;
    color: #48514d;
}

.empty-state p {
    margin: 6px 0 0;
    font-size: 12px;
}

.empty-mark {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    color: var(--primary);
    background: #e5f2f0;
    border-radius: 50%;
    font-size: 20px;
}

.edit-dialog,
.detail-dialog {
    width: min(620px, calc(100vw - 28px));
    border-radius: 8px;
}

.mdui-dialog-title {
    font-size: 19px;
    font-weight: 700;
}

.edit-dialog > form > .mdui-dialog-title {
    padding: 24px 24px 20px;
}

.mdui-dialog-actions .mdui-btn-raised,
.mdui-dialog-actions .mdui-btn-raised:hover,
.mdui-dialog-actions .mdui-btn-raised:focus {
    color: #fff;
}

.mdui-dialog-content .field {
    margin-bottom: 15px;
}

.dialog-code {
    margin: 0 0 18px;
    padding: 10px 12px;
    overflow: hidden;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 6px;
}

.json-viewer {
    max-height: 420px;
    margin: 12px 0 0;
    padding: 14px;
    overflow: auto;
    color: #d8e3dc;
    background: #242826;
    border-radius: 6px;
    font: 12px/1.6 Consolas, "SFMono-Regular", monospace;
    white-space: pre-wrap;
    word-break: break-word;
}

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

.detail-grid > div {
    min-width: 0;
}

.detail-grid dt {
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 11px;
}

.detail-grid dd {
    margin: 0;
    overflow: hidden;
    color: var(--text);
}

.backup-detail .detail-grid {
    margin-bottom: 14px;
}

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

.backup-summary > div {
    display: grid;
    min-width: 0;
    min-height: 92px;
    align-content: center;
    padding: 14px 16px;
    background: #fff;
    border: 1px solid var(--line);
    border-top: 3px solid var(--primary);
    border-radius: 6px;
}

.backup-summary span,
.backup-summary small {
    color: var(--muted);
}

.backup-summary strong {
    margin: 5px 0 2px;
    overflow: hidden;
    color: var(--text);
    font-size: 21px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.backup-summary small {
    font-size: 11px;
}

.backup-summary-detail {
    margin: 18px 0 0;
}

.backup-summary-detail > div {
    background: var(--surface-soft);
    border-top-color: #94a3b8;
}

.backup-preview-table {
    margin-top: 18px;
}

.danger-zone {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-top: 18px;
    padding: 18px 20px;
    background: #fff;
    border: 1px solid #fecaca;
    border-left: 4px solid var(--danger);
    border-radius: 6px;
}

.danger-zone h2 {
    margin: 0 0 4px;
    font-size: 16px;
}

.danger-zone p {
    margin: 0;
    color: var(--muted);
}

.danger-action {
    color: var(--danger) !important;
    border: 1px solid #fecaca;
}

.account-layout {
    display: grid;
    grid-template-columns: minmax(280px, .8fr) minmax(360px, 1.2fr);
    gap: 18px;
}

.profile-panel {
    display: grid;
    grid-template-columns: 58px 1fr;
    align-content: start;
    gap: 16px;
}

.profile-panel .detail-grid {
    grid-column: 1 / -1;
    margin-top: 14px;
}

.profile-panel h2 {
    margin: 4px 0 5px;
    font-size: 20px;
}

.profile-panel p {
    margin: 0;
    color: var(--muted);
}

.profile-mark {
    width: 58px;
    height: 58px;
    border-radius: 8px;
    font-size: 22px;
}

.totp-panel,
.totp-recovery-panel {
    margin-top: 18px;
}

.totp-setup {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    align-items: center;
    gap: 24px;
    margin-bottom: 24px;
    padding: 18px;
    background: #f7faf8;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.totp-qrcode {
    display: grid;
    width: 220px;
    min-height: 220px;
    place-items: center;
    padding: 8px;
    overflow: hidden;
    color: var(--muted);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 12px;
    text-align: center;
}

.totp-qrcode svg {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
}

.totp-secret {
    display: flex;
    min-width: 0;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
}

.totp-secret > span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.totp-secret code {
    max-width: 100%;
    overflow-wrap: anywhere;
    font-size: 16px;
    line-height: 1.8;
}

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

.recovery-code-grid code {
    padding: 10px;
    text-align: center;
}

.login-step {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    color: var(--muted);
    background: #f3f7f5;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 12px;
}

.login-step strong {
    color: var(--text);
    font-size: 14px;
}

.login-restart {
    display: block;
    margin-top: 16px;
    color: var(--primary-dark);
    text-align: center;
    font-size: 12px;
}

.center-action {
    display: flex;
    justify-content: center;
    padding-bottom: 24px;
}

.login-body {
    min-height: 100vh;
    background: #eef2f0;
    border-top: 6px solid var(--primary);
}

.login-shell {
    display: grid;
    min-height: calc(100vh - 6px);
    place-content: center;
    padding: 32px 16px;
}

.login-card {
    width: min(420px, calc(100vw - 32px));
    padding: 30px;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 26px;
}

.login-brand > span {
    display: grid;
    width: 50px;
    height: 50px;
    place-items: center;
    color: #fff;
    background: var(--charcoal);
    border-radius: 8px;
    font-weight: 800;
}

.login-brand h1 {
    margin: 0;
    font-size: 20px;
}

.login-brand p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.login-submit {
    width: 100%;
    height: 42px;
    margin-top: 4px;
}

.login-footer {
    margin: 18px 0 0;
    color: #737d78;
    text-align: center;
    font-size: 11px;
}

@media (max-width: 1320px) {
    .cards {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

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

    .form-action {
        align-items: center;
    }
}

@media (max-width: 1023px) {
    .console-appbar {
        left: 0;
    }

    .console-appbar .mdui-toolbar {
        padding: 0 14px;
    }

    .menu-button {
        display: flex;
        margin-right: 4px;
    }

    .console-body .console-drawer {
        transform: translateX(-100%);
        box-shadow: 6px 0 24px rgba(0, 0, 0, .2);
    }

    .console-body .console-drawer.mdui-drawer-open {
        transform: translateX(0);
    }

    .console-main {
        padding: 20px;
    }
}

@media (max-width: 760px) {
    .brand > span:last-child,
    .account-link > span:last-child,
    .page-heading > time,
    .top-logout {
        display: none;
    }

    .console-main {
        padding: 16px 12px;
    }

    .page-heading {
        margin-bottom: 16px;
    }

    .page-heading h1 {
        font-size: 22px;
    }

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

    .card {
        min-height: 116px;
    }

    .overview-strip,
    .dashboard-grid,
    .account-layout,
    .grid-form,
    .filter-form {
        grid-template-columns: 1fr;
    }

    .overview-strip {
        gap: 16px;
    }

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

    .field-wide {
        grid-column: auto;
    }

    .input-wide {
        min-width: 0;
    }

    .panel {
        padding: 16px;
    }

    .table-panel {
        padding-right: 0;
        padding-left: 0;
    }

    .table-panel > .section-heading {
        padding: 0 16px;
    }

    .section-heading {
        flex-direction: column;
    }

    .section-actions {
        width: 100%;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

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

    .danger-zone {
        align-items: flex-start;
        flex-direction: column;
    }

    .totp-setup {
        grid-template-columns: 1fr;
    }

    .totp-qrcode {
        width: min(220px, 100%);
        min-height: 0;
        justify-self: center;
        aspect-ratio: 1;
    }

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

    .login-card {
        padding: 24px 20px;
    }
}

@media (max-width: 420px) {
    .cards {
        grid-template-columns: 1fr;
    }

    .card {
        min-height: 104px;
    }

    .row-actions,
    .filter-actions,
    .section-actions {
        flex-wrap: wrap;
    }

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