/* 森缇纳全域感知系统 - 深色工业风 */
:root {
    --bg-primary: #0d1117;
    --bg-card: #161b22;
    --bg-input: #21262d;
    --border: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --accent: #d4a853;
    --accent-hover: #e6c06b;
    --danger: #f85149;
    --success: #3fb950;
    --warning: #d2991d;
    --blue: #58a6ff;
    --radius: 6px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

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

/* details 收起兜底：部分 WebView 对孙元素不传导 UA 隐藏，显式关断 */
details:not([open]) > *:not(summary) {
    display: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

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

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 48px 40px;
    width: 400px;
    box-shadow: var(--shadow);
}

.login-card h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--accent);
}

.login-card .subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 32px;
}

.form-group {
    margin-bottom: 20px;
}

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

.form-group input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--accent);
}

.login-error {
    color: var(--danger);
    font-size: 13px;
    margin-bottom: 16px;
    min-height: 20px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    width: 100%;
    background: var(--accent);
    color: #0d1117;
    font-weight: 600;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled {
    opacity: 0.7;
    cursor: wait;
}
.btn-primary:disabled::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid transparent;
    border-top-color: #0d1117;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #e04040; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---- 主布局 ---- */
header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-12px); }
    to { opacity: 1; transform: translateY(0); }
}

main {
    animation: fadeIn 0.4s ease 0.1s backwards;
}

header .logo {
    font-size: 18px;
    font-weight: 600;
    color: var(--accent);
}

header .user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--text-secondary);
}

header .user-info .role-badge {
    background: var(--bg-input);
    border: 1px solid var(--border);
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    text-transform: uppercase;
}

header .user-info .role-admin { border-color: var(--accent); color: var(--accent); }
header .user-info .role-editor { border-color: var(--blue); color: var(--blue); }

/* ---- 导航 ---- */
nav {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    gap: 4px;
}

nav a {
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

nav a:hover, nav a.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ---- 内容区 ---- */
main {
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
}

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

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    cursor: default;
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    box-shadow: 0 4px 16px rgba(212,168,83,0.1);
}

.stat-card .stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent);
    transition: color 0.3s ease;
}

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

/* 状态指示灯 */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.status-running {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
    animation: pulse-green 2s infinite;
}

.status-stopped { background: var(--text-secondary); }
.status-maintenance {
    background: var(--warning);
    animation: pulse-yellow 1s infinite;
}

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 4px var(--success); }
    50% { box-shadow: 0 0 12px var(--success), 0 0 20px rgba(63,185,80,0.3); }
}

@keyframes pulse-yellow {
    0%, 100% { box-shadow: 0 0 4px var(--warning); opacity: 1; }
    50% { box-shadow: 0 0 12px var(--warning), 0 0 20px rgba(210,153,29,0.3); opacity: 0.6; }
}

/* ---- 工具栏 ---- */
.toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar input[type="text"] {
    padding: 8px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    min-width: 240px;
    outline: none;
}

.toolbar input[type="text"]:focus { border-color: var(--accent); }

.toolbar select {
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

/* ---- 表格 ---- */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}

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

th {
    background: var(--bg-input);
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

th:hover { color: var(--accent); }

td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tr {
    transition: background 0.2s ease, transform 0.15s ease;
}

tr:hover td {
    background: rgba(212,168,83,0.08);
}

tr:hover td:first-child {
    border-left: 3px solid var(--accent);
}

td.code {
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    color: var(--accent);
    font-weight: 500;
}

td.empty {
    color: var(--text-secondary);
    font-style: italic;
}

/* ---- 分页 ---- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    color: var(--text-secondary);
    font-size: 13px;
}

.pagination button {
    padding: 6px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
}

.pagination button:hover { border-color: var(--accent); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .current { color: var(--accent); font-weight: 600; }

/* ---- 弹窗 ---- */
.modal-overlay {
    /* v3 动效重构：常驻 flex + visibility 切换（display:none 无法参与过渡）。
       浏览器端 CSS transition 完整开合动画；APP 性能模式杀 transition 后为瞬切，
       入场动画由 api.js 以 WAAPI 补播（WAAPI 独立于 CSS 动画系统，不受压制） */
    display: flex;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100;
    align-items: center;
    justify-content: center;
    /* 退场：淡出完成后再隐藏（visibility 延迟到 180ms 后切换） */
    transition: opacity 0.18s ease, visibility 0s linear 0.18s;
}

.modal-overlay.active {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    /* 入场：立即可见 + 淡入 */
    transition: opacity 0.18s ease;
}

/* 修复：森缇纳APP性能模式会把全局 animation-duration 压成 0s，
   部分 Android WebView 下弹窗会卡在入场帧(opacity:0)——遮罩变暗但弹窗透明。
   用 !important 钉住激活态的可见性（CSS 动画优先级低于 !important，无法覆盖）。 */
.modal-overlay.active,
.modal-overlay.active .modal {
    opacity: 1 !important;
    transform: none !important;
}

/* v3: animation 改 transition（translateY+scale 上浮入场，退场同步回弹） */
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
    width: 520px;
    max-height: 80vh;
    overflow-y: auto;
    transform: translateY(16px) scale(0.98);
    transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.modal-overlay.active .modal {
    transform: none;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* 行级渐入 */
tbody tr {
    animation: rowFadeIn 0.3s ease backwards;
}

tbody tr:nth-child(1) { animation-delay: 0.02s; }
tbody tr:nth-child(2) { animation-delay: 0.04s; }
tbody tr:nth-child(3) { animation-delay: 0.06s; }
tbody tr:nth-child(4) { animation-delay: 0.08s; }
tbody tr:nth-child(5) { animation-delay: 0.10s; }

@keyframes rowFadeIn {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}

.modal h2 {
    font-size: 20px;
    margin-bottom: 24px;
    color: var(--accent);
}

.modal .form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* ---- 提示 ---- */
.toast {
    position: fixed;
    top: 24px;
    right: 24px;
    background: var(--success);
    color: #fff;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    z-index: 200;
    display: none;
}

.toast.error { background: var(--danger); }
.toast.show { display: block; animation: fadeOut 2.5s forwards; }

@keyframes fadeOut {
    0% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

/* ---- 响应式 ---- */
@media (max-width: 768px) {
    .login-card { width: 90%; padding: 32px 24px; }
    main { padding: 12px; }
    /* v4：筛选区紧凑化——竖排改为流式换行（日期并排/下拉并排/搜索框独占），
       手机上从 8+ 行压到 3~4 行，不再占满首屏 */
    .toolbar { flex-direction: row; flex-wrap: wrap; gap: 8px; align-items: center; }
    .toolbar input[type="text"] { min-width: auto; flex: 1 1 100%; }
    .toolbar input[type="date"] { flex: 1 1 calc(50% - 40px); min-width: 0; }
    .toolbar select { flex: 0 1 auto; min-width: 84px; }
}

/* ============================================
 * 14. 故障分析建议区（设备详情弹窗）
 * ============================================ */
.advice-panel {
    margin-top: 18px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.advice-panel .panel-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1.2px;
}

.advice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.advice-block {
    background: rgba(13, 17, 23, 0.6);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    transition: border-color 0.2s ease;
}

.advice-block:hover { border-color: rgba(212, 168, 83, 0.35); }

.advice-head {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 1px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.advice-head::before {
    content: '';
    width: 3px;
    height: 12px;
    background: var(--accent);
    box-shadow: 0 0 6px rgba(212, 168, 83, 0.5);
}

.fault-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.fault-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.fault-item .fault-name {
    width: 76px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}

.fault-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.fault-bar i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--warning));
    border-radius: 3px;
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.fault-item .fault-count {
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    color: var(--accent);
    font-size: 12px;
    min-width: 30px;
    text-align: right;
}

.advice-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.advice-list li {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.7;
    padding-left: 14px;
    position: relative;
}

.advice-list li::before {
    content: '▸';
    position: absolute;
    left: 0;
    color: var(--accent);
}

.advice-empty {
    color: var(--text-secondary);
    font-size: 12px;
    font-style: italic;
    padding: 6px 0;
}

/* ============================================
 * 15. 告警推送页
 * ============================================ */
.section-title {
    font-size: 18px;
    color: var(--accent);
    margin: 28px 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    letter-spacing: 1px;
}

.section-title:first-child { margin-top: 0; }

.alarm-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.alarm-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--warning);
    border-radius: var(--radius);
    padding: 18px 20px;
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
}

.alarm-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--warning), transparent);
    transition: left 0.6s ease;
}

.alarm-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.alarm-card:hover::after { left: 100%; }

.alarm-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alarm-title::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning);
    box-shadow: 0 0 8px var(--warning);
    animation: blink-yellow 1.2s ease-in-out infinite;
    flex-shrink: 0;
}

.alarm-device {
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    font-size: 12px;
    color: var(--accent);
    margin-bottom: 8px;
}

.alarm-content {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 10px;
}

.alarm-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    font-size: 11px;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    margin-bottom: 14px;
}

.alarm-meta .meta-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.alarm-actions {
    display: flex;
    gap: 10px;
}

.alarm-empty {
    color: var(--text-secondary);
    padding: 48px;
    text-align: center;
    font-style: italic;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: rgba(13, 17, 23, 0.4);
}

/* 历史状态徽章 */
.alarm-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 2px 10px;
    border-radius: 20px;
}

.alarm-status.done {
    color: var(--success);
    background: rgba(63, 185, 80, 0.1);
    border: 1px solid rgba(63, 185, 80, 0.3);
}

.alarm-status.pending {
    color: var(--warning);
    background: rgba(210, 153, 29, 0.1);
    border: 1px solid rgba(210, 153, 29, 0.3);
}

/* ============================================
 * 16. 告警推送横幅（WebSocket 实时提醒）
 * ============================================ */
.alarm-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 300;
    background: linear-gradient(90deg, rgba(210, 153, 29, 0.2), var(--bg-card) 45%);
    border-bottom: 1px solid var(--warning);
    padding: 12px 24px;
    display: none;
    align-items: center;
    gap: 14px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.alarm-banner.show {
    display: flex;
    animation: banner-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes banner-in {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.alarm-banner .banner-icon {
    font-size: 22px;
    animation: blink-yellow 1s ease-in-out infinite;
    flex-shrink: 0;
}

.alarm-banner .banner-text {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.5;
}

.alarm-banner .banner-text b {
    color: var(--warning);
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    margin-right: 6px;
}

/* ============================================
 * 17. 用户管理页
 * ============================================ */
.role-tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-secondary);
    white-space: nowrap;
}

.role-tag.role-admin { border-color: var(--accent); color: var(--accent); }
.role-tag.role-editor { border-color: var(--blue); color: var(--blue); }
.role-tag.role-viewer { border-color: var(--border); color: var(--text-secondary); }

.user-me-tag {
    display: inline-block;
    margin-left: 6px;
    font-size: 10px;
    color: var(--accent);
    border: 1px solid var(--accent);
    padding: 0 6px;
    border-radius: 3px;
    vertical-align: 1px;
}

/* ============================================
 * 18. 设备搜索下拉（新建告警弹窗）
 * ============================================ */
.combobox { position: relative; }

.combobox-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 240px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    z-index: 20;
    display: none;
}

.combobox-dropdown.show { display: block; animation: slideUp 0.2s ease; }

.dropdown-item {
    padding: 9px 14px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    border-bottom: 1px solid rgba(48, 54, 61, 0.5);
    transition: all 0.15s ease;
}

.dropdown-item:last-child { border-bottom: none; }

.dropdown-item:hover {
    background: rgba(212, 168, 83, 0.1);
    color: var(--accent);
}

.dropdown-item .code {
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    color: var(--accent);
    margin-right: 8px;
}

.dropdown-empty {
    padding: 14px;
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
}

/* 响应式补充 */
@media (max-width: 768px) {
    .advice-grid { grid-template-columns: 1fr; }
    .alarm-cards { grid-template-columns: 1fr; }
    .alarm-banner { padding: 10px 14px; font-size: 13px; }
}

/* ============ 移动端适配（手机/窄屏，≤768px） ============ */
@media (max-width: 768px) {
    /* 顶栏 */
    header {
        padding: 10px 12px;
        flex-wrap: wrap;
        gap: 4px 8px;
    }
    header .logo { font-size: 15px; }
    header .user-info { margin-left: auto; }

    /* 导航：横向可滑动 */
    nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: flex;
        flex-wrap: nowrap;
        padding: 0 8px;
    }
    nav a {
        flex-shrink: 0;
        padding: 9px 13px;
        font-size: 13px;
    }

    main { padding: 12px 12px 28px; }

    /* 搜索区：纵向堆叠 */
    .search-section { flex-direction: column; align-items: stretch; gap: 10px; }
    .search-controls { flex-wrap: wrap; gap: 8px; }
    .search-controls select { flex: 1; min-width: 0; max-width: none; }
    .search-input-large { font-size: 14px; }

    /* 统计卡片：2x2 */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 14px 10px; }
    .stat-card .stat-value { font-size: 22px; }
    .stat-card .stat-label { font-size: 12px; }

    /* 设备表格 → 卡片化（每行一张卡片，两列标签布局）
       仅作用于 index.html 设备表（容器 id=table-container）；
       其他页面（维修/值班/备件/办票/用户/告警）保持「表头可见+横滑表格」模式 */
    #table-container {
        overflow: visible;
        background: transparent;
        border: none;
        border-radius: 0;
    }
    #table-container thead { display: none; }
    #device-tbody tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 2px 14px;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 12px 14px;
        margin-bottom: 10px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    }
    #device-tbody tr:hover td { background: transparent; }
    #device-tbody td {
        display: flex;
        align-items: center;
        gap: 8px;
        border: none;
        padding: 4px 0;
        white-space: normal;
        font-size: 12.5px;
    }
    #device-tbody td::before {
        content: attr(data-label);
        color: var(--text-secondary);
        font-size: 11px;
        flex-shrink: 0;
        min-width: 44px;
    }
    #device-tbody td:nth-child(1)::before { content: "序号"; }
    #device-tbody td:nth-child(2)::before { content: "状态"; }
    #device-tbody td:nth-child(3)::before { content: "系统"; }
    #device-tbody td:nth-child(4)::before { content: "位号"; }
    #device-tbody td:nth-child(5)::before { content: "名称"; }
    #device-tbody td:nth-child(6)::before { content: "位置"; }
    #device-tbody td:nth-child(7)::before { content: "功率"; }
    #device-tbody td:nth-child(8)::before { content: "电流"; }
    #device-tbody td:nth-child(9)::before { content: "变频"; }
    #device-tbody td:nth-child(10) {
        grid-column: 1 / -1;
        margin-top: 4px;
        padding-top: 8px;
        border-top: 1px dashed var(--border);
    }
    #device-tbody td:nth-child(10)::before { content: none; }
    #device-tbody td:nth-child(10) .btn { width: 100%; }
    /* 空行/加载行保持整行 */
    #device-tbody tr.empty { display: table-row; }
    #device-tbody tr.empty td { display: table-cell; }

    /* 弹窗：宽度自适应屏幕 */
    .modal {
        width: auto !important;
        max-width: 92vw;
        max-height: 86vh;
        max-height: 86dvh;
        overflow-y: auto;
        padding: 18px 16px;
    }
    .modal-overlay { padding: 10px; }
    .modal .form-actions { flex-wrap: wrap; gap: 8px; }
    .modal .form-actions .btn { flex: 1; }

    /* 分页 */
    .pagination { flex-wrap: wrap; gap: 6px; }
    .pagination button { padding: 6px 12px; }

    /* 搜索结果卡片 */
    .search-results { padding: 0; }
}

/* 超窄屏（≤400px）微调 */
@media (max-width: 400px) {
    #device-tbody tr { grid-template-columns: 1fr; }
    .stats-grid { gap: 8px; }
}

/* ============================================
 * 15. 移动端导航与全局防横向溢出（2026-08-31 手机适配）
 * ============================================ */
@media (max-width: 768px) {
    html, body { overflow-x: hidden; }
    header { flex-wrap: wrap; row-gap: 6px; }
    nav {
        padding: 0 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    nav::-webkit-scrollbar { display: none; }
    nav a {
        flex: none;
        white-space: nowrap;
        padding: 12px 14px;
        font-size: 13.5px;
    }
}

/* ============================================
 * 16. 移动端优化 v2（2026-09-06）
 * 弹窗✕按钮 / 背景滚动锁定 / HTML确认弹窗 /
 * 表头吸顶 + 操作列吸附 / 触控目标加大 / 软键盘适配
 * ============================================ */

/* 弹窗打开时锁定背景滚动（:has 不支持时优雅降级为原行为） */
body:has(.modal-overlay.active),
body:has(.confirm-overlay.active) { overflow: hidden; }

/* 软键盘弹出时视口压缩自适应（dvh 优先，不支持则回退 vh） */
.modal { max-height: 86vh; max-height: 86dvh; }

/* 弹窗右上角 ✕（由 api.js 自动注入） */
.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 34px;
    height: 34px;
    line-height: 32px;
    text-align: center;
    font-size: 16px;
    color: var(--text-secondary);
    background: rgba(33, 38, 45, 0.92);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    z-index: 20;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.modal-close:hover,
.modal-close:active { color: var(--text-primary); border-color: var(--accent); }

/* HTML 确认弹窗（替代原生 confirm） */
.confirm-overlay {
    /* v3: 同 modal-overlay 的 visibility 动效方案 */
    display: flex;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 150;
    align-items: center;
    justify-content: center;
    padding: 16px;
    transition: opacity 0.16s ease, visibility 0s linear 0.16s;
}
.confirm-overlay.active {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.16s ease;
}

.confirm-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--warning);
    border-radius: 12px;
    padding: 22px 20px;
    width: 360px;
    max-width: 100%;
    transform: translateY(14px) scale(0.98);
    transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.confirm-overlay.active .confirm-box { transform: none; }
.confirm-box.danger { border-left-color: var(--danger); }

.confirm-box .confirm-msg {
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.7;
    margin-bottom: 18px;
    white-space: pre-wrap;
    word-break: break-all;
}

.confirm-box .confirm-actions {
    display: flex;
    gap: 10px;
}
.confirm-box .confirm-actions .btn {
    flex: 1;
    justify-content: center;
    min-height: 40px;
}

@media (max-width: 768px) {
    /* 触控目标加大 */
    .btn-sm { padding: 9px 14px; font-size: 13px; min-height: 38px; }
    .pagination button { padding: 6px 12px; min-height: 38px; min-width: 40px; }
    th, td { padding: 12px 10px; }

    /* 表头吸顶：长表格竖向滚动时列名常驻 */
    .table-container:not(#table-container) th {
        position: sticky;
        top: 0;
        z-index: 1;
    }

    /* 操作列吸附右缘：横滑时按钮永远可见可达
       （table[data-ops-col] 由 api.js 对末列含 .btn 的表格自动打标） */
    .table-container:not(#table-container) table[data-ops-col] th:last-child,
    .table-container:not(#table-container) table[data-ops-col] td:last-child {
        position: sticky;
        right: 0;
        z-index: 2;
        background: var(--bg-card);
        box-shadow: -8px 0 14px -8px rgba(0, 0, 0, 0.55), -1px 0 0 0 var(--border);
    }
    .table-container:not(#table-container) table[data-ops-col] th:last-child {
        z-index: 3;
        background: var(--bg-input);
    }
    .table-container:not(#table-container) tr:hover td:last-child {
        background: #1b232e;
    }
}

/* ============================================
 * 18. 移动端优化 v3（2026-09-06）
 * 按压反馈 / 长文本列截断 / 弹窗内双列表单折行
 * （弹窗开合动效重构见 .modal-overlay 注释 + api.js WAAPI）
 * ============================================ */

/* 按压反馈：transform+filter 全走 GPU 合成层，零 layout/paint；
   APP 性能模式下 transition 被压 0s = 瞬切，仍保留即时触觉反馈 */
.btn:active:not(:disabled),
.pagination button:active:not(:disabled),
nav a:active {
    transform: scale(0.96);
    filter: brightness(1.18);
}

.modal-close:active {
    transform: scale(0.9);
    border-color: var(--accent);
}

/* 表格行按压：按下时整行底色反馈（含设备卡片行） */
.table-container tr:active td {
    background: var(--bg-input);
}

/* 长文本列截断：超长备注/事项/内容不再把表格撑爆。
   排除 #table-container（设备页卡片化布局，td 为 block 不适用列宽限制）；
   排除 colspan 空态行 */
.table-container:not(#table-container) td:not([colspan]) {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .table-container:not(#table-container) td:not([colspan]) { max-width: 200px; }

    /* 弹窗内联双列表单折行：仅匹配含 .form-group 的内联 flex 容器（:has 精确圈定，
       不误伤 confirm-actions/零件标签等其他 flex 行）；字段全宽后输入框不再被挤压截断 */
    .modal div[style*="display:flex"]:has(> .form-group),
    .modal div[style*="display: flex"]:has(> .form-group) { flex-wrap: wrap; }
    .modal div[style*="display:flex"]:has(> .form-group) > .form-group,
    .modal div[style*="display: flex"]:has(> .form-group) > .form-group {
        flex: 1 1 100% !important;
        min-width: 0;
    }
    /* flex 子项溢出修复：允许输入控件收缩到容器宽度 */
    .modal .form-group input,
    .modal .form-group select,
    .modal .form-group textarea { min-width: 0; }
}
