/* ==========================================================================
   TOTP 门禁站 — 样式
   ========================================================================== */

:root {
    --bg:        #0a0c11;
    --bg-soft:   #0f1218;
    --card:      #12161f;
    --card-2:    #161b26;
    --line:      #232a38;
    --line-soft: #1b212c;
    --text:      #e9edf6;
    --muted:     #8a93a8;
    --muted-2:   #5f687c;
    --accent:    #5b8cff;
    --accent-2:  #8b5cff;
    --ok:        #2fbf71;
    --warn:      #ffb020;
    --bad:       #ff5c6c;
    --radius:    16px;
    --shadow:    0 24px 60px -30px rgba(0, 0, 0, .9);
}

* { box-sizing: border-box; }

/* 关键：让 hidden 属性胜过 .loading { display: flex } 这类类选择器 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    padding: 28px 16px 56px;
    font-family: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background:
        radial-gradient(900px 520px at 12% -12%, rgba(91, 140, 255, .16), transparent 62%),
        radial-gradient(760px 480px at 88% 0%, rgba(139, 92, 255, .13), transparent 62%),
        var(--bg);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
}

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

h1, h2 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.02rem; }

p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

code {
    font-family: ui-monospace, "SFMono-Regular", "JetBrains Mono", Consolas, "Courier New", monospace;
    font-size: .92em;
}

/* ---------- 布局 ---------- */

.wrap {
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
}

.wrap.wide { max-width: 1080px; }

.card {
    position: relative;
    padding: 26px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: linear-gradient(180deg, var(--card-2), var(--card));
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}

.card.narrow { padding: 30px 26px; }

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.card > h2 { margin-bottom: 14px; }

/* ---------- 品牌 ---------- */

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.brand h1 { font-size: 1.22rem; }

.dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 0 12px rgba(91, 140, 255, .8);
    flex: none;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    padding: 0 2px;
}

.topbar .brand { margin-bottom: 0; }

.lead {
    color: var(--muted);
    font-size: .93rem;
    margin-bottom: 20px;
}

/* ---------- 表单 ---------- */

.field { display: block; margin-bottom: 16px; }

.field > span {
    display: block;
    margin-bottom: 8px;
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"] {
    width: 100%;
    padding: 13px 15px;
    font: inherit;
    color: var(--text);
    background: #0b0e14;
    border: 1px solid var(--line);
    border-radius: 12px;
    outline: none;
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

input[type="text"]::placeholder,
input[type="password"]::placeholder { color: var(--muted-2); }

input:focus {
    border-color: rgba(91, 140, 255, .7);
    background: #0c1017;
    box-shadow: 0 0 0 4px rgba(91, 140, 255, .14);
}

/* 访问密码输入框：等宽 + 字距 */
input[name="password"][inputmode="latin"] {
    font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
    letter-spacing: .14em;
    text-transform: uppercase;
}

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

.field.compact { margin-bottom: 0; width: 110px; }
.field.compact.grow { width: auto; flex: 1 1 220px; }

.row-form .btn { height: 46px; }

form.inline { display: inline-flex; margin: 0; }

/* ---------- 按钮 ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    font: inherit;
    font-weight: 600;
    color: var(--text);
    background: var(--card-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    cursor: pointer;
    transition: transform .12s ease, background .18s ease, border-color .18s ease, box-shadow .18s ease;
    user-select: none;
}

.btn:hover { border-color: #2f394d; background: #1a2030; }
.btn:active { transform: translateY(1px); }

.btn.primary {
    color: #fff;
    border: none;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 12px 26px -14px rgba(91, 140, 255, .95);
}

.btn.primary:hover { filter: brightness(1.06); }

.btn.primary.copied {
    background: linear-gradient(135deg, #22a35f, #2fbf71);
    box-shadow: 0 12px 26px -14px rgba(47, 191, 113, .95);
}

.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(255, 255, 255, .04); }

.btn.danger { color: #ff8b96; border-color: #3a2129; background: transparent; }
.btn.danger:hover { background: rgba(255, 92, 108, .1); border-color: #5a2b34; }

.btn.small { padding: 7px 13px; font-size: .84rem; border-radius: 10px; }

.btn#copy, .btn.copy { width: 100%; margin-bottom: 16px; }

/* ---------- 提示 ---------- */

.alert {
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: .88rem;
    border: 1px solid var(--line);
    border-left-width: 3px;
    border-radius: 10px;
    background: #0d1118;
}

.alert.bad  { border-left-color: var(--bad);  color: #ffb3ba; background: rgba(255, 92, 108, .07); }
.alert.ok   { border-left-color: var(--ok);   color: #9be5bd; background: rgba(47, 191, 113, .07); }
.alert.warn { border-left-color: var(--warn); color: #ffd79a; background: rgba(255, 176, 32, .07); }

.hints {
    margin: 18px 0 0;
    padding: 0;
    list-style: none;
    font-size: .82rem;
    color: var(--muted-2);
}

.hints li { padding-left: 14px; position: relative; margin-bottom: 6px; }
.hints li::before {
    content: "";
    position: absolute;
    left: 0; top: .62em;
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--muted-2);
}

.muted { color: var(--muted); }
.small { font-size: .84rem; }
.tiny  { font-size: .78rem; }
.ok-text { color: var(--ok); }
.mono { font-family: ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; }
.wrap-any { overflow-wrap: anywhere; }
.small-code { font-size: .74rem; color: var(--muted); }

/* ---------- 验证码展示 ---------- */

.code-card { text-align: center; }

.loading {
    padding: 26px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.loading-text { margin: 0; font-size: .92rem; color: var(--muted); }

.wait-big {
    margin: 2px 0 0;
    font-size: .95rem;
    color: var(--muted);
}

.wait-big b {
    display: inline-block;
    min-width: 1.6em;
    margin: 0 2px;
    font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
    font-size: 1.55rem;
    font-variant-numeric: tabular-nums;
    color: #cfe0ff;
    text-shadow: 0 0 18px rgba(91, 140, 255, .45);
}

.loading .wait-bar {
    width: 100%;
    max-width: 260px;
    margin: 6px auto 4px;
}

.spinner {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid rgba(91, 140, 255, .18);
    border-top-color: var(--accent);
    animation: spin .85s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.label {
    font-size: .76rem;
    font-weight: 600;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 14px;
}

.digits {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 14px;
    font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
    font-variant-numeric: tabular-nums;
}

.digits .digit {
    min-width: 1.1em;
    padding: 6px 4px;
    font-size: clamp(2.4rem, 13vw, 4rem);
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: 0;
    color: #fff;
    text-shadow: 0 0 26px rgba(91, 140, 255, .55);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(91, 140, 255, .1), rgba(91, 140, 255, .02));
    border: 1px solid rgba(91, 140, 255, .18);
    animation: pop .42s cubic-bezier(.2, .9, .25, 1) both;
}

.digits .digit:nth-child(1) { animation-delay: .00s; }
.digits .digit:nth-child(2) { animation-delay: .04s; }
.digits .digit:nth-child(3) { animation-delay: .08s; }
.digits .digit:nth-child(5) { animation-delay: .12s; }
.digits .digit:nth-child(6) { animation-delay: .16s; }
.digits .digit:nth-child(7) { animation-delay: .20s; }

.digits .sep {
    color: var(--muted-2);
    font-size: 1.4rem;
    padding-bottom: .35em;
    user-select: none;
}

@keyframes pop {
    from { opacity: 0; transform: translateY(10px) scale(.94); }
    to   { opacity: 1; transform: none; }
}

.progress {
    position: relative;
    height: 6px;
    margin: 16px 0 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .07);
    overflow: hidden;
}

.progress.thin { height: 4px; margin: 8px 0 0; }

.progress i {
    display: block;
    height: 100%;
    width: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    transform-origin: left center;
    transform: scaleX(1);
    will-change: transform;
}

/* ---------- 统计 ---------- */

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

.card.stat {
    margin-bottom: 0;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-label {
    font-size: .74rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted);
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 650;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.live-stat .stat-value { font-size: 1.5rem; letter-spacing: .06em; }

/* ---------- 新密码 ---------- */

.newcodes { border-color: rgba(255, 176, 32, .28); }

.code-list {
    list-style: none;
    margin: 0 0 14px;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 8px;
}

.code-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #0b0e14;
}

.code-list code {
    font-size: .95rem;
    letter-spacing: .08em;
    color: #cfe0ff;
    white-space: nowrap;
}

/* ---------- 表格 ---------- */

.table-wrap { overflow-x: auto; margin: 0 -6px; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
    min-width: 620px;
}

thead th {
    text-align: left;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted-2);
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

tbody td {
    padding: 11px 10px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}

tbody tr:hover { background: rgba(255, 255, 255, .018); }
tbody tr:last-child td { border-bottom: none; }

td code { color: #b9c6de; letter-spacing: .04em; white-space: nowrap; }
.right { text-align: right; }

.pill {
    display: inline-block;
    padding: 2px 9px;
    font-size: .74rem;
    font-weight: 600;
    border-radius: 999px;
    border: 1px solid transparent;
}

.pill.fresh { color: #9be5bd; background: rgba(47, 191, 113, .12); border-color: rgba(47, 191, 113, .28); }
.pill.used  { color: var(--muted); background: rgba(255, 255, 255, .05); border-color: var(--line); }

/* ---------- 密钥折叠 ---------- */

.secret summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--muted);
    list-style: none;
}

.secret summary::-webkit-details-marker { display: none; }
.secret summary::before { content: "▸ "; color: var(--muted-2); }
.secret[open] summary::before { content: "▾ "; }

.secret-body {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.secret-body p { margin: 0; }

.blur {
    filter: blur(6px);
    user-select: none;
    transition: filter .2s ease;
}

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

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

@media (max-width: 520px) {
    body { padding: 18px 14px 44px; }
    .card { padding: 20px 18px; border-radius: 14px; }
    .card.narrow { padding: 24px 18px; }
    .digits { gap: 5px; }
    .digits .digit { padding: 4px 2px; border-radius: 9px; }
    .row-form .btn { width: 100%; }
    .field.compact { width: 100%; flex: 1 1 100%; }
    .topbar { flex-wrap: wrap; }
}

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