:root {
    --bg: #f6f8fb;
    --card: #ffffff;
    --border: #e5e9f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-soft: #eff6ff;
    --up: #dc2626;
    --up-bg: #fef2f2;
    --down: #16a34a;
    --down-bg: #f0fdf4;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 30px rgba(15, 23, 42, .06);
    --radius: 16px;
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
    outline: 2px solid rgba(37, 99, 235, .45);
    outline-offset: 2px;
}

/* ---------------- 顶栏 ---------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255, 255, 255, .86);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}

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

.logo {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #2563eb, #4f46e5);
    color: #fff;
    font-size: 17px;
    font-weight: 800;
    box-shadow: 0 6px 14px rgba(37, 99, 235, .25);
}

.brand-text h1 {
    margin: 0;
    font-size: 17px;
    line-height: 1.2;
    letter-spacing: .01em;
}

.date-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 auto;
}

.date-field {
    display: inline-flex;
    align-items: center;
    height: 36px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
}

.date-field input {
    width: 138px;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}

.icon-btn {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

.icon-btn:hover {
    background: #f1f5f9;
}

.btn {
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s, border-color .15s, opacity .15s;
    white-space: nowrap;
}

.btn:hover {
    background: #f1f5f9;
}

.btn.ghost {
    background: transparent;
}

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

.btn.primary:hover {
    background: #1d4ed8;
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.btn[hidden] {
    display: none;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.weekday {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

.refresh-icon {
    font-size: 15px;
    line-height: 1;
}

/* ---------------- 主体 ---------------- */

.container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 18px 20px 8px;
}

.status {
    min-height: 20px;
    margin-bottom: 10px;
    font-size: 12px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.status.ok::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22c55e;
    flex-shrink: 0;
}

.status.error {
    color: var(--up);
}

.status.loading {
    color: var(--primary);
}

/* ---------------- 面板 ---------------- */

.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    overflow: hidden;
}

.panel-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px 12px;
    padding: 11px 18px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #ffffff, #fbfdff);
    font-size: 12px;
    color: var(--muted);
}

.legend {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
}

.legend .up {
    color: var(--up);
    font-weight: 800;
}

.legend .down {
    color: var(--down);
    font-weight: 800;
}

/* ---------------- 费率矩阵 ---------------- */

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.rate-table {
    width: 100%;
    min-width: 560px;
    --group-col: 88px;
    --channel-col: 148px;
    border-collapse: separate;
    border-spacing: 0;
}

.rate-table th,
.rate-table td {
    padding: 9px 12px;
    text-align: center;
    white-space: nowrap;
}

.rate-table thead th {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    background: #fbfdff;
    border-bottom: 1px solid var(--border);
}

.rate-table thead th .time {
    display: block;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--text);
}

.rate-table thead th .time-note {
    display: block;
    margin-top: 2px;
    font-size: 10px;
    font-weight: 600;
    color: #94a3b8;
}

.rate-table thead th.latest {
    background: var(--primary-soft);
}

.rate-table thead th.latest .time {
    color: var(--primary);
}

.rate-table thead th.latest .time-note {
    color: var(--primary);
}

.group-head,
.group-cell {
    position: sticky;
    left: 0;
    z-index: 3;
    width: var(--group-col);
    min-width: var(--group-col);
    background: #f8fafc;
    box-shadow: 1px 0 0 var(--border);
}

.group-head {
    z-index: 4;
    color: var(--primary);
    font-weight: 700;
}

.group-cell {
    vertical-align: middle;
    padding: 8px 6px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.35;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
}

.channel-head,
.channel-cell {
    position: sticky;
    left: var(--group-col);
    z-index: 2;
    width: var(--channel-col);
    min-width: var(--channel-col);
    text-align: left;
    background: var(--card);
    box-shadow: 1px 0 0 var(--border);
}

.channel-head {
    z-index: 3;
    background: #fbfdff;
    padding-left: 18px;
}

.channel-cell {
    padding-left: 18px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    border-bottom: 1px solid #f1f5f9;
}

.channel-cell.has-tip {
    cursor: help;
    text-decoration: underline dotted rgba(100, 116, 139, .45);
    text-underline-offset: 3px;
}

.rate-table tbody tr:nth-child(even) .channel-cell,
.rate-table tbody tr:nth-child(even) .rate-cell {
    background: #fafbfd;
}

.rate-cell {
    min-width: 82px;
    font-size: 14px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    border-bottom: 1px solid #f1f5f9;
}

.rate-cell.latest {
    background: #f5f9ff;
}

.rate-cell.up {
    color: var(--up);
    background: var(--up-bg);
}

.rate-cell.down {
    color: var(--down);
    background: var(--down-bg);
}

.rate-table tbody tr.group-end .channel-cell,
.rate-table tbody tr.group-end .rate-cell {
    border-bottom-color: var(--border);
}

.no-value {
    color: #cbd5e1;
    font-weight: 400;
}

.rate-table tbody tr:hover .channel-cell,
.rate-table tbody tr:hover .rate-cell {
    background: #f1f5f9;
}

.rate-table tbody tr:hover .rate-cell.up {
    background: #fee2e2;
}

.rate-table tbody tr:hover .rate-cell.down {
    background: #dcfce7;
}

/* ---------------- 访问口令 ---------------- */

.gate {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(246, 248, 251, .86);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.gate[hidden] {
    display: none;
}

.gate-card {
    width: min(360px, 100%);
    padding: 30px 26px 22px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--card);
    box-shadow: 0 24px 60px rgba(15, 23, 42, .16);
    text-align: center;
}

.gate-logo {
    width: 46px;
    height: 46px;
    margin: 0 auto 14px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #2563eb, #4f46e5);
    color: #fff;
    font-size: 20px;
    font-weight: 800;
    box-shadow: 0 8px 18px rgba(37, 99, 235, .25);
}

.gate-card h2 {
    margin: 0 0 6px;
    font-size: 20px;
    letter-spacing: .01em;
}

.gate-hint {
    margin: 0 0 18px;
    font-size: 12px;
    color: var(--muted);
}

.gate-input {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--card);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.gate-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.gate-input:focus-visible {
    outline: none;
}

.gate-submit {
    width: 100%;
    height: 44px;
    margin-top: 12px;
    font-size: 14px;
}

.gate-error {
    min-height: 18px;
    margin: 10px 0 0;
    font-size: 12px;
    line-height: 1.4;
    color: var(--up);
}

/* ---------------- 悬停额度 ---------------- */

.tooltip {
    position: fixed;
    z-index: 100;
    max-width: 240px;
    padding: 6px 10px;
    border-radius: 8px;
    background: #0f172a;
    color: #fff;
    font-size: 12px;
    line-height: 1.5;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .25);
}

.tooltip[hidden] {
    display: none;
}

/* ---------------- 空 / 错误 / 骨架 ---------------- */

.empty {
    padding: 42px 20px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

.empty-icon {
    font-size: 26px;
    line-height: 1;
    margin-bottom: 8px;
    color: #cbd5e1;
}

.empty-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.empty-hint {
    margin-top: 4px;
    font-size: 12px;
    color: #94a3b8;
}

.error-panel {
    border-color: #fecaca;
}

.error-body {
    padding: 26px 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 9px;
}

.error-body h2 {
    margin: 0;
    font-size: 18px;
}

.error-msg {
    margin: 0;
    color: var(--up);
    font-size: 13px;
    word-break: break-word;
}

.error-hint {
    margin: 0;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.6;
}

code {
    padding: 1px 5px;
    border-radius: 5px;
    background: #f1f5f9;
    border: 1px solid var(--border);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
}

.skeleton-panel {
    overflow: hidden;
}

.sk-bar {
    height: 42px;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
    animation: pulse 1.4s ease-in-out infinite;
}

.sk-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    border-bottom: 1px solid #f1f5f9;
}

.sk-row span {
    height: 14px;
    border-radius: 6px;
    background: #eef2f7;
    animation: pulse 1.4s ease-in-out infinite;
}

.sk-row span:first-child {
    width: 110px;
    flex-shrink: 0;
}

.sk-row span:not(:first-child) {
    flex: 1;
}

@keyframes pulse {
    0%,
    100% {
        opacity: .55;
    }
    50% {
        opacity: 1;
    }
}

/* ---------------- 页脚 ---------------- */

.footer {
    max-width: 1180px;
    margin: 0 auto;
    padding: 10px 20px 28px;
    font-size: 11px;
    color: #94a3b8;
    text-align: center;
}

/* ---------------- 响应式 ---------------- */

@media (max-width: 760px) {
    .topbar-inner {
        padding: 10px 14px;
        gap: 10px;
    }

    .date-nav {
        order: 3;
        width: 100%;
        margin: 0;
        justify-content: center;
    }

    .top-actions {
        margin-left: auto;
    }

    .weekday {
        display: none;
    }

    .container {
        padding: 14px 14px 6px;
    }

    .panel-bar {
        padding: 10px 14px;
        font-size: 11px;
    }

    .rate-table {
        min-width: 460px;
        --group-col: 56px;
        --channel-col: 104px;
    }

    .rate-table th,
    .rate-table td {
        padding: 8px 10px;
    }

    .channel-head,
    .channel-cell {
        padding-left: 12px;
    }

    .group-cell {
        padding: 6px 4px;
        font-size: 10px;
    }

    .rate-table thead th .time {
        font-size: 12px;
    }

    .rate-cell {
        min-width: 70px;
        font-size: 13px;
    }

    .footer {
        padding-bottom: 20px;
    }
}

@media (max-width: 420px) {
    .date-field input {
        width: 126px;
    }

    .btn {
        padding: 0 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}
