:root {
    --primary: #0d6efd;
    --primary-hover: #0b5ed7;
    --success: #198754;
    --warning: #ffc107;
    --danger: #dc3545;
    --info: #0dcaf0;
    --dark: #212529;
    --sidebar-bg: #252526;
    --sidebar-hover: #3c3c3c;
    --sidebar-active: #007acc;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --border-color: #dee2e6;
    --border-light: #e9ecef;
    --bg-page: #ffffff;
    --bg-content: #f5f5f5;
    --font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
}

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

body {
    font-family: var(--font-family);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-content);
}

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

/* ===== 后台布局 ===== */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

/* 侧边栏 */
.admin-sidebar {
    width: 200px;
    background: var(--sidebar-bg, #252526);
    color: var(--sidebar-text, #ccc);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.admin-sidebar .logo {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    border-bottom: 1px solid #333;
    background: #1e1e1e;
}

.admin-sidebar .menu {
    padding: 10px 0;
}

.admin-sidebar .menu-item {
    display: block;
    padding: 10px 20px;
    color: #ccc;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.admin-sidebar .menu-item:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.admin-sidebar .menu-item.active {
    background: var(--sidebar-active);
    color: #fff;
    border-left-color: #fff;
}

.admin-sidebar .menu-group-title {
    padding: 10px 20px 5px;
    font-size: 12px;
    color: #888;
    text-transform: uppercase;
}

.admin-sidebar .menu-item i {
    margin-right: 8px;
    width: 16px;
    text-align: center;
}

/* 主内容区 */
.admin-main {
    flex: 1;
    margin-left: 200px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* 顶部导航 */
.admin-header {
    height: 56px;
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.admin-header .breadcrumb {
    font-size: 14px;
    color: var(--text-secondary);
}

.admin-header .user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.admin-header .user-info .username {
    color: var(--text-primary);
}

.admin-header .user-info .logout-btn {
    color: var(--danger);
    cursor: pointer;
}

/* 内容区 */
.admin-content {
    flex: 1;
    padding: 20px;
}

/* 卡片 */
.card {
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.card-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-light);
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: 20px;
}

/* 统计卡片 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: #fff;
    border-radius: 4px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-card .stat-label {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 8px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: bold;
    color: var(--text-primary);
}

.stat-card .stat-icon {
    float: right;
    font-size: 36px;
    color: var(--primary);
    opacity: 0.3;
}

/* 表格 */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.table th {
    background: #fafafa;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
}

.table tr:hover td {
    background: #f9f9f9;
}

/* 按钮 */
.btn {
    display: inline-block;
    padding: 6px 16px;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    text-align: center;
    line-height: 1.5;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-hover);
    color: #fff;
}

.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.btn-warning {
    background: var(--warning);
    color: #fff;
    border-color: var(--warning);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.btn-default {
    background: #fff;
    color: var(--text-primary);
    border-color: var(--border-color);
}
.btn-default:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

/* 表单 */
.form-group {
    margin-bottom: 15px;
}

.form-label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.5;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.1);
}

.form-inline {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.form-inline .form-control {
    width: auto;
}

/* 分页 */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px 0;
    gap: 6px;
    list-style: none;
}

.pagination ul {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.pagination li {
    display: inline-flex;
    list-style: none;
    margin: 0;
    padding: 0;
}

.pagination li > a,
.pagination li > span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fff;
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s;
}

.pagination li > a:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #f0f6ff;
}

.pagination li.active > span {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 600;
}

.pagination li.disabled > span {
    color: var(--text-muted);
    cursor: not-allowed;
}

/* 中间省略号：去掉边框 */
.pagination li.disabled:not(:first-child):not(:last-child) > span {
    border-color: transparent;
    background: transparent;
    min-width: auto;
    padding: 0 2px;
}

/* 状态标签 */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.5;
}

.badge-success { background: #d4edda; color: var(--success); }
.badge-danger { background: #f8d7da; color: var(--danger); }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-info { background: #d1ecf1; color: #0c5460; }
.badge-secondary { background: #e2e3e5; color: #383d41; }

/* 搜索栏 */
.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    align-items: center;
}

.search-bar .form-control {
    width: 200px;
}

/* 操作按钮组 */
.action-btns {
    display: flex;
    gap: 5px;
}

/* 趋势图 */
.trend-chart {
    display: flex;
    align-items: flex-end;
    height: 200px;
    gap: 10px;
    padding: 20px 0;
}

.trend-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.trend-bar {
    width: 100%;
    background: linear-gradient(to top, var(--primary), #5ba0ff);
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    transition: height 0.3s;
}

.trend-date {
    font-size: 12px;
    color: var(--text-secondary);
}

.trend-value {
    font-size: 12px;
    color: var(--text-primary);
    font-weight: 500;
}

/* 左右并排卡片行 */
.stats-row {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

/* 分布条（浏览器/OS/来源/类型分布） */
.dist-item {
    margin-bottom: 12px;
}
.dist-item:last-child {
    margin-bottom: 0;
}
.dist-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 13px;
}
.dist-name {
    color: var(--text-primary);
}
.dist-count {
    color: var(--text-secondary);
}
.dist-bar-bg {
    width: 100%;
    height: 8px;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
}
.dist-bar {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}

/* 今日24小时分布图 */
.hourly-chart {
    display: flex;
    align-items: flex-end;
    height: 160px;
    gap: 2px;
    padding: 20px 0 10px;
    overflow-x: auto;
}
.hourly-item {
    flex: 1;
    min-width: 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}
.hourly-bar {
    width: 70%;
    background: linear-gradient(to top, #198754, #5cb85c);
    border-radius: 3px 3px 0 0;
    min-height: 3px;
}
.hourly-value {
    font-size: 10px;
    color: var(--text-secondary);
}
.hourly-label {
    font-size: 10px;
    color: var(--text-muted);
    transform: rotate(-45deg);
    white-space: nowrap;
}

/* 登录日志：成功/失败行高亮 */
.row-success td {
    background: #f8fff9;
}
.row-fail td {
    background: #fff5f5;
}
.ip-text {
    font-family: monospace;
    font-size: 12px;
}

/* 登录页 */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    width: 380px;
    max-width: calc(100vw - 32px);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    padding: 30px;
}

.login-box .login-title {
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 25px;
    color: var(--text-primary);
}

.login-box .captcha-box {
    display: flex;
    gap: 10px;
}

.login-box .captcha-box .form-control {
    flex: 1;
}

.login-box .captcha-img {
    width: 100px;
    height: 38px;
    cursor: pointer;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.login-box .btn {
    width: 100%;
    padding: 10px;
    font-size: 16px;
}

/* ===== 表单页通用 ===== */
.form-page {
    max-width: 600px;
}
.form-page-sm {
    max-width: 500px;
}
/* 输入框与提示文字同行排列 */
.input-hint-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.input-hint-row .input-hint {
    font-size: 12px;
    color: #999;
    white-space: nowrap;
}
/* 表单项下方灰色提示文字 */
.form-hint {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
}

/* 登录页手机端适配 */
@media (max-width: 480px) {
    .login-box {
        padding: 24px 20px;
    }
    .login-box .captcha-img {
        width: 90px;
    }
}

/* 侧边栏 logo 图标（桌面端与文字并排） */
.admin-sidebar .logo .logo-text {
    margin-left: 8px;
}

/* 移动端菜单开关按钮（桌面端隐藏） */
.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-right: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fff;
    font-size: 18px;
    color: var(--text-primary);
    cursor: pointer;
    flex-shrink: 0;
}
.menu-toggle:active {
    background: var(--bg-content);
}

/* 抽屉遮罩 */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
}
.sidebar-overlay.show {
    display: block;
}

/* 平板端（769px ~ 992px）：侧边栏收窄为图标栏 */
@media (min-width: 769px) and (max-width: 992px) {
    .admin-sidebar {
        width: 60px;
    }
    .admin-sidebar .logo {
        padding: 0;
        font-size: 24px;
    }
    .admin-sidebar .logo .logo-text {
        display: none;
    }
    .admin-sidebar .menu-group-title {
        display: none;
    }
    .admin-sidebar .menu-item {
        padding: 14px 0;
        text-align: center;
    }
    .admin-sidebar .menu-item i {
        display: block;
        width: auto;
        margin-right: 0;
        font-size: 20px;
    }
    .admin-sidebar .menu-item span {
        display: none;
    }
    .admin-main {
        margin-left: 60px;
    }
}

/* 手机端（≤768px）：侧边栏改为抽屉式，菜单文字完整保留 */
@media (max-width: 768px) {
    .admin-sidebar {
        width: 220px;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: none;
    }
    .admin-sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.3);
    }
    .menu-toggle {
        display: inline-flex;
    }
    .admin-main {
        margin-left: 0;
    }
    .admin-header {
        padding: 0 12px;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* 超小屏（≤480px）：隐藏用户名，只留退出按钮 */
@media (max-width: 480px) {
    .admin-header .user-info {
        gap: 8px;
    }
    .admin-header .user-info .username {
        display: none;
    }
    .admin-header .breadcrumb {
        font-size: 13px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* 手机/平板端：表格转为卡片式展示 */
@media (max-width: 992px) {
    .admin-content {
        padding: 12px;
    }
    .card-header {
        padding: 12px 14px;
    }
    .card-body {
        padding: 14px;
    }
    .search-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .search-bar form {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .search-bar .form-control {
        width: 100%;
        flex: 1 1 140px;
    }
    .search-bar .btn {
        flex: 0 0 auto;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .stat-card {
        padding: 14px;
    }
    .stat-card .stat-value {
        font-size: 22px;
    }
    .stats-row {
        flex-direction: column;
        gap: 15px;
    }
    .stats-row > .card {
        flex: 0 0 auto !important;
        width: 100%;
    }

    /* 表格 -> 卡片 */
    .table {
        border-collapse: separate;
    }
    .table thead {
        display: none;
    }
    .table,
    .table tbody,
    .table tr,
    .table td {
        display: block;
        width: 100%;
    }
    .table tr {
        background: #fff;
        border: 1px solid var(--border-light);
        border-radius: 10px;
        padding: 6px 14px;
        margin-bottom: 12px;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    }
    .table tr:hover td {
        background: transparent;
    }
    .table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 14px;
        padding: 9px 0;
        border-bottom: 1px dashed var(--border-light);
        text-align: right;
        font-size: 13px;
        overflow-wrap: anywhere;
    }
    .table td:last-child {
        border-bottom: none;
    }
    .table td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        min-width: 76px;
        text-align: left;
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 13px;
    }
    .table td:not([data-label])::before {
        display: none;
    }
    /* 空数据/跨列单元格居中 */
    .table td[colspan] {
        justify-content: center;
        text-align: center;
        border-bottom: none;
    }
    .table td[colspan]::before {
        display: none;
    }
    .table tr:has(> td[colspan]) {
        border: none;
        box-shadow: none;
        background: transparent;
        padding: 0;
    }
}
