/*
 * 「朱印」主题（参考 auth 统一认证中心）：宣纸底、墨色字、靛青强调、朱砂印记。
 * 主操作用墨色，朱砂只留给品牌印章与危险操作。
 */

/* ========== Design tokens ========== */
:root {
    --bg: #f4efe4;
    --surface: #fbf8f1;
    --surface-2: #ede6d6;
    --border: #ddd4c0;
    --border-strong: #c4b9a1;
    --text: #1d1a16;
    --text-2: #574f43;
    --text-3: #766c5d;
    --accent: #1f5868;
    --accent-hover: #163f4b;
    --accent-soft: #dce8e6;
    --ink: #1d1a16;
    --ink-hover: #3a332a;
    --ink-text: #f8f4ea;
    --seal: #c0392b;
    --seal-text: #fff8ee;
    --success: #35704e;
    --success-soft: #e0ebdc;
    --danger: #b3261e;
    --danger-soft: #f5dfd8;
    --warning: #8f5a0e;
    --warning-soft: #f4e6c8;
    --focus: 0 0 0 3px rgba(31, 88, 104, .25);
    --shadow: 0 1px 0 rgba(60, 45, 20, .04), 0 8px 24px -12px rgba(60, 45, 20, .18);
    --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .25  0 0 0 0 .18  0 0 0 0 .08  0 0 0 .1 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
    --radius: 8px;
    --radius-sm: 6px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
    --display: "Kaiti SC", "STKaiti", "KaiTi", "楷体", "Songti SC", serif;
    --numeric: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --mono: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas, monospace;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #141210;
    --surface: #1c1916;
    --surface-2: #26221d;
    --border: #332e27;
    --border-strong: #4b4439;
    --text: #ece5d6;
    --text-2: #b9af9c;
    --text-3: #8f8676;
    --accent: #86bcc7;
    --accent-hover: #a6d0d9;
    --accent-soft: #1b2f34;
    --ink: #ece5d6;
    --ink-hover: #fffaf0;
    --ink-text: #1d1a16;
    --seal: #d4503d;
    --success: #86c29a;
    --success-soft: #1a2a1f;
    --danger: #ee7c6c;
    --danger-soft: #331a18;
    --warning: #dcaa55;
    --warning-soft: #2e2413;
    --focus: 0 0 0 3px rgba(134, 188, 199, .3);
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 28px -12px rgba(0, 0, 0, .6);
    --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1  0 0 0 0 .95  0 0 0 0 .85  0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg: #141210;
        --surface: #1c1916;
        --surface-2: #26221d;
        --border: #332e27;
        --border-strong: #4b4439;
        --text: #ece5d6;
        --text-2: #b9af9c;
        --text-3: #8f8676;
        --accent: #86bcc7;
        --accent-hover: #a6d0d9;
        --accent-soft: #1b2f34;
        --ink: #ece5d6;
        --ink-hover: #fffaf0;
        --ink-text: #1d1a16;
        --seal: #d4503d;
        --success: #86c29a;
        --success-soft: #1a2a1f;
        --danger: #ee7c6c;
        --danger-soft: #331a18;
        --warning: #dcaa55;
        --warning-soft: #2e2413;
        --focus: 0 0 0 3px rgba(134, 188, 199, .3);
        --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 28px -12px rgba(0, 0, 0, .6);
        --grain: none;
        color-scheme: dark;
    }
}

/* ========== Base ========== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg) var(--grain);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-family: var(--display); font-size: 32px; font-weight: 400; letter-spacing: .02em; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
code { color: var(--text-2); }
::selection { background: var(--seal); color: var(--seal-text); }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); font-size: 13px; }
.right { text-align: right; }

/* ========== Forms ========== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }
.input, select.input, textarea.input {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 76px; padding: 10px 12px; font-family: var(--mono); font-size: 12.5px; resize: vertical; }
.input::placeholder { color: var(--text-3); }
.input:hover { border-color: var(--text-3); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input-sm { height: 34px; padding: 0 10px; font-size: 13px; }

.check {
    display: flex; align-items: center; gap: 8px;
    font-size: 13.5px; color: var(--text-2); cursor: pointer;
    padding: 4px 0;
}
.check input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); flex: none; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 18px;
    font: inherit;
    font-weight: 600;
    letter-spacing: .02em;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s, transform .08s;
}
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn-primary { background: var(--ink); color: var(--ink-text); }
.btn-primary:hover { background: var(--ink-hover); color: var(--ink-text); }
.btn-accent { background: var(--accent); color: #fff8ee; }
.btn-accent:hover { background: var(--accent-hover); color: #fff8ee; }
.btn-secondary { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-3); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-icon { width: 36px; height: 36px; padding: 0; }

.divider {
    display: flex; align-items: center; gap: 14px;
    margin: 20px 0; color: var(--text-3); font-size: 12px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* ========== Alerts & badges ========== */
.alert {
    display: flex; gap: 10px; align-items: flex-start;
    padding: 10px 14px; margin-bottom: 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    border-left: 3px solid currentColor;
}
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-info { background: var(--accent-soft); color: var(--accent); }
.alert[hidden] { display: none; }

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    height: 22px; padding: 0 8px;
    font-size: 12px; font-weight: 600;
    border-radius: 4px;
    background: var(--surface-2); color: var(--text-2);
    white-space: nowrap;
}
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ========== Logo：朱砂白文印 ========== */
.logo { display: inline-flex; align-items: center; gap: 10px; color: inherit; }
.logo:hover { text-decoration: none; color: inherit; }
.logo-text { font-family: var(--display); font-size: 19px; letter-spacing: .06em; }
.logo-mark {
    position: relative; flex: none;
    width: 32px; height: 32px; border-radius: 5px;
    display: grid; place-items: center;
    background: var(--seal); color: var(--seal-text);
    font-family: var(--display); font-size: 19px; line-height: 1;
}
.logo-mark::after {
    content: ""; position: absolute; inset: 3px;
    border: 1px solid color-mix(in srgb, var(--seal-text) 55%, transparent); border-radius: 2px;
}

/* ========== Auth Login Shell ========== */
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(380px, 46%) 1fr; }
.auth-shell[hidden] { display: none; }

.auth-brand {
    position: relative; overflow: hidden; isolation: isolate;
    display: flex; flex-direction: column; justify-content: space-between;
    padding: 44px 56px;
    border-right: 1px solid rgba(236, 229, 214, .07);
    background: linear-gradient(180deg, #171411 0%, #1f1b17 45%, #2b2620 100%);
    color: #ece5d6;
}
.auth-brand .scene { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 68%; z-index: -1; }
.auth-brand .brand-vertical {
    position: absolute; top: 48px; right: 44px;
    writing-mode: vertical-rl; letter-spacing: .55em;
    font-family: var(--display); font-size: 15px; color: rgba(236, 229, 214, .5);
}
.auth-brand .brand-vertical::after { content: ""; display: block; width: 1px; height: 56px; margin: 14px auto 0; background: rgba(236, 229, 214, .25); }
.auth-brand .brand-copy { margin-top: -6vh; }
.auth-brand h1 { font-size: 46px; line-height: 1.3; letter-spacing: .08em; color: #f8f4ea; margin-bottom: 18px; }
.auth-brand .lead { color: #b9af9c; font-size: 15px; max-width: 320px; line-height: 1.8; }
.feature-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 28px; }
.feature-list li { display: flex; gap: 8px; align-items: center; color: #d8cfbd; font-size: 13px; }
.feature-list svg { width: 16px; height: 16px; color: #e0705c; flex: none; }
.auth-brand footer { display: flex; flex-direction: column; gap: 18px; color: #8f8676; font-size: 12px; }

.auth-main { position: relative; display: flex; align-items: center; justify-content: center; padding: 56px 24px; }
.auth-main > .theme-toggle { position: absolute; top: 20px; right: 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card > header { margin-bottom: 28px; }
.auth-card > header h1 { font-size: 34px; }
.auth-card > header p { margin-top: 8px; color: var(--text-2); }
.auth-mobile-logo { display: none; margin-bottom: 32px; }
.auth-details { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.auth-details summary { cursor: pointer; font-size: 13px; color: var(--text-2); font-weight: 500; }

/* ========== App layout ========== */
.console-shell[hidden] { display: none; }
.topbar {
    position: sticky; top: 0; z-index: 10;
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1180px; margin: 0 auto; height: 64px; padding: 0 24px; display: flex; align-items: center; gap: 28px; }
.topnav { display: flex; gap: 22px; flex: 1; align-self: stretch; overflow-x: auto; scrollbar-width: none; }
.topnav button {
    position: relative; display: flex; align-items: center;
    background: none; border: 0; padding: 0 2px; cursor: pointer;
    font: inherit; color: var(--text-2); font-weight: 500; white-space: nowrap;
}
.topnav button:hover { color: var(--text); }
.topnav button.active { color: var(--text); font-weight: 600; }
.topnav button.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--seal); }

.user-chip { display: flex; align-items: center; gap: 8px; flex: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex: none; }
.dot.on { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.avatar {
    width: 30px; height: 30px; border-radius: 50%;
    display: grid; place-items: center; flex: none;
    background: var(--ink); color: var(--ink-text);
    font-weight: 600; font-size: 12px; text-transform: uppercase;
}

.page { max-width: 1180px; margin: 0 auto; padding: 36px 24px 72px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.page-head p { color: var(--text-2); margin-top: 6px; }

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

.stack { display: grid; gap: 22px; min-width: 0; }
.stack > *, .grid-2 > * { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--border); }
.card-head h2 { display: flex; align-items: center; gap: 10px; }
.card-head h2::before { content: ""; width: 3px; height: 15px; border-radius: 1px; background: var(--seal); }
.card-head p { color: var(--text-3); font-size: 13px; margin: 3px 0 0 13px; }
.card-body { padding: 22px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { padding: 18px 20px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.stat .label { color: var(--text-3); font-size: 13px; padding-bottom: 4px; }
.stat .value { font-family: var(--numeric); font-size: 36px; line-height: 1; font-variant-numeric: lining-nums tabular-nums; }
.stat .unit { font-size: 14px; color: var(--text-3); margin-left: 2px; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 11px 18px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--text-3); border-bottom-color: var(--border-strong); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
td .actions { display: flex; gap: 6px; justify-content: flex-end; }
td .badge + .badge { margin-left: 4px; }

/* ========== Charts & Gateway widgets ========== */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 84px; padding-top: 8px; }
.bars i { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; transition: height .2s; }
.seg { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.legend { display: flex; gap: 18px; margin-top: 10px; color: var(--text-2); font-size: 12.5px; flex-wrap: wrap; }

.code-block {
    margin: 8px 0 0; padding: 12px 14px; overflow: auto; max-height: 280px;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text); line-height: 1.55; white-space: pre-wrap; word-break: break-all;
}

.step-card { padding: 18px 22px; }
.step-card h3 { font-size: 15px; margin-bottom: 4px; }
.step-card p { color: var(--text-2); margin-bottom: 12px; font-size: 13.5px; }
.res-row { display: flex; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; flex-wrap: wrap; }
.res-row + .res-row { border-top: 1px dashed var(--border); }
.res-ok { color: var(--success); font-weight: 700; }
.res-bad { color: var(--danger); font-weight: 700; }
details summary { cursor: pointer; color: var(--text-3); font-size: 12.5px; }

.s2 { color: var(--success); }
.s3 { color: var(--accent); }
.s4 { color: var(--warning); }
.s5 { color: var(--danger); }

.toast {
    position: fixed; right: 24px; bottom: 24px; z-index: 40;
    background: var(--ink); color: var(--ink-text);
    padding: 10px 18px; border-radius: var(--radius-sm);
    box-shadow: var(--shadow); font-size: 13.5px; font-weight: 500;
    display: none;
}

@media (max-width: 900px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-brand { display: none; }
    .auth-mobile-logo { display: block; }
    .auth-main { align-items: flex-start; padding: 44px 20px; }
    .topbar-inner { padding: 0 16px; gap: 14px; }
    .topbar .logo-text { display: none; }
    .page { padding: 24px 16px 56px; }
    .grid-2, .form-grid { grid-template-columns: 1fr; }
    .page-head { flex-direction: column; align-items: flex-start; }
    th, td { padding: 10px 12px; }
}
