/* =============================================================
   main.css — 「启明」 · 全局样式与主题变量
   设计语言：编辑感（衬线大标题）+ 深松绿主色 + 暖中性灰
   浅色 / 深色双主题，token 全部经 CSS 变量下发
   ============================================================= */

/* ---------- 主题变量 ---------- */
:root {
    --bg: #f5f4ef;
    --surface: #ffffff;
    --surface-2: #efede6;
    --border: #e3e0d6;
    --border-strong: #cfccbf;

    --text: #1b1a16;
    --text-muted: #6e6a5e;
    --text-faint: #a19d90;

    --primary: #175e4a;
    --primary-strong: #0f4738;
    --on-primary: #ffffff;
    --primary-soft: #e3efe9;
    --accent: #c98a2e;
    --danger: #b3402e;
    --danger-soft: #f7e7e3;
    --ok: #26866a;
    --ok-soft: #e3efe9;

    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgb(27 26 22 / 0.05), 0 8px 24px rgb(27 26 22 / 0.07);
    --shadow-lg: 0 2px 6px rgb(27 26 22 / 0.06), 0 16px 40px rgb(27 26 22 / 0.12);

    --font-display: Georgia, "Times New Roman", "Songti SC", "STSong", "Noto Serif SC", "SimSun", serif;
    --font-body: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
    --font-mono: "SF Mono", "Cascadia Code", Consolas, Menlo, monospace;

    --nav-h: 64px;
    --bottomnav-h: 56px;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg: #131512;
    --surface: #1c1f1b;
    --surface-2: #232620;
    --border: #33362f;
    --border-strong: #454840;

    --text: #edebe3;
    --text-muted: #a19d90;
    --text-faint: #6e6a5e;

    --primary: #3db58d;
    --primary-strong: #2c8f6e;
    --on-primary: #0f241b;
    --primary-soft: #1d2b25;
    --accent: #e0a33e;
    --danger: #e07a5f;
    --danger-soft: #33221d;
    --ok: #3db58d;
    --ok-soft: #1d2b25;

    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.35);
    --shadow-lg: 0 2px 6px rgb(0 0 0 / 0.3), 0 16px 40px rgb(0 0 0 / 0.45);
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.7;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    overflow-x: clip; /* 禁止横向滚动（不破坏 sticky） */
    animation: page-in 300ms var(--ease) both;
}

/* 注意：body 上不能有任何 transform —— 会让 position:fixed 的底部导航相对化 */
@keyframes page-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
/* 页面切换压暗反馈（pageload.js 点击站内链接时切换，靠 JS 解除动画后生效） */
body { transition: opacity 240ms var(--ease); }

/* ---------- 页面切换加载动画（pageload.js 配套） ---------- */
.v3-loadbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 2.5px;
    z-index: 999;
    pointer-events: none;
}
.v3-loadbar::before {
    content: "";
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    box-shadow: 0 0 10px color-mix(in srgb, var(--primary) 55%, transparent);
    transform-origin: left;
    animation: v3-load-crawl 8s cubic-bezier(0.25, 0.6, 0.35, 1) forwards;
}
@keyframes v3-load-crawl {
    0%   { transform: scaleX(0); }
    16%  { transform: scaleX(0.38); }
    60%  { transform: scaleX(0.62); }
    100% { transform: scaleX(0.72); }
}
.v3-loadbar.done::before { animation: v3-load-finish 260ms var(--ease) forwards; }
@keyframes v3-load-finish {
    from { transform: scaleX(0.72); }
    to   { transform: scaleX(1); }
}
.v3-loadbar.hide { opacity: 0; transition: opacity 320ms var(--ease); }

/* ---------- 页面切换转圈遮罩（全站） ---------- */
.v3-nav-veil {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 1;
    visibility: visible;
    transition: opacity 280ms var(--ease), visibility 280ms;
}
.v3-nav-veil.leaving { opacity: 0; visibility: hidden; }
.veil-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 30px 44px;
    border-radius: 20px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    box-shadow: 0 12px 40px color-mix(in srgb, var(--text) 10%, transparent);
}
.veil-spin { position: relative; width: 52px; height: 52px; }
.veil-spin i {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid transparent;
}
.veil-spin .a {
    border-top-color: var(--primary);
    border-right-color: var(--primary);
    animation: veil-rot 0.85s linear infinite;
}
.veil-spin .b {
    inset: 9px;
    border-bottom-color: color-mix(in srgb, var(--primary) 50%, transparent);
    border-left-color: color-mix(in srgb, var(--primary) 50%, transparent);
    animation: veil-rot 1.4s linear infinite reverse;
}
.veil-txt {
    font-size: 13px;
    color: var(--text-2);
    letter-spacing: 0.12em;
}
@keyframes veil-rot { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .veil-spin .a { animation-duration: 2.2s; }
    .veil-spin .b { animation-duration: 3.2s; }
}

a, button, .btn, summary { -webkit-tap-highlight-color: transparent; }

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 1.3;
    text-wrap: pretty;
}

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

img { max-width: 100%; display: block; }

button { font: inherit; color: inherit; cursor: pointer; }

input, select, textarea { font: inherit; color: inherit; }

.mono { font-family: var(--font-mono); font-size: 0.86em; }

/* ---------- 通用图标 ---------- */
.ico { width: 20px; height: 20px; flex: none; }
.ico.sm { width: 16px; height: 16px; }

/* ---------- 布局 ---------- */
.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 88px 24px 48px; /* 顶部导航留白 */
}

/* ---------- Logo 主题切换 ---------- */
.logo { height: 30px; width: auto; }
.logo-dark { display: none; }
[data-theme="dark"] .logo-light { display: none; }
[data-theme="dark"] .logo-dark { display: block; }

/* ---------- 品牌 ---------- */
.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none !important;
    color: var(--text);
}
.brand-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 17px;
    letter-spacing: 0.02em;
}
.brand-sub {
    font-size: 11.5px;
    color: var(--text-faint);
    letter-spacing: 0.03em;
    white-space: nowrap;
    border-left: 1px solid var(--border-strong);
    padding-left: 12px;
}
@media (max-width: 1100px) { .brand-sub { display: none; } }

/* ---------- 顶部导航（PC ≥768px） ---------- */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--nav-h);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}
.topbar-inner {
    max-width: 1200px;
    height: 100%;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 28px;
}
.topnav { display: flex; gap: 6px; flex: 1; justify-content: center; }
.topnav-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 999px;
    color: var(--text-muted);
    text-decoration: none !important;
    transition: color 200ms var(--ease), background 200ms var(--ease);
}
.topnav-link .ico { width: 18px; height: 18px; }
.topnav-link:hover { color: var(--text); background: var(--surface-2); }
.topnav-link.active { color: var(--primary); background: var(--primary-soft); }

.topbar-side { display: flex; align-items: center; gap: 12px; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; }
.user-chip-name { font-weight: 600; font-size: 14px; }
.avatar {
    width: 34px; height: 34px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: var(--primary);
    color: var(--on-primary);
    font-weight: 700;
    font-size: 15px;
}

/* 自定义头像（渐进加载）：微缩图模糊打底，主图加载完整体渐显清晰 ——
   不是一行行 / 一块块扫出来，而是整张从模糊变清楚 */
.avatar-has { position: relative; overflow: hidden; }
.avatar-has .av-tiny {
    position: absolute; inset: 0;
    width: 100%; height: 100%; object-fit: cover;
    filter: blur(10px); transform: scale(1.25);
}
.avatar-has .av-full {
    position: absolute; inset: 0;
    width: 100%; height: 100%; object-fit: cover;
    opacity: 0; filter: blur(14px); transform: scale(1.08);
    transition: opacity 450ms var(--ease), filter 600ms var(--ease), transform 600ms var(--ease);
}
.avatar-has .av-full.ok { opacity: 1; filter: none; transform: none; }
@media (prefers-reduced-motion: reduce) {
    .avatar-has .av-full { transition: none; }
}

/* ---------- 手机底部导航（<768px） ---------- */
.topnav { display: flex; }
.bottomnav { display: none; }

@media (max-width: 767px) {
    .topbar { display: none; }
    .page {
        padding-top: 14px;
        padding-left: 12px;
        padding-right: 12px;
        padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px) + 20px);
    }
    .bottomnav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--surface); /* 老浏览器兜底 */
        background: color-mix(in srgb, var(--surface) 94%, transparent);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        border-top: 1px solid var(--border);
        box-shadow: 0 -6px 24px rgb(27 26 22 / 0.06);
        z-index: 100;
    }
    .bottomnav-link {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        color: var(--text-faint);
        font-size: 11px;
        line-height: 1.2;
        text-decoration: none !important;
        transition: color 150ms var(--ease);
    }
    .bottomnav-link:active { color: var(--primary); }
    .bottomnav-link .ico { width: 23px; height: 23px; }
    .bottomnav-link.active { color: var(--primary); font-weight: 600; }
    .bottomnav-link span {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 0 22px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 15px;
    text-decoration: none !important;
    transition: transform 150ms var(--ease), box-shadow 200ms var(--ease),
                background 200ms var(--ease), border-color 200ms var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-strong); }

.btn-ghost {
    background: transparent;
    color: var(--primary);
    border-color: var(--border-strong);
}
.btn-ghost:hover { border-color: var(--primary); background: var(--primary-soft); }

.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 13px; }

.icon-btn {
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    transition: border-color 200ms var(--ease), color 200ms var(--ease);
}
.icon-btn:hover { border-color: var(--border-strong); color: var(--text); }

/* 主题按钮：随主题显示太阳/月亮 */
.theme-toggle .sun { display: none; }
[data-theme="dark"] .theme-toggle .sun { display: block; }
[data-theme="dark"] .theme-toggle .moon { display: none; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 18px; }
.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}

.control {
    position: relative;
    display: flex;
    align-items: center;
}
.control input, .control select, .control textarea {
    width: 100%;
    min-height: 46px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color 200ms var(--ease), box-shadow 200ms var(--ease);
}
.control input:focus, .control select:focus, .control textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.control input::placeholder, .control textarea::placeholder { color: var(--text-faint); }

/* 下拉框：自定义展开角标（各浏览器原生箭头位置不一，统一接管） */
:root {
    --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='8' viewBox='0 0 13 8'%3E%3Cpath d='M1.5 1.5 6.5 6.3 11.5 1.5' fill='none' stroke='%236e6a5e' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
[data-theme="dark"] {
    --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='8' viewBox='0 0 13 8'%3E%3Cpath d='M1.5 1.5 6.5 6.3 11.5 1.5' fill='none' stroke='%23a19d90' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.control select {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 44px;
    background-image: var(--select-chevron);
    background-repeat: no-repeat;
    background-position: right 15px center;
    background-size: 13px 8px;
    cursor: pointer;
}
.control select:invalid, .control select:hover { border-color: var(--border-strong); }
.control select option { color: var(--text); background: var(--surface); }
.control.has-ico input { padding-left: 42px; }

/* 手机端表单：16px 防 iOS 聚焦缩放 + 更大触控目标 */
@media (max-width: 767px) {
    .control input, .control select, .control textarea { font-size: 16px; }
    .btn { min-height: 48px; }
    .field { margin-bottom: 16px; }
}
.control .field-ico {
    position: absolute;
    left: 13px;
    width: 19px; height: 19px;
    color: var(--text-faint);
    pointer-events: none;
}
.pw-toggle {
    position: absolute;
    right: 6px;
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    background: none; border: none; border-radius: 8px;
    color: var(--text-faint);
}
.pw-toggle:hover { color: var(--text); background: var(--surface-2); }
.pw-toggle .ico { width: 19px; height: 19px; }
.pw-toggle .eyeoff { display: none; }
.pw-toggle.showing .eye { display: none; }
.pw-toggle.showing .eyeoff { display: block; }

.field-error {
    display: none;
    margin-top: 6px;
    font-size: 13px;
    color: var(--danger);
}
.field-error.show { display: block; }

/* ---------- 卡片 ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* ---------- 徽章 ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.8;
    white-space: nowrap;
}
.badge .ico { width: 13px; height: 13px; }
.badge-student { background: var(--primary-soft); color: var(--primary); }
.badge-teacher { background: var(--primary-soft); color: var(--primary); }
.badge-parent  { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.badge-admin   { background: var(--surface-2); color: var(--text-muted); }
.badge-ok   { background: var(--ok-soft); color: var(--ok); }
.badge-wrong { background: var(--danger-soft); color: var(--danger); }
.badge-readonly { background: var(--surface-2); color: var(--text-muted); }
.badge-member { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.table th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { font-variant-numeric: tabular-nums; }
.td-clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 手机端：表格改卡片式展示 */
@media (max-width: 767px) {
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tbody tr {
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        padding: 6px 0;
        margin-bottom: 12px;
    }
    .table tbody tr:hover { background: transparent; }
    .table td {
        border-bottom: none;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 16px;
        padding: 8px 12px;
        font-size: 13.5px;
        word-break: break-word;
        text-align: right;
    }
    .table td::before {
        content: attr(data-label);
        flex: none;
        color: var(--text-muted);
        font-size: 12px;
        font-weight: 600;
        text-align: left;
    }
    .table td:not([data-label])::before { content: none; }
    .table td .badge { font-size: 11.5px; }
}

/* ---------- 空状态 ---------- */
.empty {
    padding: 44px 20px;
    text-align: center;
    color: var(--text-faint);
}
.empty p { margin-top: 10px; font-size: 14px; }
.empty-ico { width: 44px; height: 44px; opacity: 0.5; margin: 0 auto; }
.empty-sm { padding: 22px 14px; }

/* ---------- 卡片入场 stagger（整页交互节奏：依次上浮淡入） ---------- */
.check-layout > .card,
.wx-profile > .card {
    animation: card-rise 420ms var(--ease) both;
}
.check-layout > .card:nth-child(2),
.wx-profile > .card:nth-child(2) { animation-delay: 70ms; }
.wx-profile > .card:nth-child(3) { animation-delay: 140ms; }
.wx-profile > .card:nth-child(4) { animation-delay: 200ms; }
.wx-profile > .card:nth-child(5) { animation-delay: 260ms; }
.wx-profile > .card:nth-child(6) { animation-delay: 320ms; }
.wx-profile > .card:nth-child(n+7) { animation-delay: 380ms; }
@keyframes card-rise {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
}

/* ---------- 无障碍 ---------- */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

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