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

:root {
    --primary: #5b6bf5;
    --primary-dark: #4a58d6;
    --primary-light: #eef0ff;
    --danger: #ff4d4f;
    --danger-light: #fff1f0;
    --bg: #f5f7fa;
    --sidebar-bg: #fff;
    --card-bg: #fff;
    --text: #333;
    --text-secondary: #888;
    --border: #e8eaf0;
    --shadow: 0 2px 12px rgba(0,0,0,0.06);
    --radius: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.app {
    display: flex;
    min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
    width: 220px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s;
}

.brand {
    padding: 24px 20px;
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand::before {
    content: "🐱";
}

.menu {
    padding: 12px 0;
    overflow-y: auto;
    flex: 1;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    font-size: 14px;
    border-left: 3px solid transparent;
}

.menu-item:hover {
    color: var(--primary);
    background: var(--primary-light);
}

.menu-item.active {
    color: var(--primary);
    background: var(--primary-light);
    border-left-color: var(--primary);
    font-weight: 500;
}

.menu-item .icon {
    width: 24px;
    margin-right: 12px;
    text-align: center;
}

.menu-divider {
    padding: 12px 20px 4px;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

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

.topbar {
    height: 64px;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 2px 8px rgba(91,107,245,0.3);
}

.menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    margin-right: 16px;
}

.page-title {
    font-size: 18px;
    font-weight: 500;
    flex: 1;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* 角色切换 */
.role-switch {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.5);
    color: #fff;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    transition: background 0.2s;
}

.role-switch:hover {
    background: rgba(255,255,255,0.32);
}

/* 管理员专属菜单，默认隐藏 */
.admin-only {
    display: none;
}

body.is-admin .admin-only {
    display: flex;
}

/* 用户管理 */
.users-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 16px;
}

.search-box input {
    width: 280px;
    max-width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
}

.table-wrap {
    overflow-x: auto;
}

.users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.users-table th {
    text-align: left;
    padding: 12px 14px;
    color: var(--text-secondary);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.users-table td {
    padding: 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.users-table tbody tr:hover {
    background: #fafbff;
}

.cell-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mini-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.cell-name {
    font-weight: 500;
}

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

.plan-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 13px;
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
}

.status-badge.ok { background: #e6f7ed; color: #18a058; }
.status-badge.warn { background: #fff7e6; color: #d48806; }
.status-badge.bad { background: var(--danger-light); color: var(--danger); }

.usage-bar {
    width: 140px;
    height: 6px;
    background: #eef0f5;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 4px;
}

.usage-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.4s;
}

.usage-text {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.row-actions {
    display: flex;
    gap: 12px;
}

.link-btn {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 13px;
    padding: 0;
    font-family: inherit;
}

.link-btn:hover {
    text-decoration: underline;
}

.link-btn.danger {
    color: var(--danger);
}

.table-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 0;
}

/* 弹窗 */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: var(--radius);
    width: 480px;
    max-width: 92vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0,0,0,0.2);
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body {
    padding: 22px;
}

.modal-body .form-group {
    margin-bottom: 16px;
}

.modal-body select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
}

.modal-body select:focus {
    outline: none;
    border-color: var(--primary);
}

.modal-body .form-group input:disabled {
    background: #f5f7fa;
    color: var(--text-secondary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 22px;
    border-top: 1px solid var(--border);
}

.modal-footer .btn {
    background: #f5f7fa;
    color: var(--text);
}

.modal-footer .btn-primary {
    background: var(--primary);
    color: #fff;
}

.modal-footer .btn-primary:hover {
    background: var(--primary-dark);
}

.btn {
    padding: 8px 20px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-primary {
    background: #fff;
    color: var(--primary);
    font-weight: 500;
}

.btn-primary:hover {
    background: #f0f2ff;
}

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

.btn-danger:hover {
    background: #d9363e;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    cursor: pointer;
}

.content {
    padding: 24px;
    flex: 1;
}

.page {
    display: none;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Banner */
.banner {
    background: var(--primary);
    color: #fff;
    padding: 14px 20px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 14px;
}

/* 邮件队列告警条 */
.alert-banner {
    background: #fff7e6;
    border: 1px solid #ffd591;
    color: #ad6800;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-banner.critical {
    background: #fff1f0;
    border-color: #ffccc7;
    color: #cf1322;
}
.mq-actions {
    margin-top: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.mq-hint {
    font-size: 12px;
    color: var(--text-secondary);
}
.mq-resend-all {
    margin-left: auto;
    background: #fff;
    border: 1px solid currentColor;
    color: inherit;
    padding: 4px 12px;
    font-size: 12px;
}
.alert-banner.critical .mq-resend-all { color: #cf1322; }
.mq-failed {
    margin-top: 14px;
    border-top: 1px dashed var(--border, #eee);
    padding-top: 12px;
}
.mq-failed-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}
.mq-checkall {
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}
.mq-failed-list {
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--border, #eee);
    border-radius: 8px;
}
.mq-failed-row {
    display: grid;
    grid-template-columns: 20px 1.4fr 1fr 1.2fr;
    gap: 10px;
    align-items: center;
    padding: 8px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--border, #f0f0f0);
    cursor: pointer;
}
.mq-failed-row:last-child { border-bottom: none; }
.mq-failed-row:hover { background: var(--bg-soft, #fafafa); }
.mq-subj { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mq-to { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mq-err { color: #cf1322; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.mq-empty { padding: 14px; text-align: center; color: var(--text-secondary); font-size: 13px; }

.banner a {
    color: #fff;
    text-decoration: underline;
    margin-left: 4px;
}

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

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    position: relative;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.stat-icon.crown { background: var(--primary-light); }
.stat-icon.data { background: #e6f7ed; }
.stat-icon.device { background: #e6f4ff; }
.stat-icon.wallet { background: #fff7e6; }

.stat-info {
    flex: 1;
}

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

.stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}

.stat-meta {
    width: 100%;
    margin-top: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-secondary);
}

/* 面板 */
.panel {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.panel-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 6px;
}

.panel-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.row.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.row.two-col .panel {
    margin-bottom: 0;
}

/* 设备时间 */
.time-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.time-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
}

.time-label {
    color: var(--text-secondary);
}

.time-value {
    font-weight: 500;
    font-family: "SF Mono", monospace;
}

.time-tip {
    color: var(--danger);
    font-size: 13px;
    margin-top: 4px;
}

/* 环形图 */
.chart-wrap {
    display: flex;
    align-items: center;
    gap: 30px;
}

.donut-chart {
    width: 160px;
    height: 160px;
    position: relative;
}

.donut-chart svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.donut-bg {
    fill: none;
    stroke: #e8eaf0;
    stroke-width: 18;
}

.donut-used {
    fill: none;
    stroke: var(--primary);
    stroke-width: 18;
    stroke-dasharray: 0 314;
    transition: stroke-dasharray 0.6s ease;
}

.donut-today {
    fill: none;
    stroke: #91a7ff;
    stroke-width: 18;
    stroke-dasharray: 0 314;
    stroke-dashoffset: 0;
    transition: stroke-dasharray 0.6s ease;
}

.donut-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.donut-percent {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
}

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

.chart-legend {
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 13px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot.used { background: var(--primary); }
.dot.today { background: #91a7ff; }
.dot.remain { background: #e8eaf0; }

/* 公告 */
.announcement {
    padding: 10px 0;
}

.announcement h2 {
    font-size: 24px;
    color: var(--text);
    margin-bottom: 6px;
}

.announcement h3 {
    font-size: 18px;
    color: var(--text-secondary);
    font-weight: 400;
    margin-bottom: 12px;
}

.announcement p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.8;
}

/* 节点设置 */
.danger-zone {
    border: 1px solid #ffd6d6;
}

.jump-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.jump-links a {
    display: block;
    padding: 10px 14px;
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s;
}

.jump-links a:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.jump-links a.active {
    background: var(--primary);
    color: #fff;
}

.warning-box {
    background: var(--danger-light);
    border: 1px solid #ffccc7;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.warning-title {
    color: var(--danger);
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.warning-box ul {
    margin-top: 12px;
    padding-left: 18px;
    font-size: 13px;
    color: var(--text-secondary);
}

.warning-box li {
    margin-bottom: 6px;
}

.sub-url-box {
    margin-bottom: 20px;
}

.sub-url-box label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.sub-url {
    background: #f5f7fa;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    font-family: "SF Mono", monospace;
    font-size: 13px;
    word-break: break-all;
    color: var(--danger);
    margin-bottom: 8px;
}

.url-tip {
    font-size: 12px;
    color: var(--danger);
}

/* 表单 */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

/* 占位页面 */
.placeholder .panel {
    min-height: 300px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: var(--text-secondary);
}

.placeholder h2 {
    color: var(--text);
    margin-bottom: 12px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(0,0,0,0.8);
    color: #fff;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 200;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* 响应式 */
@media (max-width: 1100px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .row.two-col {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main {
        margin-left: 0;
    }
    .menu-toggle {
        display: block;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .form-grid {
        grid-template-columns: 1fr;
    }
    .chart-wrap {
        flex-direction: column;
        align-items: flex-start;
    }
}
