/* Split from the original single style.css; the style-*.css files continue
   this sheet in the load order defined by index.html. */
/* ── Reset & base ──────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

:root {
    /* Tells the browser to render native controls (date picker icon and popup,
       scrollbars, autofill) in dark — without this they stay light regardless of
       our own colours, which is why the calendar icon looked black. */
    color-scheme: dark;

    /* colours — dark (default) */
    --bg: #0f1117;
    --bg-2: #181c27;
    --bg-3: #1e2335;
    --border: #2a2f45;
    --text: #e2e8f0;
    --text-muted: #8892a4;
    --accent: #6366f1;
    --accent-h: #818cf8;
    --ok: #22c55e;
    --fail: #ef4444;
    /* Softer siblings of the two above. --ok/--fail are tuned for a 13px pill;
       at the heading size the forwarding summary uses, the same vivid values
       shout, so that line takes these instead. */
    --ok-soft: #86efac;
    --fail-soft: #fca5a5;
    --warn: #f59e0b;
    --shadow: 0 4px 32px rgba(0, 0, 0, 0.5);

    /* typography */
    --font: "Microsoft YaHei", "Segoe UI", -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI Symbol", "Apple Color Emoji", "Segoe UI Emoji", monospace;
    --text-base: 16px;
    --text-sm: 14px;
    --text-xs: 14px;

    --line-num: #4a5270;
    /* line number gutter text */
    /* Occurrence marks in the keys textarea. Translucent on purpose: the text on
       top of the mark keeps the textarea's own colour, so the mark has to be
       strong enough to read as orange and dark enough to keep the glyphs legible
       — amber (#f59e0b) came out brown against --bg-2, this orange does not. */
    --mark-keys: rgba(234, 88, 12, 0.55);
    --mark-keys-current: rgba(234, 88, 12, 0.85);
    --radius: 10px;
    --radius-sm: 6px;
    /* Height of one single-line control. Single-line inputs and the small
       toolbar buttons that sit beside them both take this value, so a row of
       input + buttons reads as one band instead of stepping in size. */
    --control-h: 2.5rem;
}

/* Light theme overrides */
[data-theme="light"] {
    color-scheme: light;
    --bg: #f4f6fb;
    --bg-2: #ffffff;
    --bg-3: #eef0f7;
    --border: #d1d5e8;
    --text: #1a1f36;
    --text-muted: #5a6384;
    --line-num: #8a93aa;
    /* line number gutter text — light mode */
    --mark-keys: rgba(234, 88, 12, 0.45);
    --mark-keys-current: rgba(234, 88, 12, 0.68);
    /* The pale pair is unreadable on a white page, so light mode softens the
       other way: same hue, less saturation, still enough contrast to read. */
    --ok-soft: #2f8f5b;
    --fail-soft: #c2544f;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}

html {
    font-size: var(--text-base);
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    height: 100%;
    -webkit-font-smoothing: antialiased;
}

body {
    height: 100%;
    line-height: 1.6;
    overflow: hidden;
}

html.has-token #auth-overlay {
    display: none !important;
}

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

a:hover {
    text-decoration: underline;
}

button:focus,
button:focus-visible,
a:focus,
a:focus-visible,
[tabindex]:focus,
[tabindex]:focus-visible {
    outline: none;
}

/* ── Auth overlay ──────────────────────────────────────────────────────── */
.auth-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--bg);
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.auth-overlay.active {
    display: flex;
}

.auth-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: min(440px, 100%);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-card h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

.auth-card .muted {
    font-size: var(--text-sm);
    line-height: 1.7;
}

.auth-row {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.auth-row input {
    width: 100%;
    padding: 0.85rem 1rem;
    font-size: 1rem;
}

.auth-row .btn {
    align-self: stretch;
    padding: 0.85rem 1rem;
    font-size: 1rem;
}

/* ── App shell ─────────────────────────────────────────────────────────── */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ── Topbar ────────────────────────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1.5rem;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    gap: 1rem;
    flex-wrap: wrap;
}

.topbar h1 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 0.2rem;
}

.topbar-menu {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.topbar-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.hidden-desktop {
    display: none;
}

.topbar-menu-title {
    font-weight: 600;
}

/* Two classes on purpose: .btn-ghost and .btn-sm are declared further down the
   file, so a single-class rule here would lose to them on source order — which
   is what the style attribute this replaced used to win. */
.btn-ghost.topbar-menu-close,
.btn-sm.topbar-menu-close {
    border: none;
    padding: 0.2rem;
}

/* Theme toggle */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.65rem 0.75rem;
    line-height: 1;
    transition:
        border-color 0.15s,
        color 0.15s;
}

.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--text);
}

/* ── Tabs ──────────────────────────────────────────────────────────────── */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 0.65rem 1.25rem;
    font-size: var(--text-sm);
    font-family: var(--font);
    /* 常驻粗体：雅黑 Regular 的「效」等字形墨迹天生略高于相邻字，
     * 在 125%/150% 缩放的分数像素下会现形 1px 跳升；Bold 轮廓等高
     * 不会。未选／选中改以颜色与背景区分。 */
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition:
        color 0.15s,
        background 0.15s;
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--text);
    background: var(--bg-3);
}

.tab-btn.active {
    color: var(--accent-h);
    background: rgba(99, 102, 241, 0.1);
}

/* ── Workspace ─────────────────────────────────────────────────────────── */
.workspace-wrap {
    flex: 1;
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    scrollbar-gutter: stable;
    scrollbar-gutter: stable both-edges;
}

.workspace {
    padding: 2rem 1.5rem;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
}

.copy-btn {
    flex-shrink: 0;
    box-sizing: border-box;
}

.copy-btn.copied {
    color: var(--ok) !important;
}

.tab-panel {
    display: none;
}

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

.hidden {
    display: none !important;
}

/* ── Panel head ────────────────────────────────────────────────────────── */
.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 2rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.panel-head h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.panel-head .muted {
    font-size: var(--text-sm);
    margin-top: 0.25rem;
}

/* ── Result group collapsible ──────────────────────────────────────────── */
.result-group {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    overflow: clip;
}

.result-group-header {
    padding: 1rem 1.25rem;
    background: var(--bg-2);
    cursor: pointer;
    user-select: none;
}

.result-group-header:hover {
    background: var(--bg-3);
}

/* inner layout */
.rgh-main {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 0;
}

.rgh-top {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rgh-arrow {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-left: auto;
    transition: transform 0.2s;
    display: inline-block;
    flex-shrink: 0;
}

.result-group.open .rgh-arrow {
    transform: rotate(180deg);
}

.rgh-host {
    font-size: 1rem;
    font-weight: 600;
    word-break: break-all;
    min-width: 0;
}

.rgh-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.rgh-type {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-muted);
    min-width: 9.5ch;
}

.rgh-time {
    font-size: var(--text-sm);
}

.running-status {
    color: var(--warn);
    font-size: var(--text-sm);
    font-weight: 600;
    white-space: nowrap;
}

.provider-type-label {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-muted);
}

.result-group-body {
    display: none;
    padding: 1.25rem;
    background: var(--bg);
}

.result-group.open .result-group-body {
    display: block;
}

.result-section {
    margin-bottom: 2.5rem;
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.inv-group-sep {
    width: 1px;
    height: 1em;
    background: var(--border);
    flex-shrink: 0;
}

.group-count {
    font-size: var(--text-sm);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    min-width: 3ch;
    text-align: center;
    flex-shrink: 0;
}

.count-ok {
    color: var(--ok-soft);
}

.count-fail {
    color: var(--fail-soft);
}

.inv-group-code {
    font-size: var(--text-sm);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    min-width: 4ch;
    text-align: center;
    flex-shrink: 0;
}

/* ── Table ─────────────────────────────────────────────────────────────── */
.table-scroll {
    overflow-x: auto;
    overflow-y: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.table-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-3);
}

/* 失效密钥／请求记录不再用内部滚动轴：换页钮位于表格下方（靠右对齐，
 * 每页最多 10 笔），容器只在窄屏时保留横向滑动。末页不满时只显示实际
 * 列，表格与换页钮之间由 .table-pager-spacer（组件内量测高度差）补足
 * 留白，换页钮位置与满页完全一致。 */
.table-pager {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}

.table-pager .proxy-pagination {
    margin-top: 0;
    justify-content: flex-end;
}

#dk-table-wrap,
#logs-table-wrap {
    overflow-x: auto;
    overflow-y: visible;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

/* 没有 column-gap。栏与栏之间的视觉间隔 = 本格 padding-right + 下一格 padding-left。
 * 预设左右各 1rem，所以相邻两栏文字之间是 2rem，不是另有一份「栏间距」。 */
.data-table th {
    background: var(--bg-3);
    padding: 0.65rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: var(--bg-3);
}

.data-table th[data-sort] {
    cursor: pointer;
    user-select: none;
}

.data-table th[data-sort]:hover {
    color: var(--text);
}

/* Empty still occupies width so toggling ▲/▼ does not shift columns.
 * 编号栏内容区要能放下：label + margin-left + width。
 * 看起来偏低：▲ 的墨水在字框里偏下，vertical-align:middle 对的又是拉丁 x-height
 * 中线，中文「编号」视觉中心更高。往上挪用 transform（负值往上），不要改 padding。 */
.sort-indicator {
    display: inline-block;
    width: 1rem;
    margin-left: 0.6em;
    font-size: 1em;
    line-height: 1;
    color: var(--accent);
    text-align: center;
    vertical-align: middle;
    transform: translateY(-0.1em);
}

/* ── Invalid key groups (collapsible) ─────────────────────────────────── */
.inv-group {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.6rem;
    overflow: hidden;
}

.inv-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1.1rem;
    background: var(--bg-2);
    cursor: pointer;
    user-select: none;
    gap: 0.75rem;
}

.inv-group-header:hover {
    background: var(--bg-3);
}

.inv-group-title {
    font-size: var(--text-sm);
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inv-group-toggle {
    color: var(--text-muted);
    font-size: 0.75rem;
    flex-shrink: 0;
    transition: transform 0.2s;
    display: inline-block;
}

.inv-group.open .inv-group-toggle {
    transform: rotate(180deg);
}

.inv-group-body {
    display: none;
    padding: 0.85rem 1.1rem;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

.inv-group.open .inv-group-body {
    display: block;
}

.inv-key-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
    font-size: var(--text-sm);
}

.inv-key-item:last-child {
    border-bottom: none;
}

.inv-key-mono {
    font-family: var(--mono);
    color: var(--text);
    font-size: var(--text-xs);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

/* ── Scroll to top button ─────────────────────────────────────────────── */
.btn-scroll-top {
    position: fixed;
    right: 2.75rem;
    bottom: 3rem;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius-sm);
    background: var(--bg-card, var(--bg-2));
    border: 1px solid var(--border);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 0.2s ease, transform 0.2s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-scroll-top:hover {
    background: var(--bg-3);
    border-color: var(--border-h);
    color: var(--accent-h);
    transform: translateY(-2px);
}

.btn-scroll-top.is-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

@media (max-width: 640px) {
    .btn-scroll-top {
        right: 1.75rem;
        bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
    }
}
