:root {
    color-scheme: light;
    --page: #f3f5f8;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #202a36;
    --heading: #111827;
    --muted: #6b7280;
    --line: #dde3ea;
    --blue: #3159d9;
    --blue-soft: #eef2ff;
    --green: #16835f;
    --green-soft: #eaf8f2;
    --red: #be3f50;
    --red-soft: #fff0f2;
    --amber: #a8640a;
    --amber-soft: #fff6e5;
    --shadow: 0 8px 24px rgba(31, 41, 55, .07);
}

* {
    box-sizing: border-box;
    letter-spacing: 0;
}

html {
    min-width: 320px;
    background: var(--page);
}

body {
    margin: 0;
    color: var(--text);
    background: var(--page);
    font-family: Arial, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.55;
}

a {
    color: var(--blue);
    text-decoration: none;
}

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

button,
summary {
    cursor: pointer;
}

button {
    min-height: 40px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
}

button:hover {
    border-color: #bdc7d4;
    background: var(--surface-soft);
}

.primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    border-color: var(--blue);
    color: #fff;
    background: var(--blue);
    font-weight: 700;
}

.primary:hover {
    border-color: #2449be;
    background: #2449be;
}

.danger {
    border-color: #f0c6cc;
    color: var(--red);
    background: var(--red-soft);
}

label {
    display: grid;
    min-width: 0;
    gap: 7px;
    color: #475569;
    font-size: 13px;
}

input,
select,
textarea {
    width: 100%;
    min-width: 0;
    min-height: 42px;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 7px;
    outline: 0;
    background: #fff;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #7890ea;
    box-shadow: 0 0 0 3px rgba(49, 89, 217, .1);
}

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

code {
    display: inline-block;
    max-width: 100%;
    padding: 3px 6px;
    border: 1px solid #dfe5ed;
    border-radius: 5px;
    overflow-wrap: anywhere;
    color: #334155;
    background: #f5f7fa;
    font-family: Consolas, "Courier New", monospace;
    white-space: normal;
}

.sidebar {
    position: fixed;
    z-index: 80;
    inset: 0 auto 0 0;
    display: flex;
    width: 248px;
    flex-direction: column;
    padding: 22px 18px;
    border-right: 1px solid var(--line);
    background: #fff;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 48px;
    margin-bottom: 22px;
}

.brand > span,
.public-brand > span {
    display: grid;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    place-items: center;
    border-radius: 7px;
    color: #fff;
    background: var(--blue);
    font-size: 17px;
    font-weight: 800;
}

.brand b,
.public-brand strong {
    display: block;
    color: var(--heading);
    font-size: 15px;
}

.brand small,
.public-brand small {
    display: block;
    color: var(--muted);
    font-size: 11px;
}

.nav-close {
    display: none;
    width: 36px;
    min-height: 36px;
    margin-left: auto;
    padding: 0;
    border: 0;
    font-size: 24px;
}

.sidebar nav {
    display: grid;
    gap: 4px;
}

.sidebar nav a {
    min-height: 40px;
    padding: 9px 11px;
    border-radius: 6px;
    color: #4b5563;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    color: var(--blue);
    background: var(--blue-soft);
}

.sidebar-footer {
    display: grid;
    gap: 8px;
    margin-top: auto;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.sidebar-footer > a {
    padding: 7px 2px;
}

.sidebar-footer button {
    width: 100%;
}

.mobile-header,
.sidebar-overlay {
    display: none;
}

.main {
    min-height: 100vh;
    margin-left: 248px;
    padding: 28px 32px 44px;
}

.page-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, .7fr);
    align-items: end;
    gap: 24px;
    margin-bottom: 20px;
}

.page-head p {
    grid-column: 1;
    margin: 0 0 3px;
    color: var(--blue);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.page-head h1 {
    grid-column: 1;
    margin: 0;
    color: var(--heading);
    font-size: 28px;
}

.page-head span {
    grid-column: 2;
    grid-row: 1 / span 2;
    color: var(--muted);
    text-align: right;
}

.panel,
.stat-grid article,
.service-panel,
.service-entry-card,
.public-result,
.login-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

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

.panel > h2,
.tool-grid h2 {
    margin: 0 0 16px;
    color: var(--heading);
    font-size: 17px;
}

.panel > p,
.tool-grid p {
    color: var(--muted);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-grid article {
    min-height: 112px;
    padding: 17px;
}

.stat-grid small {
    color: var(--muted);
}

.stat-grid strong {
    display: block;
    margin-top: 14px;
    color: var(--heading);
    font-size: 30px;
}

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

.grid-form .wide {
    grid-column: 1 / -1;
}

.grid-form > button {
    justify-self: start;
}

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

.tool-grid .panel {
    margin-bottom: 0;
}

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

.api-box code {
    display: block;
    padding: 10px;
}

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

.panel-toolbar h2 {
    margin: 0;
    font-size: 17px;
}

.filter-form {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) 130px auto;
    gap: 8px;
}

.table-wrap {
    width: 100%;
    max-height: min(68vh, 760px);
    overflow-x: auto;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

th,
td {
    max-width: 210px;
    padding: 7px 9px;
    border-bottom: 1px solid var(--line);
    overflow: hidden;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
}

th {
    position: sticky;
    z-index: 2;
    top: 0;
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 11px;
    text-transform: uppercase;
}

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

tbody tr:hover td {
    background: #fbfcff;
}

td code {
    display: inline-block;
    max-width: min(180px, 100%);
    padding: 2px 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
    white-space: nowrap;
}

td:nth-child(1) {
    width: 52px;
    max-width: 58px;
    color: var(--muted);
}

.actions {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
    overflow: visible;
}

.actions form {
    margin: 0;
}

.actions button,
.actions summary {
    min-height: 28px;
    padding: 4px 7px;
    font-size: 12px;
}

.actions summary {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    list-style: none;
    background: #fff;
}

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

.inline-edit {
    position: fixed;
    z-index: 220;
    top: 50%;
    left: 50%;
    display: grid;
    width: min(420px, calc(100vw - 32px));
    max-height: calc(100vh - 40px);
    gap: 10px;
    overflow-y: auto;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 24px 70px rgba(15, 23, 42, .25);
    transform: translate(-50%, -50%);
}

.badge {
    display: inline-flex;
    min-height: 20px;
    align-items: center;
    padding: 2px 6px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
}

.badge.active,
.badge.unused {
    color: var(--green);
    background: var(--green-soft);
}

.badge.disabled {
    color: var(--red);
    background: var(--red-soft);
}

.badge.expired,
.badge.used {
    color: var(--amber);
    background: var(--amber-soft);
}

.toast {
    position: relative;
    z-index: 10;
    margin-bottom: 14px;
    padding: 12px 14px;
    border: 1px solid #cdd8f8;
    border-radius: 7px;
    color: #294eaa;
    background: #f2f5ff;
}

.toast.error {
    border-color: #efc5cc;
    color: var(--red);
    background: var(--red-soft);
}

.toast.success {
    border-color: #bfe3d5;
    color: var(--green);
    background: var(--green-soft);
}

.empty-cell,
.muted-text {
    color: var(--muted);
    text-align: center;
}

.auth-main {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
}

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

.login-card h1 {
    margin: 0 0 6px;
    color: var(--heading);
    font-size: 25px;
}

.login-card p {
    margin-bottom: 18px;
    color: var(--muted);
}

.login-card form {
    display: grid;
    gap: 12px;
}

.public-main {
    min-height: 100vh;
    background: #f5f7fa;
}

.public-topbar {
    display: flex;
    width: min(1120px, calc(100% - 40px));
    min-height: 72px;
    margin: 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    border-bottom: 1px solid var(--line);
}

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

.admin-entry {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: #475569;
    background: #fff;
}

.public-service-head {
    width: min(1120px, calc(100% - 40px));
    margin: 0 auto;
    padding: 52px 0 24px;
}

.public-service-head p {
    margin: 0 0 5px;
    color: var(--blue);
    font-size: 12px;
    font-weight: 800;
}

.public-service-head h1 {
    margin: 0;
    color: var(--heading);
    font-size: 36px;
}

.public-service-head span {
    display: block;
    max-width: 680px;
    margin-top: 10px;
    color: var(--muted);
    font-size: 15px;
}

.public-service-head-compact {
    padding-top: 30px;
}

.public-back-link {
    display: inline-flex;
    margin-bottom: 20px;
    align-items: center;
    color: #526173;
    font-size: 13px;
    font-weight: 700;
}

.public-back-link:hover {
    color: var(--blue);
}

.self-service-grid {
    display: grid;
    width: min(1120px, calc(100% - 40px));
    margin: 0 auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.service-entry-card {
    display: grid;
    min-width: 0;
    min-height: 190px;
    padding: 24px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: start;
    gap: 16px;
    border-top: 3px solid #6f7f91;
    color: inherit;
    transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.service-entry-card:hover {
    border-color: #9eabba;
    box-shadow: 0 12px 28px rgba(31, 41, 55, .1);
    transform: translateY(-2px);
}

.service-entry-card-accent,
.service-entry-card-accent:hover {
    border-top-color: var(--blue);
}

.service-entry-index {
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    border-radius: 7px;
    color: var(--blue);
    background: var(--blue-soft);
    font-weight: 800;
}

.service-entry-card p {
    margin: 1px 0 3px;
    color: var(--muted);
    font-size: 11px;
}

.service-entry-card h2 {
    margin: 0;
    color: var(--heading);
    font-size: 22px;
}

.service-entry-card div > span {
    display: block;
    margin-top: 10px;
    color: var(--muted);
    font-size: 13px;
}

.service-entry-card > strong {
    color: var(--blue);
    font-size: 24px;
    line-height: 1;
}

.single-service {
    width: min(720px, calc(100% - 40px));
    margin: 0 auto;
}

.service-panel {
    min-width: 0;
    padding: 22px;
    border-top: 3px solid #6f7f91;
}

.service-panel-accent {
    border-top-color: var(--blue);
}

.service-panel-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.service-panel-head > span {
    display: grid;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    place-items: center;
    border-radius: 7px;
    color: var(--blue);
    background: var(--blue-soft);
    font-weight: 800;
}

.service-panel-head p {
    margin: 0;
    color: var(--muted);
    font-size: 11px;
}

.service-panel-head h2 {
    margin: 1px 0 0;
    color: var(--heading);
    font-size: 19px;
}

.public-form {
    display: grid;
    gap: 13px;
}

.public-form .primary {
    justify-self: start;
    min-width: 118px;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.public-result {
    width: min(1120px, calc(100% - 40px));
    margin: 0 auto 18px;
    padding: 20px;
    border-left: 4px solid var(--red);
}

.public-result.success {
    border-left-color: var(--green);
}

.result-heading {
    display: flex;
    align-items: center;
    gap: 10px;
}

.result-heading > span {
    padding: 3px 8px;
    border-radius: 999px;
    color: var(--red);
    background: var(--red-soft);
    font-size: 11px;
    font-weight: 700;
}

.public-result.success .result-heading > span {
    color: var(--green);
    background: var(--green-soft);
}

.result-heading h2 {
    margin: 0;
    color: var(--heading);
    font-size: 19px;
}

.public-result > p {
    margin: 10px 0 14px;
    color: var(--muted);
}

.public-result dl {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 0;
}

.public-result dt {
    color: var(--muted);
    font-size: 11px;
}

.public-result dd {
    margin: 3px 0 0;
    overflow-wrap: anywhere;
    color: var(--heading);
}

.public-footer {
    display: flex;
    width: min(1120px, calc(100% - 40px));
    margin: 42px auto 0;
    justify-content: space-between;
    gap: 20px;
    padding: 20px 0 30px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
}

@media (max-width: 1099px) {
    .mobile-header {
        position: fixed;
        z-index: 70;
        top: 0;
        right: 0;
        left: 0;
        display: flex;
        min-height: 62px;
        align-items: center;
        gap: 12px;
        padding: 9px 18px;
        border-bottom: 1px solid var(--line);
        background: #fff;
    }

    .mobile-header strong {
        color: var(--heading);
    }

    .mobile-header > a {
        margin-left: auto;
    }

    .nav-toggle {
        width: 40px;
        min-height: 40px;
        padding: 0;
        font-size: 20px;
    }

    .sidebar {
        width: min(280px, 86vw);
        transform: translateX(-102%);
        transition: transform .2s ease;
    }

    .nav-close {
        display: block;
    }

    .sidebar-overlay {
        position: fixed;
        z-index: 75;
        inset: 0;
        width: 100%;
        height: 100%;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: rgba(15, 23, 42, .38);
    }

    .nav-open .sidebar {
        transform: translateX(0);
    }

    .nav-open .sidebar-overlay {
        display: block;
    }

    .main {
        margin-left: 0;
        padding: 88px 24px 36px;
    }

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

    .api-box {
        grid-template-columns: 1fr;
    }

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

@media (max-width: 767px) {
    .mobile-header {
        padding: 9px 12px;
    }

    .mobile-header > a {
        font-size: 12px;
    }

    .main {
        padding: 76px 12px 28px;
    }

    .page-head {
        display: block;
        margin-bottom: 14px;
    }

    .page-head h1 {
        font-size: 24px;
    }

    .page-head span {
        display: block;
        margin-top: 7px;
        text-align: left;
    }

    .panel {
        padding: 15px;
    }

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

    .stat-grid article {
        min-height: 98px;
        padding: 14px;
    }

    .stat-grid strong {
        margin-top: 9px;
        font-size: 25px;
    }

    .grid-form,
    .tool-grid {
        grid-template-columns: 1fr;
    }

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

    .grid-form > button {
        width: 100%;
    }

    .panel-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .filter-form {
        grid-template-columns: minmax(0, 1fr) minmax(110px, .55fr);
    }

    .filter-form input {
        grid-column: 1 / -1;
    }

    .filter-form button {
        width: 100%;
    }

    table {
        min-width: 760px;
    }

    .actions {
        flex-wrap: wrap;
    }

    .inline-edit {
        width: calc(100vw - 24px);
        max-height: calc(100vh - 24px);
    }

    .auth-main {
        padding: 12px;
    }

    .login-card {
        padding: 22px;
    }

    .public-topbar,
    .public-service-head,
    .self-service-grid,
    .single-service,
    .public-result,
    .public-footer {
        width: calc(100% - 24px);
    }

    .public-topbar {
        min-height: 64px;
    }

    .public-brand small {
        display: none;
    }

    .public-service-head {
        padding: 30px 0 18px;
    }

    .public-service-head h1 {
        font-size: 28px;
    }

    .public-service-head span {
        font-size: 13px;
    }

    .self-service-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .single-service {
        width: calc(100% - 24px);
    }

    .service-entry-card {
        min-height: 154px;
        padding: 18px;
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 12px;
    }

    .service-entry-card h2 {
        font-size: 19px;
    }

    .service-panel {
        padding: 17px;
    }

    .public-form .primary {
        width: 100%;
    }

    .public-result {
        padding: 16px;
    }

    .public-result dl {
        grid-template-columns: 1fr;
        gap: 9px;
    }

    .public-footer {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
        margin-top: 28px;
    }
}

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

    .public-brand strong {
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}
