/* ============================================================
   群码系统 · 管理后台样式
   ============================================================ */
:root {
    --brand: #1aad19;
    --brand-grad: linear-gradient(135deg, #26c66b, #1aad19);
    --sidebar-bg: #001529;
    --topbar-bg: #001529;
    --sidebar-hover: rgba(255, 255, 255, .06);
    --text: #2b3445;
    --text-sub: #7a8699;
    --text-mute: #98a1b0;
    --line: #eceff3;
    --line-soft: #f3f5f8;
    --bg: #f4f6f9;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 6px 18px rgba(16, 24, 40, .05);
    --shadow-hover: 0 4px 10px rgba(16, 24, 40, .08), 0 12px 28px rgba(16, 24, 40, .09);
    --topbar-h: 58px;
    --sidebar-w: 210px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; border: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ===== 登录页 ===== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1aad19 0%, #26c66b 100%);
}
.login-box {
    background: #fff;
    padding: 44px 40px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .18);
    width: 380px;
}
.login-box h2 { margin-bottom: 26px; text-align: center; color: var(--brand); font-size: 20px; }
.tip { text-align: center; color: var(--text-mute); font-size: 12.5px; margin-top: 16px; }

/* ============================================================
   后台框架：顶栏 + 侧边栏 + 内容区
   ============================================================ */
/* app.js 会把 #mainPage 设为 display:flex，这里固定为纵向排列，
   保证顶栏占满整行、侧边栏紧随其下并贴齐最左侧 */
.main-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.top-bar {
    height: var(--topbar-h);
    flex-shrink: 0;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--topbar-bg);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
}
.top-bar h1 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16.5px;
    font-weight: 600;
    letter-spacing: .3px;
    white-space: nowrap;
}
.top-right { display: flex; align-items: center; gap: 10px; }

.layout {
    display: flex;
    align-items: flex-start;
    min-height: calc(100vh - var(--topbar-h));
}

/* 侧边栏 */
.sidebar {
    position: sticky;
    top: var(--topbar-h);
    flex: 0 0 var(--sidebar-w);
    width: var(--sidebar-w);
    height: calc(100vh - var(--topbar-h));
    overflow-y: auto;
    background: var(--sidebar-bg);
}
.sidebar nav { display: flex; flex-direction: column; padding: 10px 0; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    /* 左侧 17px + 3px 左边框 = 20px，与顶栏标题的左内边距对齐 */
    padding: 12px 20px 12px 17px;
    color: #a3adbb;
    font-size: 13.5px;
    border-left: 3px solid transparent;
    transition: background .18s, color .18s;
}
.nav-item span {
    flex: 0 0 20px;
    width: 20px;
    font-size: 15px;
    line-height: 1;
    text-align: center;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active {
    background: linear-gradient(90deg, rgba(26, 173, 25, .30), rgba(26, 173, 25, .05));
    color: #fff;
    border-left-color: var(--brand);
    font-weight: 500;
}

/* 内容区 */
.content { flex: 1; min-width: 0; padding: 22px 26px 44px; }
.page { display: none; }
.page.active { display: block; }
.page > h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 18px;
}
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
    margin-bottom: 18px;
}
.page-header h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 600;
    flex-shrink: 0;
    white-space: nowrap;
}
.page-header .list-total {
    font-size: 13px;
    font-weight: 400;
    color: #8a94a6;
    background: #f2f4f7;
    padding: 3px 10px;
    border-radius: 20px;
}
.page-header .list-total b { color: var(--brand); font-size: 14px; }
.page-header .filter-bar { margin-left: auto; }
.section-title { font-size: 15px; font-weight: 600; color: var(--text); margin: 24px 0 14px; }

/* ===== 统计卡片 ===== */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 22px 24px;
    display: flex;
    align-items: center;
    box-shadow: var(--shadow);
    transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.stat-icon {
    width: 54px; height: 54px;
    flex-shrink: 0;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 26px;
    margin-right: 16px;
}
.stat-icon.blue { background: #e8f3ff; }
.stat-icon.green { background: #eafaf0; }
.stat-icon.orange { background: #fff5e8; }
.stat-info { display: flex; flex-direction: column; min-width: 0; }
.stat-num { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1.15; }
.stat-label { font-size: 12.5px; color: var(--text-sub); margin-top: 4px; }

/* ===== 快捷入口 ===== */
.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.quick-btn {
    background: #fff;
    border-radius: var(--radius);
    padding: 24px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    font-size: 13.5px;
    color: #55606f;
    box-shadow: var(--shadow);
    transition: transform .2s, box-shadow .2s, color .2s;
}
.quick-btn:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); color: var(--brand); }
.quick-icon { font-size: 30px; line-height: 1; }

/* ===== 筛选栏 ===== */
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filter-bar input, .filter-bar select {
    padding: 8px 12px;
    border: 1px solid #dfe4ea;
    border-radius: 8px;
    font-size: 13px;
    background: #fff;
    color: var(--text);
    transition: border-color .2s, box-shadow .2s;
}
.filter-bar input:focus, .filter-bar select:focus {
    border-color: var(--brand);
    outline: none;
    box-shadow: 0 0 0 3px rgba(26, 173, 25, .12);
}

/* 批量操作条 */
.batch-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    background: #fffbe6;
    border: 1px solid #ffe58f;
    border-radius: 10px;
    padding: 10px 16px;
    margin: 12px 0;
    font-size: 13px;
}
.batch-bar b { color: #ff5722; font-size: 15px; }
.batch-bar em { font-style: normal; color: #d48806; margin-left: 4px; }
.btn-link { background: none; border: none; color: var(--brand); cursor: pointer; font-size: 13px; padding: 0 6px; }
.btn-link:hover { text-decoration: underline; }

/* ===== 数据表格 ===== */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: #fff;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.data-table th {
    background: #f7f9fc;
    padding: 12px 14px;
    text-align: left;
    font-size: 12.5px;
    color: #6b7686;
    font-weight: 600;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.data-table td {
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text);
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #fafbfd; }
.data-table .thumb {
    width: 46px; height: 46px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--line);
    display: block;
}

.status-tag {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    line-height: 1.5;
    white-space: nowrap;
}
.status-tag.on { background: #eafaf0; color: #17a34a; }
.status-tag.off { background: #f2f4f7; color: #8a93a0; }
.action-btns { display: flex; gap: 6px; flex-wrap: nowrap; }

.pagination { display: flex; justify-content: flex-end; align-items: center; gap: 6px; margin-top: 16px; }
.pagination button {
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #dfe4ea;
    border-radius: 8px;
    font-size: 13px;
    color: #55606f;
    transition: all .2s;
}
.pagination button:hover:not(.active) { border-color: var(--brand); color: var(--brand); }
.pagination button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ===== 表单卡片 ===== */
.form-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 24px 26px;
    box-shadow: var(--shadow);
    max-width: 880px;
}
.form-card h3 { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 16px; }
.btn-group { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

/* ===== 表单元素 ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: #55606f; margin-bottom: 6px; font-weight: 500; }
.form-group input, .form-group select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #dfe4ea;
    border-radius: 8px;
    font-size: 13.5px;
    color: var(--text);
    background: #fff;
    transition: border-color .2s, box-shadow .2s;
}
.form-group input:focus, .form-group select:focus {
    border-color: var(--brand);
    outline: none;
    box-shadow: 0 0 0 3px rgba(26, 173, 25, .12);
}
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 180px; margin-bottom: 16px; }

/* ===== 按钮 ===== */
.btn-primary {
    background: var(--brand-grad);
    color: #fff;
    padding: 9px 22px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 500;
    transition: transform .12s, box-shadow .2s;
}
.btn-primary:hover { box-shadow: 0 4px 14px rgba(26, 173, 25, .35); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
    background: #f2f4f7;
    color: #5b6675;
    padding: 9px 22px;
    border-radius: 8px;
    font-size: 13.5px;
    transition: background .2s;
}
.btn-secondary:hover { background: #e7ebef; }
.btn-edit {
    background: #f0f6ff;
    color: #1677ff;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12.5px;
    transition: background .2s;
}
.btn-edit:hover { background: #e0edff; }
.btn-danger {
    background: #fff1f0;
    color: #e64545;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12.5px;
    transition: background .2s;
}
.btn-danger:hover { background: #ffe0dd; }
.btn-logout {
    background: rgba(255, 255, 255, .18);
    color: #fff;
    padding: 7px 16px;
    border-radius: 8px;
    font-size: 13px;
    transition: background .2s;
}
.btn-logout:hover { background: rgba(255, 255, 255, .3); }

/* ===== 上传区域 ===== */
.upload-area {
    border: 2px dashed #dbe0e6;
    border-radius: 10px;
    padding: 28px;
    text-align: center;
    position: relative;
    background: #fbfcfd;
    transition: border-color .2s, background .2s;
}
.upload-area:hover { border-color: var(--brand); background: #f5fcf5; }
.upload-area.large { padding: 56px 20px; }
.upload-area input[type="file"] {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    opacity: 0; cursor: pointer;
}
.upload-hint { color: var(--text-mute); font-size: 13.5px; }
.preview-img {
    display: block;
    max-width: 160px;
    max-height: 160px;
    margin: 12px auto 0;
    border-radius: 8px;
}

.batch-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    margin-top: 16px;
}
.batch-preview .item {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    text-align: center;
}
.batch-preview .item img { width: 100%; height: 90px; object-fit: cover; border-radius: 6px; }
.batch-preview .item input {
    width: 100%;
    margin-top: 6px;
    padding: 4px 6px;
    font-size: 11px;
    border: 1px solid var(--line);
    border-radius: 4px;
}
.batch-preview .item .remove {
    margin-top: 4px;
    background: #fff1f0;
    color: #e64545;
    border-radius: 4px;
    font-size: 11px;
    padding: 2px 8px;
}

/* ===== 批量导入 - Tab 切换 ===== */
.tab-bar { display: flex; margin-bottom: 16px; flex-wrap: wrap; }
.tab-btn {
    background: #fff;
    border: 1px solid #e8e8e8;
    padding: 10px 22px;
    font-size: 13.5px;
    color: #6b7686;
    border-radius: 8px 8px 0 0;
    transition: all .2s;
}
.tab-btn + .tab-btn { margin-left: -1px; }
.tab-btn.active {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
    position: relative;
    z-index: 1;
}
.tab-panel { margin-top: 16px; }

/* ===== 批量导入 - 二维码校验 ===== */
.qr-hint {
    background: #f6ffed;
    border-left: 4px solid #52c41a;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 13px;
    color: #389e0d;
}

.badge {
    background: #f2f4f7;
    color: var(--text-sub);
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 12px;
}

.batch-result {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px dashed var(--line);
}

.result-summary { font-size: 13.5px; }
.result-summary .summary.ok { color: #17a34a; font-weight: 600; }
.result-summary .summary.bad { color: #e64545; font-weight: 600; }

/* ===== 弹窗 ===== */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 20px;
}
.modal-box {
    background: #fff;
    padding: 28px 30px;
    border-radius: 14px;
    width: 520px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .2);
}
.modal-box h3 { margin-bottom: 20px; font-size: 16px; font-weight: 600; }

/* ===== Toast ===== */
.toast {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, .82);
    color: #fff;
    padding: 14px 28px;
    border-radius: 10px;
    font-size: 14px;
    z-index: 1000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
}

/* ===== 系统设置页 ===== */
.ocr-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: #f0f9eb;
    padding: 14px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
}
.ocr-status {
    font-size: 13.5px;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 14px;
    white-space: nowrap;
}
.ocr-status.ready { background: #e8f5e9; color: #2e7d32; }
.ocr-status.unconfigured { background: #fff3e0; color: #e65100; }
.ocr-status.disabled { background: #f5f6f8; color: var(--text-mute); }
.ocr-link { font-size: 13px; color: #1890ff; text-decoration: none; }

.masked-label {
    font-size: 12px;
    color: var(--text-mute);
    font-weight: normal;
    margin-left: 8px;
}

/* Switch 开关 */
.switch-wrap { display: flex; align-items: center; cursor: pointer; }
.switch {
    position: relative;
    display: inline-block;
    width: 44px; height: 22px;
    flex-shrink: 0;
    background: #ccd2da;
    border-radius: 22px;
    margin-right: 12px;
    transition: background .2s;
}
.switch::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 18px; height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform .2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}
.switch-wrap input { display: none; }
.switch-wrap input:checked + .switch { background: var(--brand); }
.switch-wrap input:checked + .switch::after { transform: translateX(22px); }
.switch-text { font-size: 13px; color: #5b6675; }

/* ===== 广告管理页 ===== */
.page-desc {
    font-size: 13px;
    color: #8a93a0;
    line-height: 1.7;
    margin: 0 0 18px;
}
.ad-sec-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin: 22px 0 10px;
}
.ad-sec-title:first-of-type { margin-top: 0; }

.ad-pos-main { flex: 1; min-width: 0; }
.ad-pos-name { font-size: 14px; font-weight: 600; color: var(--text); }
.ad-pos-where { font-size: 12.5px; color: #8a93a0; line-height: 1.6; margin-top: 4px; }
.ad-pos-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.ad-pos-head .switch { margin-right: 0; }
.ad-flat-card { margin-bottom: 16px; max-width: 100%; padding: 16px 18px; }

/* 广告位分组卡片：开关 + 该位置的广告 */
.ad-group {
    max-width: 100%;
    margin-bottom: 16px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}
.ad-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 18px;
    background: #fafbfc;
    border-bottom: 1px solid var(--line);
}
.ad-group-head .switch { margin-right: 0; }
.ad-group-off .ad-group-head { background: #f4f5f7; }
.ad-group-off .ad-group-body,
.ad-group-off .ad-group-foot { opacity: 0.5; }
.ad-count {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 8px;
    font-size: 11.5px;
    font-weight: 400;
    color: #8a93a0;
    background: #eef0f3;
    border-radius: 999px;
}
.ad-group-body { padding: 4px 18px; }

/* 单条广告 */
.ad-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px dashed #eef0f3;
}
.ad-item:last-child { border-bottom: none; }
.ad-item-off .ad-item-title { color: #9aa3b0; }
.ad-thumb {
    width: 64px;
    height: 44px;
    border-radius: 6px;
    object-fit: cover;
    background: #f2f3f5;
    flex: none;
}
.ad-thumb-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: #b4bcc7;
}
.ad-item-main { flex: 1; min-width: 0; }
.ad-item-title {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ad-item-sub {
    margin-top: 4px;
    font-size: 12px;
    color: #8a93a0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ad-url { color: #b4bcc7; }
.ad-item-state { flex: none; }
.ad-empty {
    padding: 18px 0;
    text-align: center;
    font-size: 12.5px;
    color: #b4bcc7;
}
.ad-group-foot {
    padding: 12px 18px;
    border-top: 1px solid var(--line);
    background: #fafbfc;
}


.ocr-result {
    margin-top: 20px;
    background: #f5f7fa;
    padding: 16px;
    border-radius: 10px;
    border-left: 4px solid var(--brand);
}
.ocr-result h4 { margin-bottom: 10px; color: var(--text); font-size: 14px; }
.ocr-result pre {
    background: #fff;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-all;
    color: #555;
    max-height: 200px;
    overflow-y: auto;
}

.ocr-help {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px dashed var(--line);
}
.ocr-help h4 { font-size: 14px; color: var(--text); margin-bottom: 12px; }
.ocr-help ol { padding-left: 20px; }
.ocr-help ol li { font-size: 13px; color: #5b6675; line-height: 2; }
.ocr-help a { color: #1890ff; text-decoration: none; }

/* ===== 滚动条美化 ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d0d5da; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #b0b6bc; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== 窄屏适配 ===== */
@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .quick-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
    :root { --sidebar-w: 168px; }
    .content { padding: 18px 16px 40px; }
    .top-bar { padding: 0 16px; }
    .top-bar h1 { font-size: 15px; }
}