/* 台区AI分析系统 - 全局样式 */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #3498db;
    --primary-dark: #2980b9;
    --success: #27ae60;
    --danger: #e74c3c;
    --warning: #f39c12;
    --bg: #f5f7fa;
    --card: #ffffff;
    --text: #333333;
    --text-light: #666666;
    --border: #e0e6ed;
    --sidebar-bg: #1f2937;
    --sidebar-text: #cbd5e1;
}

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

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

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

.sidebar {
    width: 200px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
}

.brand {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.brand h2 {
    font-size: 18px;
    color: #fff;
    margin-bottom: 4px;
}

.brand p {
    font-size: 11px;
    color: #94a3b8;
}

.nav {
    flex: 1;
    padding: 10px 0;
}

.nav-item {
    display: block;
    padding: 12px 20px;
    color: var(--sidebar-text);
    font-size: 14px;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: rgba(255,255,255,0.05);
    color: #fff;
}

.nav-item.active {
    background: rgba(52, 152, 219, 0.15);
    color: #fff;
    border-left-color: var(--primary);
}

.user {
    padding: 15px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.user a { color: #94a3b8; }
.user a:hover { color: #fff; }

.main {
    flex: 1;
    margin-left: 200px;
    padding: 20px;
    min-width: 0;
}

/* 页面头部 */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.page-header h1 {
    font-size: 20px;
    font-weight: 600;
}

.quick-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.time {
    color: var(--text-light);
    font-size: 12px;
}

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

.stat-card {
    background: var(--card);
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border-left: 4px solid var(--primary);
}

.stat-card.highlight {
    border-left-color: var(--warning);
}

.stat-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

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

/* 面板 */
.panel-row {
    margin-bottom: 20px;
}

.panel {
    background: var(--card);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    overflow: hidden;
}

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

.panel-header h3 {
    font-size: 15px;
    font-weight: 600;
}

.panel-header a {
    font-size: 12px;
}

/* 表格 */
.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    min-width: 900px;
}

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

.data-table th {
    background: #f8fafc;
    font-weight: 600;
    color: var(--text-light);
    position: sticky;
    top: 0;
}

.data-table tr:hover {
    background: #f8fafc;
}

.data-table .empty {
    text-align: center;
    color: #94a3b8;
    padding: 40px;
}

/* 标签 */
.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.tag-success {
    background: #dcfce7;
    color: var(--success);
}

.tag-fail {
    background: #fee2e2;
    color: var(--danger);
}

.tag-primary {
    background: #dbeafe;
    color: var(--primary);
}

.tag-warn {
    background: #fef3c7;
    color: #b45309;
}

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

.btn-danger:hover {
    background: #b91c1c;
    color: #fff;
}

.ops .btn {
    margin: 2px;
}

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    background: var(--primary);
    color: #fff;
    transition: background 0.2s;
}

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

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

.btn-xs {
    padding: 2px 8px;
    font-size: 11px;
}

.btn-light {
    background: #e2e8f0;
    color: var(--text);
}

.btn-light:hover {
    background: #cbd5e1;
    color: var(--text);
}

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

.btn-block {
    width: 100%;
    padding: 10px;
    font-size: 14px;
}

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

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

.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 14px;
}

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

.input-sm {
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    min-width: 100px;
}

.inline-search {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* 登录页 */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
}

.login-box {
    width: 360px;
    background: var(--card);
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.login-box h1 {
    font-size: 22px;
    text-align: center;
    margin-bottom: 6px;
}

.subtitle {
    text-align: center;
    color: var(--text-light);
    font-size: 12px;
    margin-bottom: 24px;
}

.alert {
    padding: 10px 12px;
    border-radius: 5px;
    margin-bottom: 16px;
    font-size: 12px;
}

.alert-error {
    background: #fee2e2;
    color: var(--danger);
}

.login-tip {
    text-align: center;
    color: #94a3b8;
    font-size: 11px;
    margin-top: 16px;
}

/* 分页 */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-top: 1px solid var(--border);
}

.page-link {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 12px;
}

.page-link:hover {
    background: var(--bg);
}

.page-info {
    font-size: 12px;
    color: var(--text-light);
}

/* 可排序表头 */
.data-table th a.sortable {
    color: var(--text-light);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px;
    border-radius: 3px;
}

.data-table th a.sortable:hover {
    color: var(--primary);
    background: rgba(52, 152, 219, 0.08);
}

.data-table th a.sortable.active {
    color: var(--primary);
    font-weight: 700;
}

/* 抄表记录宽表格：列宽按内容自适应（够放数字即可），字号保持可读 */
.wide-table {
    overflow-x: visible;
}

.wide-table .data-table {
    width: auto;              /* 不拉伸：列宽只按内容需求分配 */
    min-width: 0;
    table-layout: auto;       /* 关闭固定布局，改由内容决定列宽 */
    font-size: 13px;
    border-collapse: collapse;
}

.wide-table .data-table th,
.wide-table .data-table td {
    padding: 5px 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.35;
}

.wide-table .data-table thead th {
    font-size: 12.5px;
    letter-spacing: 0;
    vertical-align: top;
}

.wide-table .data-table tbody td {
    font-size: 13px;
}

.wide-table .data-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* 每列之间加竖线分隔 */
.readings-table th,
.readings-table td {
    border-right: 1px solid var(--border);
}

.readings-table th:last-child,
.readings-table td:last-child {
    border-right: none;
}

.readings-table thead th {
    border-bottom: 2px solid var(--border);
}

.readings-table tbody tr:hover td {
    background: #f8fafc;
}

/* 各列宽度：贴合内容，不额外留白 */
.readings-table th.c-no, .readings-table td.c-no { min-width: 36px; text-align: center; color: var(--text-light); }
.readings-table th.c-time, .readings-table td.c-time { min-width: 72px; }
.readings-table th.c-nid, .readings-table td.c-nid { min-width: 52px; text-align: center; }
.readings-table th.c-addr, .readings-table td.c-addr { min-width: 84px; }
.readings-table th.c-site, .readings-table td.c-site { min-width: 96px; }
/* auto 布局下 td 的 max-width 无效，用内联块截断长地址 */
.readings-table td.c-site .ellip {
    display: inline-block;
    vertical-align: bottom;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.readings-table th.c-meter, .readings-table td.c-meter { min-width: 80px; }
.readings-table th.c-phase, .readings-table td.c-phase { min-width: 28px; text-align: center; }
.readings-table th.c-level, .readings-table td.c-level { min-width: 28px; text-align: center; }
.readings-table th.c-v, .readings-table td.c-v { min-width: 46px; }
.readings-table th.c-i, .readings-table td.c-i { min-width: 48px; }
.readings-table th.c-pf, .readings-table td.c-pf { min-width: 40px; }
.readings-table th.c-pw, .readings-table td.c-pw { min-width: 52px; }
.readings-table th.c-freq, .readings-table td.c-freq { min-width: 44px; }
.readings-table th.c-kwh, .readings-table td.c-kwh { min-width: 54px; }
.readings-table th.c-rssi, .readings-table td.c-rssi { min-width: 36px; }
.readings-table th.c-cnt, .readings-table td.c-cnt { min-width: 44px; text-align: center; }
.readings-table th.c-ok, .readings-table td.c-ok { min-width: 48px; text-align: center; }

/* 12 位编码列略收字距 */
.readings-table td.c-addr,
.readings-table td.c-meter {
    letter-spacing: -0.2px;
}

.readings-table td.c-addr,
.readings-table td.c-meter,
.readings-table td.c-time {
    font-size: 12.5px;
}

/* 表号档案：按模块地址分组 */
.mod-group {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 14px;
    overflow: hidden;
    background: #fff;
}

.mod-group-head {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 14px;
    background: #eef4fb;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.mod-group-title { font-size: 14px; color: var(--text); }
.mod-group-title b { color: #1e6fb8; letter-spacing: 0.5px; }
.mod-group-sub { font-size: 12px; color: var(--text-light); }
.mod-group-count { font-size: 12px; color: var(--text-light); margin-left: auto; }

/* 成功率条 */
.rate-bar {
    position: relative;
    height: 18px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    min-width: 80px;
}

.rate-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: var(--success);
    opacity: 0.85;
}

.rate-bar span {
    position: relative;
    z-index: 1;
    display: block;
    text-align: center;
    font-size: 11px;
    line-height: 18px;
    color: var(--text);
}

/* 错误页 */
.error-page {
    text-align: center;
    padding: 80px 20px;
}

.error-page h1 {
    font-size: 80px;
    color: var(--primary);
    margin-bottom: 10px;
}

.error-page p {
    font-size: 16px;
    color: var(--text-light);
    margin-bottom: 24px;
}

/* 弹窗 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: #fff;
    border-radius: 8px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.modal-header h3 {
    font-size: 15px;
}

.modal-close {
    font-size: 24px;
    cursor: pointer;
    color: var(--text-light);
}

.modal-close:hover {
    color: var(--text);
}

#detailBody {
    padding: 16px;
    overflow: auto;
    font-size: 12px;
    line-height: 1.6;
    background: #f8fafc;
    white-space: pre-wrap;
    word-break: break-all;
}

/* 抄表记录：表头列级搜索 */
.readings-form {
    margin: 0;
}

.data-table .filter-row th {
    background: #fff;
    padding: 3px 4px;
    vertical-align: top;
    border-bottom: 2px solid var(--border);
    overflow: visible;
}

.data-table .filter-row input.input-xs,
.data-table .filter-row select.input-xs {
    width: 100%;
    min-width: 0;
    padding: 2px 3px;
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 11px;
    line-height: 1.3;
    background: #fff;
    color: var(--text);
}

/* auto 布局下输入框必须给固定宽度，否则默认 size 会把列撑宽 */
.readings-table .filter-row th.c-time input.input-xs { width: 68px; }
.readings-table .filter-row th.c-nid input.input-xs { width: 48px; }
.readings-table .filter-row th.c-addr input.input-xs { width: 80px; }
.readings-table .filter-row th.c-site input.input-xs { width: 92px; }
.readings-table .filter-row th.c-meter input.input-xs { width: 76px; }
.readings-table .filter-row th.c-phase select.input-xs { width: 34px; }
.readings-table .filter-row th.c-level input.input-xs { width: 30px; }
.readings-table .filter-row th.c-v input.input-xs { width: 42px; }
.readings-table .filter-row th.c-i input.input-xs { width: 44px; }
.readings-table .filter-row th.c-pf input.input-xs { width: 36px; }
.readings-table .filter-row th.c-pw input.input-xs { width: 48px; }
.readings-table .filter-row th.c-freq input.input-xs { width: 40px; }
.readings-table .filter-row th.c-kwh input.input-xs { width: 50px; }
.readings-table .filter-row th.c-rssi input.input-xs { width: 34px; }
.readings-table .filter-row th.c-cnt input.input-xs { width: 38px; }
.readings-table .filter-row th.c-ok select.input-xs { width: 44px; }

.data-table .filter-row input.input-xs:focus,
.data-table .filter-row select.input-xs:focus {
    outline: none;
    border-color: var(--primary);
}

.data-table .filter-row th > input.input-xs + input.input-xs,
.data-table .filter-row th > input.input-xs + select.input-xs {
    margin-top: 4px;
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    background: #f8fafc;
}

.filter-actions .hint {
    font-size: 11px;
    color: var(--text-light);
    margin-left: auto;
}

/* 让表头排序链接与搜索框垂直排列 */
.data-table thead th {
    vertical-align: top;
}

/* 响应式 */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: relative;
        flex-direction: row;
        height: auto;
    }
    .main {
        margin-left: 0;
    }
    .nav {
        display: flex;
        flex-wrap: wrap;
    }
    .nav-item {
        padding: 8px 12px;
        font-size: 12px;
    }
    .brand, .user {
        display: none;
    }
    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
