/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --success: #0d904f;
    --warning: #e37400;
    --danger: #d93025;
    --bg: #f5f7fa;
    --card-bg: #fff;
    --text: #202124;
    --text-muted: #5f6368;
    --border: #e0e0e0;
    --sidebar-w: 240px;
}

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

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

/* ── Login / Register ── */
.auth-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 20px;
    background: linear-gradient(135deg, #1a73e8 0%, #0d47a1 100%);
}
.auth-card {
    background: #fff; border-radius: 12px; padding: 40px;
    width: 100%; max-width: 420px; box-shadow: 0 8px 40px rgba(0,0,0,0.15);
}
.auth-card h1 {
    font-size: 22px; text-align: center; margin-bottom: 4px; color: var(--primary);
}
.auth-card .subtitle { text-align: center; color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }
.auth-card label { font-weight: 500; font-size: 13px; display: block; margin: 16px 0 6px; }
.auth-card input[type="text"],
.auth-card input[type="email"],
.auth-card input[type="password"] {
    width: 100%; padding: 10px 14px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 14px; transition: border 0.2s;
}
.auth-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,115,232,0.12); }
.auth-card .remember-row { display: flex; align-items: center; gap: 8px; margin: 16px 0; font-size: 13px; }
.auth-card button {
    width: 100%; padding: 11px; background: var(--primary); color: #fff;
    border: none; border-radius: 8px; font-size: 15px; font-weight: 500;
    cursor: pointer; transition: background 0.2s;
}
.auth-card button:hover { background: var(--primary-dark); }
.auth-card .footer-link { text-align: center; margin-top: 20px; font-size: 13px; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w); background: #1e293b; color: #cbd5e1;
    position: fixed; top: 0; left: 0; bottom: 0; overflow-y: auto;
    padding: 20px 0; z-index: 100;
}
.sidebar-logo {
    padding: 0 20px 20px; border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 12px;
}
.sidebar-logo h2 { color: #fff; font-size: 17px; }
.sidebar-logo span { font-size: 12px; color: #94a3b8; }
.sidebar-nav { padding: 0 12px; }
.sidebar-section { color: #64748b; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; padding: 16px 8px 6px; }
.sidebar a {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    border-radius: 8px; color: #cbd5e1; font-size: 14px; transition: all 0.15s;
}
.sidebar a:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.sidebar a.active { background: var(--primary); color: #fff; }
.sidebar a.disabled { color: #64748b; opacity: .55; cursor: not-allowed; pointer-events: none; }
.sidebar a.disabled:hover { background: none; color: #64748b; }
.sidebar .icon { font-size: 18px; width: 24px; text-align: center; }
.sidebar .badge-red {
    margin-left: auto; background: #c5221f; color: #fff;
    font-size: 11px; font-weight: 700; min-width: 18px; height: 18px;
    line-height: 18px; border-radius: 9px; padding: 0 5px; text-align: center;
}
.sidebar-section[data-toggle="group"] { display: flex; justify-content: space-between; align-items: center; cursor: pointer; user-select: none; }
.sidebar-section[data-toggle="group"]:hover { color: #cbd5e1; }
.sidebar-section .arrow { font-size: 10px; transition: transform 0.2s; }
.sidebar-section.collapsed .arrow { transform: rotate(-90deg); }
.sidebar-group { overflow: hidden; }
.sidebar-group.collapsed { display: none; }

.main {
    margin-left: var(--sidebar-w); flex: 1; padding: 24px 32px;
    max-width: calc(100vw - var(--sidebar-w));
}
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.topbar h3 { font-size: 20px; }
.topbar-right { display: flex; align-items: center; gap: 16px; font-size: 14px; }
.topbar-right .user-name { color: var(--text-muted); }
.btn-sm {
    padding: 6px 14px; border-radius: 6px; font-size: 13px;
    border: 1px solid var(--border); background: #fff; cursor: pointer;
    color: var(--text-muted); transition: all 0.15s;
}
.btn-sm:hover { background: #f1f3f4; text-decoration: none; }
.btn-sm.danger { color: var(--danger); border-color: var(--danger); }
.btn-sm.danger:hover { background: #fce8e6; }
.btn-new {
    padding: 8px 18px; border-radius: 6px; font-size: 13px; font-weight: 600;
    border: none; background: var(--primary); color: #fff; cursor: pointer;
    transition: background 0.15s; display: inline-block;
}
.btn-new:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }

/* ── Form inputs ── */
label { font-weight: 500; font-size: 13px; display: block; margin-bottom: 4px; color: var(--text-muted); }
input[type="text"], input[type="date"], input[type="file"] {
    padding: 8px 12px; border: 1px solid var(--border);
    border-radius: 6px; font-size: 14px; background: #fff;
}
input[type="text"]:focus, input[type="date"]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,115,232,0.1); }
button, .btn-new, input[type="submit"] {
    padding: 10px 24px; background: var(--primary); color: #fff;
    border: none; border-radius: 6px; font-size: 14px; font-weight: 500;
    cursor: pointer; transition: background 0.15s;
}
button:hover { background: var(--primary-dark); }

/* ── Cards & Stats ── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--card-bg); border-radius: 10px; padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06); border: 1px solid var(--border);
}
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; margin-bottom: 6px; }
.stat-card .value { font-size: 28px; font-weight: 700; }
.stat-card .sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.card {
    background: var(--card-bg); border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06); border: 1px solid var(--border);
    margin-bottom: 20px;
}
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 15px; }
.card-body { padding: 20px; }

/* ── Tables ── */
table.data-table {
    width: 100%; border-collapse: collapse; font-size: 13px;
}
table.data-table th {
    text-align: left; padding: 10px 12px; background: #f8f9fa;
    border-bottom: 2px solid var(--border); font-weight: 600; font-size: 12px;
    color: var(--text-muted); text-transform: uppercase;
}
table.data-table td { padding: 9px 12px; border-bottom: 1px solid #f0f0f0; }
table.data-table tr:hover { background: #f8f9fa; }
table.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data-table .highlight { color: var(--danger); font-weight: 600; }

/* ── Flash Messages ── */
.flash-msg {
    padding: 10px 16px; border-radius: 8px; margin-bottom: 16px;
    font-size: 13px; font-weight: 500;
}
.flash-msg.success { background: #e6f4ea; color: #1e7e34; border: 1px solid #b7dfc1; }
.flash-msg.danger { background: #fce8e6; color: #c5221f; border: 1px solid #f5c6cb; }
.flash-msg.warning { background: #fef7e0; color: #b06000; border: 1px solid #feefc3; }
.flash-msg.info { background: #e8f0fe; color: #1a5bbf; border: 1px solid #c6d9f7; }

/* ── Dashboard Modules ── */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.module-card {
    background: var(--card-bg); border-radius: 10px; padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06); border: 1px solid var(--border);
    transition: box-shadow 0.2s, transform 0.2s;
}
.module-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); transform: translateY(-2px); text-decoration: none; }
.module-card .icon-box { font-size: 32px; margin-bottom: 12px; }
.module-card h4 { font-size: 15px; margin-bottom: 6px; color: var(--text); }
.module-card p { font-size: 13px; color: var(--text-muted); }
.module-card .badge {
    display: inline-block; padding: 2px 10px; border-radius: 12px;
    font-size: 11px; font-weight: 600; margin-top: 12px;
}
.badge-active { background: #e6f4ea; color: #1e7e34; }
.badge-soon { background: #fef7e0; color: #b06000; }

/* ── Section header ── */
.section-title { font-size: 18px; font-weight: 600; margin: 28px 0 16px; color: var(--text); }

/* ── 移动端底部导航 ── */
.mobile-nav {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0;
    background: #fff; border-top: 1px solid var(--border);
    z-index: 300; justify-content: space-around;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}
.mobile-nav a {
    flex: 1; text-align: center; padding: 8px 4px 6px;
    font-size: 11px; color: var(--text-muted);
    display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.mobile-nav a:hover { text-decoration: none; color: var(--text-muted); }
.mobile-nav a .icon { font-size: 20px; }
.mobile-nav a.active { color: var(--primary); }

/* ── 手机端菜单按钮与遮罩（桌面隐藏） ── */
.nav-toggle {
    display: none; flex: 0 0 auto;
    align-items: center; justify-content: center;
    width: 34px; height: 34px; margin-right: 8px;
    border: 1px solid var(--border); border-radius: 8px;
    background: #fff; color: var(--text); font-size: 17px; line-height: 1;
    cursor: pointer;
}
.nav-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(15, 23, 42, .45); z-index: 390;
}

/* ── 智能管家布局 ── */
.butler-layout { display: flex; gap: 12px; height: calc(100vh - 170px); }
.butler-topics {
    width: 230px; flex-shrink: 0; background: #fff;
    border: 1px solid #e8eaed; border-radius: 8px; padding: 12px;
    display: flex; flex-direction: column;
}
.butler-chat {
    flex: 1; background: #fff; border: 1px solid #e8eaed;
    border-radius: 8px; padding: 16px; display: flex; flex-direction: column;
}
.butler-topics-toggle { display: none; }

/* ── Responsive ── */
@media (max-width: 768px) {
    /* 侧栏改为抽屉：默认移出屏幕，点菜单按钮滑入 */
    .sidebar {
        display: block; width: 82vw; max-width: 320px;
        transform: translateX(-100%); transition: transform .2s ease;
        z-index: 400; padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
    body.nav-open .sidebar { transform: none; }
    body.nav-open .nav-overlay { display: block; }
    body.nav-open { overflow: hidden; }
    .nav-toggle { display: flex; }

    .main { margin-left: 0; max-width: 100%; padding: 12px 12px 76px; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .module-grid { grid-template-columns: 1fr; }
    .topbar { flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 12px; padding-bottom: 10px; }
    .topbar h3 { flex: 1 1 auto; min-width: 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .topbar-right { flex: 0 0 100%; flex-wrap: wrap; justify-content: flex-end; gap: 6px; font-size: 12.5px; }
    .topbar-right .user-name { display: none; }
    .btn-sm { padding: 4px 9px; font-size: 12.5px; white-space: nowrap; }
    .mobile-nav { display: flex; padding-bottom: env(safe-area-inset-bottom); }

    .butler-layout { flex-direction: column; height: calc(100vh - 130px); min-height: 420px; }
    .butler-topics { width: 100%; display: none; max-height: 42vh; overflow-y: auto; }
    .butler-topics.open { display: flex; }
    .butler-chat { flex: 1; min-height: 0; }
    .butler-topics-toggle { display: inline-block; }
    #orientPanel { left: 0 !important; right: 0 !important; min-width: 0 !important; width: 100% !important; }
}

/* ── 院感管理移动端（手机预览） ── */
.m-tabbar { display: none; }

@media (max-width: 768px) {
    /* 移动端页面内 tab bar（感控平台/环境监测/设置） */
    body.inf-mobile .m-tabbar {
        display: flex; background: #fff; border: 1px solid var(--border);
        border-radius: 8px; margin-bottom: 12px; overflow: hidden;
    }
    body.inf-mobile .m-tabbar a {
        flex: 1; text-align: center; padding: 10px 4px; font-size: 13px;
        color: var(--text-muted); text-decoration: none; white-space: nowrap;
    }
    body.inf-mobile .m-tabbar a.active { background: var(--primary); color: #fff; font-weight: 600; }

    /* 宽表格 → 卡片流（全站通用，JS 给 td 注入 data-label） */
    table.is-card,
    table.is-card tbody { display: block; }
    table.is-card thead { display: none; }
    table.is-card tbody tr {
        display: block; background: #fff; border: 1px solid var(--border);
        border-radius: 10px; margin-bottom: 10px; padding: 8px 14px;
        box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    }
    /* 行上的 hidden 类（筛选/折叠用）在卡片化后仍要生效，别被 display:block 顶掉 */
    table.is-card tbody tr.hidden,
    table.is-card tbody tr[hidden] { display: none; }
    table.is-card tbody td {
        display: flex; justify-content: space-between; align-items: flex-start;
        gap: 12px; padding: 6px 0; border-bottom: 1px dashed #f0f0f0;
        font-size: 14px; text-align: left;
    }
    table.is-card tbody td:last-child { border-bottom: none; }
    table.is-card tbody td::before {
        content: attr(data-label); flex-shrink: 0; font-size: 12px;
        color: #888; font-weight: 600; min-width: 68px; padding-top: 1px;
    }
    table.is-card tbody td.td-actions {
        display: block; padding-top: 8px; margin-top: 4px;
        border-bottom: none; text-align: right;
    }
    table.is-card tbody td.td-actions::before { display: none; }
    table.is-card tbody td.td-hidden { display: none; }
    /* 单元格里有多行内容（标题+小字说明）：标签独占一行，内容整块纵向排 */
    table.is-card tbody td.td-block { display: block; text-align: left; }
    table.is-card tbody td.td-block::before { display: block; margin-bottom: 2px; }
    table.is-card tbody td.td-wide {
        display: block; text-align: center; color: var(--text-muted);
    }
    table.is-card tbody td.td-wide::before { display: none; }

    /* 卡片化不成立的表（合并单元格、无表头）：横向滚动收在自身容器内 */
    .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

    /* 模板里写死行内 display:flex 的工具条，手机上允许换行，别把按钮挤出屏幕 */
    .main [style*="display:flex"],
    .main [style*="display: flex"] { flex-wrap: wrap; }

    /* 弹窗全屏化 + 字段竖排 */
    body.inf-mobile .modal-overlay .modal {
        width: 94%; max-width: 94%; max-height: 90vh; overflow-y: auto;
        border-radius: 12px; padding: 16px;
    }
    body.inf-mobile .modal .row { flex-direction: column; gap: 8px; }
    body.inf-mobile .modal .field { width: 100%; }
    body.inf-mobile .modal input,
    body.inf-mobile .modal select,
    body.inf-mobile .modal textarea { font-size: 16px; }

    /* 按钮放大，便于点按 */
    body.inf-mobile .btn, body.inf-mobile .btn-sm { min-height: 40px; font-size: 14px; }

    /* 筛选栏竖排 */
    body.inf-mobile .filter-bar { flex-direction: column; align-items: stretch; gap: 8px; }
    body.inf-mobile .filter-bar select,
    body.inf-mobile .filter-bar input { width: 100%; font-size: 16px; }
    body.inf-mobile .filter-bar .btn-sm { width: 100%; }

    /* 扫码输入框防 iOS 缩放 */
    body.inf-mobile .scan-input { font-size: 16px; min-width: 0; width: 100%; }

    /* 手机端隐藏（如打印条码行） */
    body.inf-mobile .m-hide { display: none; }
}

/* ── 可搜索下拉框（单框合并：输入即搜索，点选即赋值） ── */
.ss-wrapper { position: relative; width: 100%; }
.ss-wrapper .ss-filter { width: 100%; box-sizing: border-box; font-size: 13px; }
.searchable-panel {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: #fff; border: 1px solid var(--border); border-radius: 6px;
    max-height: 220px; overflow-y: auto; z-index: 1200;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12); display: none;
}
.searchable-item { padding: 8px 12px; font-size: 13px; cursor: pointer; color: var(--text); }
.searchable-item:hover { background: #eef4fd; }
.searchable-empty { padding: 10px 12px; font-size: 13px; color: var(--text-muted); text-align: center; }

/* ── 弹窗底部操作条：内容超高滚动时按钮固定在可视区底部 ── */
.modal-actions,
.sticky-foot { position: sticky; bottom: 0; z-index: 3; background: #fff; }
