:root {
    --bg: #f2f5f7;
    --surface: #ffffff;
    --surface-soft: #f7f9fa;
    --text: #17212b;
    --muted: #657481;
    --line: #d9e1e6;
    --nav: #102a3a;
    --nav-soft: #183b50;
    --primary: #146c94;
    --primary-dark: #0d5576;
    --success: #17764a;
    --success-bg: #e7f5ed;
    --danger: #b42318;
    --danger-bg: #fcebea;
    --warning: #9a5b00;
    --warning-bg: #fff4d9;
    --pending: #4a6070;
    --pending-bg: #e9eef2;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
    font-size: 14px;
}

body {
    min-width: 320px;
}

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

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

code {
    padding: 2px 5px;
    background: #edf1f4;
    border-radius: 4px;
    color: #274252;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
}

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

.app-shell {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: 244px;
    padding: 20px 14px;
    background: var(--nav);
    color: #fff;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    min-height: 54px;
    padding: 0 8px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .12);
    display: flex;
    align-items: center;
    gap: 11px;
}

.brand-mark,
.login-brand {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: #e0a331;
    color: #102a3a;
    display: grid;
    place-items: center;
    font-size: 18px;
    font-weight: 800;
}

.sidebar-brand strong,
.sidebar-brand span {
    display: block;
}

.sidebar-brand strong {
    max-width: 158px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
}

.sidebar-brand span {
    margin-top: 3px;
    color: #aec4cf;
    font-size: 11px;
}

.nav {
    padding: 17px 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.nav a {
    min-height: 42px;
    padding: 0 12px;
    border-radius: 6px;
    color: #c7d6de;
    display: flex;
    align-items: center;
    font-weight: 600;
}

.nav a:hover {
    background: rgba(255, 255, 255, .07);
    color: #fff;
}

.nav a.active {
    background: #1c506b;
    color: #fff;
}

.sidebar-foot {
    margin-top: auto;
    padding: 16px 8px 0;
    border-top: 1px solid rgba(255, 255, 255, .12);
}

.mode-chip {
    margin-bottom: 10px;
    color: #aec4cf;
    font-size: 12px;
}

.mode-chip strong {
    color: #fff;
}

.sidebar-foot .link-button {
    color: #d8e3e8;
}

.main-area {
    min-height: 100vh;
    margin-left: 244px;
}

.topbar {
    min-height: 76px;
    padding: 15px 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.topbar h1 {
    margin: 0;
    font-size: 21px;
    letter-spacing: 0;
}

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

.admin-chip {
    min-width: 130px;
    text-align: right;
}

.admin-chip span,
.admin-chip small {
    display: block;
}

.admin-chip span {
    font-weight: 700;
}

.admin-chip small {
    margin-top: 3px;
    color: var(--muted);
}

.mobile-menu {
    display: none;
}

.content {
    width: min(1540px, 100%);
    margin: 0 auto;
    padding: 24px 28px 48px;
}

.panel {
    margin-bottom: 18px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.panel-head {
    min-height: 42px;
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.panel-head h2 {
    margin: 0 0 5px;
    font-size: 17px;
    letter-spacing: 0;
}

.panel-head p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

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

.metric {
    min-height: 132px;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-top: 3px solid var(--primary);
    border-radius: 8px;
}

.metric-green {
    border-top-color: var(--success);
}

.metric-red {
    border-top-color: var(--danger);
}

.metric-amber {
    border-top-color: #d18a14;
}

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

.metric span {
    color: var(--muted);
    font-weight: 600;
}

.metric strong {
    margin: 13px 0 8px;
    font-size: 34px;
    line-height: 1;
}

.metric strong.metric-text {
    font-size: 21px;
    line-height: 1.3;
}

.metric small {
    color: #7d8b96;
}

.toolbar-row,
.page-actions {
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.toolbar-note strong,
.toolbar-note span {
    display: block;
}

.toolbar-note span {
    margin-top: 4px;
    color: var(--muted);
}

.button {
    min-height: 40px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: 700;
    white-space: nowrap;
}

.button-primary {
    background: var(--primary);
    color: #fff;
}

.button-primary:hover {
    background: var(--primary-dark);
    color: #fff;
}

.button-light {
    background: #fff;
    border-color: #c5d0d7;
    color: var(--text);
}

.button-light:hover {
    border-color: #91a5b2;
    color: var(--text);
}

.button-danger {
    background: #fff;
    border-color: #e6aaa5;
    color: var(--danger);
}

.button-danger:hover {
    background: var(--danger-bg);
}

.button-block {
    width: 100%;
}

.link-button {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--primary);
    cursor: pointer;
}

.link-button:hover {
    color: var(--primary-dark);
}

.link-danger,
.link-button.link-danger {
    color: var(--danger);
}

.text-link {
    color: var(--primary);
    font-weight: 700;
}

.text-success {
    color: var(--success);
    font-weight: 700;
}

.text-danger {
    color: var(--danger);
    font-weight: 700;
}

.text-warning {
    color: var(--warning);
    font-weight: 700;
}

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

.alert,
.notice-box,
.inline-note,
.error-box {
    margin-bottom: 16px;
    padding: 13px 15px;
    border-left: 4px solid var(--primary);
    border-radius: 6px;
    background: #eaf4f8;
    line-height: 1.6;
}

.alert-success {
    border-left-color: var(--success);
    background: var(--success-bg);
    color: #0d5c39;
}

.alert-error {
    border-left-color: var(--danger);
    background: var(--danger-bg);
    color: #8f1e15;
}

.alert-info {
    border-left-color: var(--primary);
}

.notice-box p {
    margin: 6px 0 0;
    color: #405563;
}

.error-box {
    border-left-color: var(--danger);
    background: var(--danger-bg);
    color: #7f1d1d;
    word-break: break-word;
}

.inline-note {
    margin-top: 14px;
    margin-bottom: 0;
}

.status-strip {
    display: grid;
    grid-template-columns: repeat(7, minmax(100px, 1fr));
    gap: 10px;
}

.status-stat {
    padding: 13px;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
}

.status-stat:hover {
    border-color: #9eb2bf;
    color: var(--text);
}

.status-stat strong {
    display: block;
    margin-top: 11px;
    font-size: 24px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--pending-bg);
    color: var(--pending);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.status-success {
    background: var(--success-bg);
    color: var(--success);
}

.status-failed,
.status-dead {
    background: var(--danger-bg);
    color: var(--danger);
}

.status-pending {
    background: var(--pending-bg);
    color: var(--pending);
}

.status-retrying {
    background: var(--warning-bg);
    color: var(--warning);
}

.status-processing {
    background: #e5effa;
    color: #285b8c;
}

.status-muted {
    background: #edf1f3;
    color: #60717c;
}

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

.bar-chart {
    height: 238px;
    padding-top: 20px;
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    gap: 10px;
}

.bar-column {
    min-width: 36px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.bar-value {
    height: 20px;
    color: var(--muted);
    font-size: 11px;
}

.bar-track {
    position: relative;
    flex: 1;
    width: 100%;
    max-width: 34px;
    background: #edf1f3;
    border-radius: 4px 4px 0 0;
    display: flex;
    align-items: flex-end;
    overflow: hidden;
}

.bar-fill {
    width: 100%;
    min-height: 4px;
    background: #2c83a8;
}

.bar-column span {
    margin-top: 8px;
    color: var(--muted);
    font-size: 11px;
}

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

.data-table,
.compact-table table {
    width: 100%;
    border-collapse: collapse;
}

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

.data-table th,
.compact-table th {
    background: #f5f8f9;
    color: #5d6c77;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.data-table tbody tr:hover {
    background: #fafcfd;
}

.data-table td small,
.callback-table td small {
    display: block;
    margin-top: 5px;
    color: var(--muted);
}

.callback-table {
    min-width: 1080px;
}

.breakable {
    max-width: 310px;
    word-break: break-all;
}

.truncate {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.error-summary {
    display: block;
    max-width: 290px;
    overflow: hidden;
    color: var(--danger);
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.row-actions form {
    margin: 0;
}

.empty-state {
    padding: 30px 18px;
    border: 1px dashed #c7d2d9;
    border-radius: 6px;
    background: #fafcfd;
    color: var(--muted);
    text-align: center;
}

.pagination {
    margin-top: 18px;
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.pagination a {
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.pagination a.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

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

.filter-actions {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.field {
    display: block;
}

.field > span {
    display: block;
    margin-bottom: 7px;
    font-weight: 700;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    border: 1px solid #c5d0d7;
    border-radius: 6px;
    background: #fff;
    color: var(--text);
}

.field textarea {
    resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: 2px solid #bde0eb;
    border-color: var(--primary);
}

.field small {
    display: block;
    margin-top: 5px;
    color: var(--muted);
    line-height: 1.5;
}

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

.checkbox-field {
    min-height: 44px;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface-soft);
    display: grid;
    grid-template-columns: 18px 1fr;
    gap: 8px 10px;
    align-items: center;
}

.checkbox-field input {
    width: 16px;
    min-height: 16px;
}

.checkbox-field span {
    margin: 0;
}

.checkbox-field small {
    grid-column: 2;
    margin: 0;
}

.stack-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.inline-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.inline-form .field {
    flex: 1;
}

.form-actions,
.sticky-actions {
    margin-top: 18px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 8;
    margin: 0;
    padding: 13px 16px;
    background: rgba(255, 255, 255, .96);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.mapping-block {
    border-left: 3px solid #7ba9be;
}

.detail-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
}

.detail-heading h2 {
    margin: 12px 0 6px;
    font-size: 22px;
}

.detail-summary {
    margin: 0;
    display: flex;
    gap: 26px;
}

.detail-summary div {
    min-width: 90px;
}

.detail-summary dt,
.definition-list dt {
    color: var(--muted);
    font-size: 12px;
}

.detail-summary dd {
    margin: 5px 0 0;
    font-size: 17px;
    font-weight: 700;
}

.definition-list {
    margin: 0;
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
}

.definition-list dt,
.definition-list dd {
    min-height: 40px;
    margin: 0;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.definition-list dd {
    word-break: break-word;
}

.code-block,
.inline-code {
    margin: 0;
    padding: 16px;
    overflow: auto;
    background: #102a3a;
    border: 1px solid #24495c;
    border-radius: 6px;
    color: #dceaf0;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
}

.inline-code {
    color: #274252;
    background: #edf1f4;
    border-color: var(--line);
}

.secret-panel {
    border-left: 4px solid #d18a14;
}

.copy-row {
    display: flex;
    align-items: stretch;
    gap: 9px;
}

.copy-row code {
    flex: 1;
    min-height: 44px;
    padding: 12px;
    border: 1px solid var(--line);
    display: flex;
    align-items: center;
    overflow-wrap: anywhere;
}

.check-list {
    border-top: 1px solid var(--line);
}

.check-list > div {
    min-height: 47px;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.check-list small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    word-break: break-all;
}

.danger-zone {
    border-color: #e6aaa5;
}

.empty-page {
    padding: 48px 24px;
    text-align: center;
}

.empty-page > strong {
    color: #8ca0ac;
    font-size: 48px;
}

.empty-page h2 {
    margin: 8px 0;
}

.empty-page p {
    margin: 0 0 20px;
    color: var(--muted);
}

.login-page {
    background: #edf1f3;
}

.login-wrap {
    min-height: 100vh;
    padding: 32px;
    display: grid;
    grid-template-columns: minmax(310px, 480px) minmax(340px, 430px);
    align-items: center;
    justify-content: center;
    gap: 34px;
}

.login-intro {
    padding: 34px;
    color: #fff;
    background: var(--nav);
    border-radius: 8px;
}

.login-intro h1 {
    margin: 22px 0 12px;
    font-size: 30px;
}

.login-intro > p {
    margin: 0;
    color: #c3d4dd;
    line-height: 1.75;
}

.login-intro dl {
    margin: 32px 0 0;
    border-top: 1px solid rgba(255, 255, 255, .15);
}

.login-intro dl div {
    padding: 14px 0;
    border-bottom: 1px solid rgba(255, 255, 255, .15);
    display: flex;
    justify-content: space-between;
    gap: 15px;
}

.login-intro dt {
    color: #9eb6c1;
}

.login-intro dd {
    margin: 0;
    font-weight: 700;
}

.login-panel {
    padding: 30px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.login-panel-head {
    margin-bottom: 22px;
}

.login-panel-head h2 {
    margin: 0 0 7px;
}

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

.health-link {
    display: block;
    margin-top: 18px;
    text-align: center;
    font-size: 12px;
}

@media (max-width: 1180px) {
    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .status-strip {
        grid-template-columns: repeat(4, minmax(100px, 1fr));
    }

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

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .18s ease;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 12px 0 32px rgba(17, 41, 55, .25);
    }

    .main-area {
        margin-left: 0;
    }

    .mobile-menu {
        min-height: 36px;
        padding: 0 12px;
        border: 1px solid var(--line);
        border-radius: 6px;
        background: #fff;
        display: inline-flex;
        align-items: center;
        cursor: pointer;
    }

    .topbar {
        padding: 13px 18px;
    }

    .content {
        padding: 18px;
    }

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

    .login-wrap {
        grid-template-columns: minmax(0, 520px);
    }

    .login-intro {
        display: none;
    }
}

@media (max-width: 680px) {
    .topbar {
        align-items: flex-start;
    }

    .topbar h1 {
        font-size: 18px;
    }

    .admin-chip {
        min-width: 0;
    }

    .admin-chip span {
        max-width: 110px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .metric-grid,
    .status-strip,
    .filter-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .metric {
        min-height: 112px;
    }

    .toolbar-row,
    .page-actions,
    .detail-heading,
    .panel-head {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar-row .button,
    .page-actions .button,
    .page-actions form,
    .page-actions form .button {
        width: 100%;
    }

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

    .detail-summary div {
        min-width: 0;
        padding: 10px;
        background: var(--surface-soft);
        border-radius: 6px;
    }

    .definition-list {
        grid-template-columns: 1fr;
    }

    .definition-list dt {
        min-height: auto;
        padding-bottom: 2px;
        border-bottom: 0;
    }

    .definition-list dd {
        min-height: 38px;
        padding-top: 2px;
    }

    .inline-form,
    .copy-row {
        align-items: stretch;
        flex-direction: column;
    }

    .form-actions,
    .sticky-actions {
        flex-direction: column-reverse;
    }

    .form-actions .button,
    .sticky-actions .button {
        width: 100%;
    }

    .filter-actions {
        flex-direction: column;
    }

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

    .login-page {
        padding: 16px;
    }

    .login-wrap {
        min-height: calc(100vh - 32px);
        padding: 0;
    }

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