/* ======================================================================
 * 麦酷笔记 - 公共设计系统 app.css
 * 统一设计 token + 公共组件 + 移动端适配
 * ====================================================================== */

/* ========== 设计 Token ========== */
:root {
    /* 主色 */
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --primary-soft: rgba(79, 70, 229, 0.10);
    --accent: #8b5cf6;

    /* 语义色 */
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warning: #f59e0b;
    --info: #3b82f6;

    /* 中性色 */
    --bg: #f6f7fb;
    --bg-soft: #f1f5f9;
    --surface: #ffffff;
    --border: #e8ebf0;
    --border-soft: #f1f5f9;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    /* 顶栏 */
    --header-bg: #1e1b3a;
    --header-bg-2: #2d2a5c;
    --header-text: rgba(255, 255, 255, 0.82);

    /* 圆角 */
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-pill: 999px;

    /* 阴影 */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.12);
    --shadow-primary: 0 8px 20px rgba(79, 70, 229, 0.28);

    /* 间距 */
    --space-xs: 4px;
    --space-sm: 8px;
    --space: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* 字号 */
    --fs-xs: 12px;
    --fs-sm: 13px;
    --fs: 14px;
    --fs-md: 15px;
    --fs-lg: 17px;
    --fs-xl: 20px;
    --fs-2xl: 26px;

    /* 过渡 */
    --t: 0.22s cubic-bezier(0.4, 0, 0.2, 1);

    /* 布局 */
    --header-h: 60px;
    --container: 1200px;
    --tabbar-h: 58px;
}

/* ========== 基础重置 ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
a { color: var(--primary); text-decoration: none; transition: color var(--t); }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; }
::selection { background: var(--primary-soft); }

/* ========== 顶部导航栏 ========== */
.header {
    background: linear-gradient(135deg, var(--header-bg) 0%, var(--header-bg-2) 100%);
    padding: 0 var(--space-lg);
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 16px rgba(15, 23, 42, 0.18);
}
.logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: var(--fs-lg);
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    letter-spacing: -0.3px;
    flex-shrink: 0;
}
.logo-area:hover { color: #fff; }
.logo-area .logo-emoji { font-size: 22px; }
.logo-area img { height: 34px; border-radius: var(--radius-sm); }
.logo-area .site-logo-text {
    background: linear-gradient(135deg, #a5b4fc, #c4b5fd);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* 桌面导航 */
.nav { display: flex; gap: 2px; align-items: center; }
.nav a, .nav-dropdown-toggle {
    padding: 9px 16px;
    color: var(--header-text);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all var(--t);
    font-size: var(--fs);
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.nav a:hover, .nav-dropdown-toggle:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.nav a.active { color: #fff; background: var(--primary-soft); }
.nav-dropdown { position: relative; }
.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 170px;
    padding: 6px;
    z-index: 200;
    margin-top: 0; /* 消除间隙，避免 hover 移动途中 mouseleave 误触发 */
}
/* 透明桥：填充按钮与菜单之间的视觉间距，鼠标经过不会中断 hover */
.nav-dropdown-menu::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 0;
    right: 0;
    height: 6px;
}
.nav-dropdown.open .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
    display: block;
    padding: 10px 14px;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
}
.nav-dropdown-menu a:hover { color: var(--primary); background: var(--primary-light); }
.nav-dropdown-menu a.active { color: var(--primary); background: var(--primary-light); font-weight: 600; }
.nav-dropdown-menu .divider { height: 1px; background: var(--border-soft); margin: 4px 0; }

/* 用户菜单 */
.user-menu { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #818cf8, #a78bfa);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: var(--fs);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.username {
    font-size: var(--fs); color: rgba(255, 255, 255, 0.92);
    max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500;
}
.btn-icon-link {
    width: 34px; height: 34px;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.85);
    border-radius: var(--radius-sm);
    font-size: 16px; border: none; cursor: pointer;
    transition: all var(--t);
}
.btn-icon-link:hover { background: rgba(255, 255, 255, 0.16); color: #fff; }
.btn-logout {
    padding: 7px 14px;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm); cursor: pointer; text-decoration: none;
    transition: all var(--t);
}
.btn-logout:hover { background: rgba(239, 68, 68, 0.22); color: #fca5a5; border-color: rgba(239, 68, 68, 0.45); }

/* 移动端菜单按钮（默认隐藏） */
.nav-toggle {
    display: none;
    width: 38px; height: 38px;
    align-items: center; justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    color: #fff; font-size: 20px; border: none; cursor: pointer;
}

/* ========== 按钮 ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--fs);
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--t);
    line-height: 1.4;
    white-space: nowrap;
}
.btn:hover { background: var(--primary-hover); color: #fff; transform: translateY(-1px); box-shadow: var(--shadow-primary); }
.btn:active { transform: translateY(0); }
.btn-success { background: var(--success); }
.btn-success:hover { background: var(--success-hover); box-shadow: 0 8px 20px rgba(16, 185, 129, 0.28); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); box-shadow: 0 8px 20px rgba(239, 68, 68, 0.28); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text-secondary); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--bg-soft); color: var(--text); border-color: var(--text-muted); box-shadow: var(--shadow); }
.btn-sm { padding: 7px 14px; font-size: var(--fs-sm); }
.btn-block { width: 100%; }

/* ========== 容器 ========== */
.container { max-width: var(--container); margin: 0 auto; padding: var(--space-lg); }
.container-md { max-width: 900px; margin: 0 auto; padding: var(--space-lg); }
.container-sm { max-width: 760px; margin: 0 auto; padding: var(--space-lg); }

/* ========== 卡片 ========== */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
    border: 1px solid var(--border-soft);
}
.card-title {
    font-size: var(--fs-lg);
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space);
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-soft);
    display: flex; align-items: center; gap: 10px;
}

/* ========== 页面标题 ========== */
.page-title {
    font-size: var(--fs-2xl);
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--space-lg);
    display: flex; align-items: center; gap: 12px;
    letter-spacing: -0.4px;
}
.page-subtitle { font-size: var(--fs-sm); color: var(--text-secondary); margin-top: 4px; }

/* ========== 表单 ========== */
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block; margin-bottom: 8px;
    font-weight: 600; color: var(--text); font-size: var(--fs);
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="url"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 11px 15px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--fs);
    font-family: inherit;
    transition: all var(--t);
    background: var(--surface);
    color: var(--text);
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}
.form-group input::placeholder, .form-group textarea::placeholder { color: var(--text-muted); }
.form-group textarea { min-height: 110px; resize: vertical; line-height: 1.6; }
.form-group .hint { font-size: var(--fs-sm); color: var(--text-secondary); margin-top: 6px; }
.form-group input[type="file"] { padding: 10px; background: var(--bg-soft); border: 1px dashed var(--text-muted); border-radius: var(--radius-sm); }
.form-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
    cursor: pointer;
}
.row { display: flex; gap: var(--space); }
.row .form-group { flex: 1; }

/* 复选框组 */
.checkbox-group { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.checkbox-group label {
    display: inline-flex; align-items: center; gap: 9px;
    cursor: pointer; font-weight: 500; font-size: var(--fs);
    color: var(--text-secondary);
    padding: 10px 16px;
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: all var(--t);
}
.checkbox-group label:hover { background: var(--primary-light); border-color: var(--primary); }
.checkbox-group input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }

/* ========== 提示框 ========== */
.alert {
    padding: 13px 17px;
    border-radius: var(--radius);
    margin-bottom: var(--space);
    font-size: var(--fs);
    border-left: 4px solid;
    display: flex; align-items: center; gap: 10px;
}
.alert-success { background: #d1fae5; color: #065f46; border-left-color: var(--success); }
.alert-error { background: #fee2e2; color: #991b1b; border-left-color: var(--danger); }
.alert-warning { background: #fef3c7; color: #92400e; border-left-color: var(--warning); }
.alert-info { background: #dbeafe; color: #1e40af; border-left-color: var(--info); }
.alert a { color: inherit; font-weight: 600; text-decoration: underline; }

/* ========== 表格 ========== */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow-sm); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--border-soft); font-size: var(--fs); }
th { font-weight: 600; color: var(--text-secondary); font-size: var(--fs-sm); background: var(--bg-soft); }
tr:hover { background: var(--bg-soft); }
tr:last-child td { border-bottom: none; }

/* ========== 徽标 ========== */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: 600; }
.badge-admin { background: var(--primary-light); color: var(--primary-hover); }
.badge-user { background: var(--bg-soft); color: var(--text-secondary); }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }

/* ========== 分页 ========== */
.pagination { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin-top: 30px; }
.pagination a {
    padding: 9px 15px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all var(--t);
    font-weight: 500;
    font-size: var(--fs-sm);
}
.pagination a:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.pagination a.active { background: var(--primary); color: #fff; border-color: var(--primary); box-shadow: var(--shadow-primary); }

/* ========== 统计卡片 ========== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space); margin-bottom: var(--space-lg); }
.stat-box, .stat-item {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 22px;
    text-align: center;
    border: 1px solid var(--border-soft);
    transition: all var(--t);
}
.stat-box:hover, .stat-item:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-num {
    font-size: 30px; font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.stat-label { font-size: var(--fs-sm); color: var(--text-secondary); margin-top: 6px; font-weight: 500; }

/* ========== 空状态 ========== */
.empty-state {
    text-align: center;
    padding: 70px 20px;
    color: var(--text-muted);
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-soft);
}
.empty-state .icon { font-size: 64px; margin-bottom: 16px; display: block; }
.empty-state p { font-size: var(--fs-md); margin-bottom: 8px; color: var(--text-secondary); }

/* ========== 通用工具 ========== */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-sm { gap: 8px; }
.gap { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.hidden { display: none !important; }

/* ========== 移动端响应式 ========== */
@media (max-width: 768px) {
    :root {
        --header-h: 54px;
        --fs-2xl: 21px;
        --fs-xl: 18px;
    }

    /* 顶栏 */
    .header { padding: 0 12px; }
    .logo-area { font-size: var(--fs-md); gap: 6px; }
    .logo-area .logo-emoji { font-size: 19px; }
    .logo-area .site-logo-text { display: inline; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
    .username { display: none; }
    .btn-logout { display: none; }
    .user-menu { gap: 6px; margin-left: auto; }
    .avatar { width: 32px; height: 32px; font-size: var(--fs-sm); }

    /* 桌面导航隐藏，启用抽屉 + 底部Tab */
    .nav-toggle { display: inline-flex; }
    .nav {
        position: fixed;
        top: var(--header-h);
        left: 0;
        bottom: 0;
        width: 78%;
        max-width: 300px;
        background: rgba(30, 27, 58, 0.97);
        backdrop-filter: blur(8px);
        flex-direction: column;
        align-items: stretch;
        padding: var(--space);
        gap: 4px;
        transform: translateX(-100%);
        transition: transform var(--t);
        z-index: 250;
        overflow-y: auto;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    }
    .nav.active { transform: translateX(0); }
    .nav a, .nav-dropdown-toggle {
        padding: 15px 16px;
        font-size: var(--fs-md);
        border-radius: var(--radius-sm);
        color: rgba(255, 255, 255, 0.88);
        justify-content: flex-start;
    }
    .nav-dropdown { position: static; }
    .nav-dropdown-menu {
        position: static;
        background: rgba(0, 0, 0, 0.25);
        box-shadow: none;
        margin: 4px 0 8px;
        padding: 4px;
    }
    .nav-dropdown-menu::before { display: none; } /* 移动端不需要透明桥 */
    .nav-dropdown-menu a { color: rgba(255, 255, 255, 0.75); }

    /* 容器 */
    .container, .container-md, .container-sm { padding: var(--space); }
    .page-title { font-size: var(--fs-xl); margin-bottom: var(--space); }

    /* 表单 */
    .form-group input, .form-group textarea, .form-group select { padding: 12px 14px; font-size: 16px; } /* 16px 防 iOS 缩放 */
    .row { flex-direction: column; gap: 0; }
    .btn { padding: 12px 20px; font-size: var(--fs); }
    .btn-sm { padding: 9px 14px; }

    /* 卡片 */
    .card { padding: var(--space); border-radius: var(--radius); }

    /* 统计：移动端改为紧凑四列横条，不再突兀 */
    .stats-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .stat-box, .stat-item { padding: 10px 4px; }
    .stat-num { font-size: 19px; }
    .stat-label { font-size: 10px; margin-top: 2px; }

    /* 表格横向滚动 */
    .table-wrapper { border-radius: var(--radius); }

    /* 给底部留出 Tab 栏空间（页面内容） */
    .has-tabbar .container,
    .has-tabbar .container-md,
    .has-tabbar .container-sm { padding-bottom: calc(var(--tabbar-h) + var(--space) + env(safe-area-inset-bottom)); }
}

/* ========== 底部 Tab 栏（仅移动端列表类页面） ========== */
.tabbar {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    z-index: 200;
    box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.06);
}
.tabbar-inner {
    display: flex;
    height: var(--tabbar-h);
    max-width: 480px;
    margin: 0 auto;
}
.tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-muted);
    font-size: var(--fs-xs);
    text-decoration: none;
    transition: color var(--t);
    -webkit-tap-highlight-color: transparent;
}
.tabbar a .tb-icon { font-size: 20px; line-height: 1; }
.tabbar a.active { color: var(--primary); font-weight: 600; }
@media (max-width: 768px) {
    .show-tabbar .tabbar { display: block; }
}

/* ========== 底部页脚 ========== */
.site-footer {
    text-align: center;
    padding: 30px 16px;
    margin-top: 40px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: var(--fs-sm);
    background: var(--surface);
}
.site-footer .footer-brand { display: flex; justify-content: center; align-items: center; gap: 8px; margin-bottom: 8px; }
.site-footer .footer-brand .dot { color: var(--primary); }
.site-footer .footer-brand .name { font-weight: 600; color: var(--text-secondary); }
@media (max-width: 768px) {
    .site-footer { padding-bottom: calc(30px + env(safe-area-inset-bottom)); margin-bottom: 0; }
    .has-tabbar .site-footer { margin-bottom: var(--tabbar-h); }
}

/* ========== 遮罩（抽屉打开时，纯视觉不拦截事件） ========== */
.nav-mask {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 240;
    pointer-events: none; /* 关键：不拦截事件，点击穿透到页面，由 document 统一处理 */
    -webkit-tap-highlight-color: transparent;
}
.nav-mask.show { display: block; }
@media (max-width: 768px) {
    .nav-toggle, .nav a, .nav-dropdown-toggle {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
}
