:root {
    color-scheme: light;
    font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
    --bg: #f5f7fb;
    --panel: #ffffff;
    --line: #dfe5ef;
    --text: #172033;
    --muted: #65728a;
    --accent: #176b87;
    --accent-dark: #0f5067;
    --ok: #0f7b53;
    --error: #b3261e;
    --warn-bg: #fff7e1;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
}

.shell {
    width: min(1440px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 40px;
}

.topbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 16px;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 28px;
    line-height: 1.25;
}

.topbar p {
    margin-top: 6px;
    color: var(--muted);
}

.filters {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
}

input,
select,
button {
    height: 38px;
    border-radius: 6px;
    font: inherit;
}

input,
select {
    min-width: 150px;
    border: 1px solid var(--line);
    padding: 0 10px;
    color: var(--text);
    background: #fff;
}

button {
    border: 0;
    padding: 0 18px;
    color: #fff;
    background: var(--accent);
    cursor: pointer;
}

button:hover {
    background: var(--accent-dark);
}

.secondary-button {
    height: 34px;
    padding: 0 12px;
    color: var(--accent);
    background: #e8f3f7;
}

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

.link-button {
    height: auto;
    padding: 0;
    color: var(--accent);
    background: transparent;
    border: 0;
    border-radius: 0;
    font: inherit;
    text-align: left;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.link-button:hover {
    color: var(--accent-dark);
    background: transparent;
}

.account {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    white-space: nowrap;
}

.account form {
    margin: 0;
}

.status {
    min-height: 42px;
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--warn-bg);
    color: #654b00;
}

.status.ok {
    background: #e8f6ef;
    color: var(--ok);
}

.status.error {
    background: #fdecea;
    color: var(--error);
}

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

.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    padding: 6px;
    overflow-x: auto;
    background: #e9eef5;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.tab {
    height: 36px;
    flex: 0 0 auto;
    padding: 0 16px;
    color: var(--muted);
    background: transparent;
    border-radius: 6px;
}

.tab:hover,
.tab.active {
    color: #fff;
    background: var(--accent);
}

.tab:focus-visible {
    outline: 2px solid var(--accent-dark);
    outline-offset: 2px;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

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

.metric {
    min-height: 118px;
    padding: 18px;
    display: grid;
    gap: 10px;
}

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

.metric strong {
    font-size: 30px;
    line-height: 1;
}

.metric b {
    color: var(--text);
    font-weight: 600;
}

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

.panel {
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

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

.retention-panel {
    margin-bottom: 16px;
}

.subscription-list-panel {
    margin-bottom: 16px;
}

.retention-table th,
.retention-table td {
    text-align: left;
}

.retention-table td.num,
.retention-table th.num {
    text-align: left;
}

.table-wrap {
    overflow: auto;
    max-height: 360px;
}

.table-wrap.tall {
    max-height: 520px;
}

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

th,
td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
}

th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f8fafc;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

td.num,
th.num {
    text-align: right;
}

tbody tr:hover {
    background: #f6fbfd;
}

tbody tr.notice-overdue {
    background: #fff7ed;
}

tbody tr.notice-overdue:hover {
    background: #ffedd5;
}

.notice-time {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.notice-badge {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    color: #9a3412;
    background: #ffedd5;
    border: 1px solid #fed7aa;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.empty {
    height: 96px;
    text-align: center;
    color: var(--muted);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(23, 32, 51, 0.45);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-panel {
    width: min(1180px, 100%);
    max-height: min(760px, calc(100vh - 48px));
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(23, 32, 51, 0.24);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.modal-head h2 {
    font-size: 17px;
}

.modal-head p {
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
}

.modal-table-wrap {
    max-height: calc(min(760px, 100vh - 48px) - 76px);
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: var(--bg);
}

.login-shell {
    width: min(420px, calc(100% - 32px));
}

.login-panel {
    display: grid;
    gap: 18px;
    padding: 28px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.login-panel h1 {
    font-size: 24px;
}

.login-panel p {
    margin-top: 8px;
    color: var(--muted);
}

.login-panel input {
    width: 100%;
}

.login-panel button {
    width: 100%;
}

.login-error {
    padding: 10px 12px;
    color: var(--error);
    background: #fdecea;
    border: 1px solid #f3c7c2;
    border-radius: 6px;
}

@media (max-width: 1100px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .filters {
        flex-wrap: wrap;
    }

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

@media (max-width: 700px) {
    .shell {
        width: min(100% - 14px, 1440px);
        padding-top: 10px;
    }

    .filters,
    .metrics,
    .grid {
        grid-template-columns: 1fr;
    }

    .filters {
        display: grid;
    }

    .tabs {
        position: sticky;
        top: 0;
        z-index: 5;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        margin: 0 -2px 12px;
        padding: 8px;
        overflow: visible;
        box-shadow: 0 8px 18px rgba(23, 32, 51, 0.08);
    }

    .tab {
        width: 100%;
        height: 44px;
        padding: 0 8px;
        font-size: 15px;
        font-weight: 600;
        background: #fff;
        border: 1px solid var(--line);
    }

    input,
    select,
    button {
        width: 100%;
    }

    h1 {
        font-size: 23px;
    }
}
