/* ==================== 全局样式 ==================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #1a73e8;
    --primary-light: #e8f0fe;
    --green: #34a853;
    --red: #ea4335;
    --yellow: #fbbc04;
    --purple: #7c3aed;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --sidebar-width: 240px;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

body {
    font-family: "Inter", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
}

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

code {
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 0.85em;
    background: var(--gray-100);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--gray-700);
}

/* ==================== 蓝牙 MAC 地址高亮 ==================== */
.mac-address {
    display: inline-block;
    font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
    font-size: 0.88em;
    font-weight: 700;
    background: linear-gradient(135deg, #e8f0fe, #ede9fe);
    color: #1a56c4;
    padding: 4px 12px;
    border-radius: 8px;
    border: none;
    letter-spacing: 0.8px;
    white-space: nowrap;
}

/* ==================== 认证页面 ==================== */
.auth-page {
    background: linear-gradient(135deg, #e8f0fe 0%, #f0f4ff 50%, #fef3f2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 420px;
}

.auth-card {
    background: white;
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    padding: 48px 40px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 28px;
}

.logo-img {
    height: 52px;
    width: auto;
}

.auth-card h1 {
    text-align: center;
    font-size: 22px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 4px;
    letter-spacing: 2px;
}

.auth-subtitle {
    text-align: center;
    color: var(--gray-400);
    font-size: 13px;
    margin-bottom: 32px;
    letter-spacing: 0.5px;
}

.auth-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 14px;
    color: var(--gray-500);
}

/* ==================== 表单元素 ==================== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-600);
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    font-size: 14px;
    color: var(--gray-800);
    background: var(--gray-50);
    transition: all 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(26,115,232,0.1);
}

.input-with-btn {
    display: flex;
    gap: 8px;
}

.input-with-btn input { flex: 1; }

.form-hint {
    font-size: 12px;
    margin-top: 6px;
    min-height: 18px;
}

.form-hint.success { color: var(--green); }
.form-hint.error { color: var(--red); }

/* ==================== 按钮 ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover { background: #1557b0; text-decoration: none; }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--gray-200);
}

.btn-outline:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    text-decoration: none;
}

.btn-block { width: 100%; }

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

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ==================== 提示消息 ==================== */
.alert {
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 20px;
}

.alert-error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

/* ==================== 应用布局 ==================== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ==================== 侧边栏 ==================== */
.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 16px;
    border-bottom: 1px solid var(--gray-100);
}

.sidebar-logo {
    height: 34px;
    width: auto;
}

.sidebar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-900);
}

.sidebar-nav {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--gray-600);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--gray-50);
    color: var(--gray-800);
    text-decoration: none;
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-item.disabled {
    color: var(--gray-300);
    cursor: not-allowed;
    pointer-events: none;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

.user-email {
    font-size: 12px;
    color: var(--gray-500);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-logout {
    font-size: 12px;
    color: var(--gray-400);
    padding: 4px 10px;
    border-radius: 6px;
    flex-shrink: 0;
}

.btn-logout:hover {
    background: #fef2f2;
    color: var(--red);
    text-decoration: none;
}

/* ==================== 主内容区 ==================== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px;
    max-width: 1400px;
}

.page-header {
    margin-bottom: 28px;
}

.page-header h2 {
    font-size: 22px;
    font-weight: 600;
    color: var(--gray-900);
}

.page-desc {
    font-size: 14px;
    color: var(--gray-400);
    margin-top: 4px;
}

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

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-card.highlight {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.stat-card.highlight .stat-value,
.stat-card.highlight .stat-label { color: white; }

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon.blue { background: #e8f0fe; color: var(--primary); }
.stat-icon.green { background: #e6f4ea; color: var(--green); }
.stat-icon.red { background: #fce8e6; color: var(--red); }
.stat-icon.purple { background: rgba(255,255,255,0.2); color: white; }

.stat-card:not(.highlight) .stat-icon.purple {
    background: #ede9fe;
    color: var(--purple);
}

.stat-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.2;
}

.stat-label {
    font-size: 13px;
    color: var(--gray-400);
}

/* ==================== 卡片 ==================== */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-100);
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--gray-800);
}

.card-body { padding: 20px; }
.card-footer { padding: 16px 20px; border-top: 1px solid var(--gray-100); }

.record-count {
    font-size: 13px;
    color: var(--gray-400);
}

.card-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-csv {
    display: inline-flex;
    align-items: center;
    color: var(--green);
    border-color: var(--green);
}

.btn-csv:hover {
    background: #e6f4ea;
    border-color: var(--green);
    color: #137333;
}

/* ==================== 内容网格 ==================== */
.content-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 20px;
    margin-bottom: 24px;
}

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.charts-grid .card-wide {
    grid-column: 1 / -1;
}

.chart-container { height: 260px; position: relative; }
.chart-container-wide { height: 280px; position: relative; }

.center-content {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 180px;
}

.today-stats { text-align: center; }

.today-number {
    font-size: 48px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
}

.today-label {
    font-size: 14px;
    color: var(--gray-400);
    margin-top: 8px;
}

.today-detail {
    font-size: 13px;
    color: var(--green);
    margin-top: 4px;
}

/* ==================== 表格 ==================== */
.table-wrapper { overflow-x: auto; padding: 0; }

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

.table th {
    background: var(--gray-50);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--gray-600);
    white-space: nowrap;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
}

.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-100);
    white-space: nowrap;
}

.table tbody tr:hover { background: var(--gray-50); }

.table-compact th,
.table-compact td { padding: 8px 10px; }

.row-pass { }
.row-fail td:first-child {
    border-left: 3px solid var(--red);
}

/* ==================== 徽章 ==================== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.badge-pass {
    background: #e6f4ea;
    color: #137333;
}

.badge-fail {
    background: #fce8e6;
    color: #c5221f;
}

/* ==================== 电池图标 ==================== */
.battery-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}

.battery-bar {
    width: 40px;
    height: 14px;
    border: 1.5px solid var(--gray-300);
    border-radius: 3px;
    padding: 1.5px;
    position: relative;
}

.battery-bar::after {
    content: '';
    position: absolute;
    right: -4px;
    top: 3px;
    width: 2px;
    height: 6px;
    background: var(--gray-300);
    border-radius: 0 1px 1px 0;
}

.battery-fill {
    height: 100%;
    border-radius: 1px;
    transition: width 0.3s;
}

.battery-fill.green { background: var(--green); }
.battery-fill.yellow { background: var(--yellow); }
.battery-fill.red { background: var(--red); }

/* ==================== 筛选表单 ==================== */
.filter-form {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
}

.filter-group {
    flex: 1;
    min-width: 140px;
}

.filter-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-500);
    margin-bottom: 4px;
}

.filter-group input,
.filter-group select {
    width: 100%;
    padding: 7px 12px;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    font-size: 13px;
    background: var(--gray-50);
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}

.filter-actions {
    display: flex;
    gap: 8px;
    padding-bottom: 1px;
}

/* ==================== 分页 ==================== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.page-btn {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--gray-600);
    transition: all 0.15s;
}

.page-btn:hover {
    background: var(--gray-100);
    text-decoration: none;
}

.page-btn.active {
    background: var(--primary);
    color: white;
}

.page-ellipsis {
    padding: 6px 4px;
    color: var(--gray-400);
}

/* ==================== 空状态 ==================== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-400);
}

.empty-state p:first-child {
    font-size: 16px;
    color: var(--gray-600);
    margin-bottom: 8px;
}

.text-muted { color: var(--gray-400); font-size: 13px; }

/* ==================== 响应式 ==================== */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .content-grid { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
    }
    .main-content {
        margin-left: 0;
        padding: 20px;
    }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .filter-form { flex-direction: column; }
}

/* ==================== Toast 通知 ==================== */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: white;
    border-radius: 14px;
    padding: 16px 20px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15), 0 2px 8px rgba(0,0,0,0.08);
    min-width: 320px;
    max-width: 420px;
    pointer-events: auto;
    transform: translateX(120%);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    border-left: 4px solid var(--gray-300);
}

.toast.toast-pass { border-left-color: var(--green); }
.toast.toast-fail { border-left-color: var(--red); }

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

.toast-hide {
    transform: translateX(120%);
    opacity: 0;
    transition: all 0.35s ease-in;
}

.toast-icon {
    flex-shrink: 0;
    margin-top: 2px;
}

.toast-body { flex: 1; min-width: 0; }

.toast-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 1px 8px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

.toast-badge.toast-pass { background: #e6f4ea; color: #137333; }
.toast-badge.toast-fail { background: #fce8e6; color: #c5221f; }

.toast-mac {
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 13px;
    font-weight: 700;
    color: #1a56c4;
    background: linear-gradient(135deg, #e8f0fe, #ede9fe);
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    margin-top: 4px;
    letter-spacing: 0.5px;
}

.toast-detail {
    font-size: 12px;
    color: var(--gray-400);
    margin-top: 4px;
}

@keyframes toast-progress {
    from { width: 100%; }
    to { width: 0%; }
}
