/* QMS v3.1 Stylesheet */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --primary: #2c3e50;
    --accent: #3498db;
    --bg: #f5f7fa;
    --card-bg: #fff;
    --border: #e0e6ed;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --ok: #27ae60;
    --warn: #f39c12;
    --err: #e74c3c;
    --sidebar-w: 220px;
}
body { font-family: "Microsoft YaHei", "PingFang SC", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* Top Bar */
.top-bar { background: var(--primary); color: #fff; height: 52px; position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.top-bar-inner { max-width: 1600px; margin: 0 auto; height: 100%; display: flex; align-items: center; padding: 0 20px; }
.logo { color: #fff; text-decoration: none; font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 8px; white-space: nowrap; flex: 0 0 auto; }
.logo-icon { font-size: 24px; }
.menu-toggle { display: none; background: none; border: none; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; padding: 8px 10px; margin-right: 6px; border-radius: 6px; -webkit-tap-highlight-color: transparent; }
.menu-toggle:hover { background: rgba(255,255,255,.15); }
.top-nav { margin-left: auto; display: flex; gap: 2px; flex-wrap: nowrap; min-width: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.top-nav::-webkit-scrollbar { display: none; }
.top-nav a { color: rgba(255,255,255,.7); text-decoration: none; padding: 8px 10px; border-radius: 6px; transition: .2s; white-space: nowrap; flex: 0 0 auto; font-size: 13px; }
.top-nav a:hover, .top-nav a.active { color: #fff; background: rgba(255,255,255,.15); }
.nav-meta { white-space: nowrap; flex: 0 0 auto; }
.nav-meta-co { max-width: 210px; overflow: hidden; text-overflow: ellipsis; }

/* Layout */
.main-layout { display: flex; max-width: 1600px; margin: 0 auto; }
.sidebar { width: var(--sidebar-w); flex-shrink: 0; padding: 16px 0 80px; position: sticky; top: 52px; height: calc(100vh - 52px); overflow-y: auto; border-right: 1px solid var(--border); background: #fff; }
.content { flex: 1; padding: 24px; min-width: 0; }

/* 侧边栏抽屉遮罩（平板/手机端） */
.nav-overlay { display: none; position: fixed; top: 52px; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.4); z-index: 890; }
.nav-overlay.show { display: block; }
body.nav-open { overflow: hidden; }

/* Sidebar */
.nav-group { margin-bottom: 4px; }
.nav-group-title {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    background: transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: .15s;
    border-radius: 6px;
}
.nav-group-title:hover { background: var(--bg); }
.nav-group.expanded .nav-group-title { color: var(--accent); background: #ebf5fb; }
.nav-group-label { display: flex; align-items: center; gap: 6px; }
.nav-group-caret { font-size: 11px; color: var(--text-light); transition: transform .2s; }
.nav-group.expanded .nav-group-caret { transform: rotate(180deg); color: var(--accent); }
.nav-group-items { display: none; padding-left: 12px; }
.nav-group.expanded .nav-group-items { display: block; }
.nav-item { display: block; padding: 8px 16px; color: var(--text); text-decoration: none; font-size: 13px; transition: .15s; border-left: 3px solid transparent; }
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: #ebf5fb; border-left-color: var(--accent); color: var(--accent); font-weight: 600; }

/* Page Header */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 24px; margin-bottom: 4px; }
.page-desc { color: var(--text-light); font-size: 13px; }
.iso-ref { color: var(--text-light); font-size: 12px; margin-top: 4px; }
.page-actions { display: flex; gap: 8px; }

/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card { background: var(--card-bg); border-radius: 10px; padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.08); border-left: 4px solid var(--accent); transition: .2s; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.kpi-label { font-size: 13px; color: var(--text-light); margin-bottom: 8px; }
.kpi-value { font-size: 28px; font-weight: 700; line-height: 1.2; }
.kpi-sub { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.gauge-box { padding: 6px 0 2px; text-align: center; }
.kpi-ok { border-left-color: var(--ok); }
.kpi-ok .kpi-value { color: var(--ok); }
.kpi-warn { border-left-color: var(--warn); }
.kpi-warn .kpi-value { color: var(--warn); }
.kpi-err { border-left-color: var(--err); }
.kpi-err .kpi-value { color: var(--err); }
.kpi-info { border-left-color: var(--accent); }

/* Charts */
.chart-section { margin-bottom: 24px; }
.chart-card { background: var(--card-bg); border-radius: 10px; padding: 24px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.chart-card h2 { font-size: 16px; margin-bottom: 16px; }

/* Quick Links */
.quick-links { margin-bottom: 24px; }
.quick-links h2 { font-size: 16px; margin-bottom: 12px; }
.quick-link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.quick-link { display: flex; flex-direction: column; align-items: center; padding: 20px 12px; background: var(--card-bg); border-radius: 10px; text-decoration: none; color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); transition: .2s; }
.quick-link:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.ql-icon { font-size: 28px; margin-bottom: 8px; }
.ql-name { font-size: 13px; font-weight: 600; }

/* Input Section */
.input-section { background: var(--card-bg); border-radius: 10px; padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.input-section h3 { font-size: 14px; margin-bottom: 12px; color: var(--text-light); }
.input-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.input-field { display: flex; flex-direction: column; }
.input-field label { font-size: 12px; color: var(--text-light); margin-bottom: 4px; }
.input-field input, .input-field select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.input-field input:focus, .input-field select:focus { outline: none; border-color: var(--accent); }

/* 可搜索下拉（searchable select）——由 static/js/searchable-select.js 自动增强 */
.ss { position: relative; display: inline-block; vertical-align: middle; }
.ss-input {
    width: 100%;
    padding: 8px 28px 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    box-sizing: border-box;
}
.ss-input:focus { outline: none; border-color: var(--accent); }
.ss::after {
    content: '▾';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    font-size: 12px;
    pointer-events: none;
}
.ss-drop {
    display: none;
    position: absolute;
    top: calc(100% + 3px);
    left: 0;
    right: 0;
    min-width: 100%;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0,0,0,.14);
    max-height: 260px;
    overflow-y: auto;
    z-index: 9999;
}
.ss-open .ss-drop { display: block; }
.ss-opt {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}
.ss-opt:hover, .ss-opt.ss-opt-hover { background: #ebf5fb; color: var(--accent); }
.ss-opt.ss-opt-sel { background: #e8f4fd; color: var(--accent); font-weight: 600; }
.ss-empty { padding: 10px 12px; font-size: 12px; color: var(--text-light); text-align: center; }

/* Data Table */
.data-section { background: var(--card-bg); border-radius: 10px; padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.data-section h3 { font-size: 14px; margin-bottom: 12px; color: var(--text-light); }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead { background: #f8f9fb; }
.data-table th { padding: 10px 12px; text-align: left; font-weight: 600; color: var(--text); border-bottom: 2px solid var(--border); white-space: nowrap; position: sticky; top: 0; }
.data-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover { background: #f8f9fb; }
.row-num { color: var(--text-light); font-size: 12px; }
.cell-auto { color: var(--text-light); font-style: italic; }
.action-cell { white-space: nowrap; }

/* Badges */
.badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-ok { background: #d4edda; color: #155724; }
.badge-warn { background: #fff3cd; color: #856404; }
.badge-err { background: #f8d7da; color: #721c24; }

/* Navigation Page */
.nav-section { margin-bottom: 28px; }
.nav-section-title { font-size: 18px; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 2px solid var(--border); }
.nav-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.nav-card { display: flex; align-items: flex-start; gap: 12px; padding: 16px; background: var(--card-bg); border-radius: 10px; text-decoration: none; color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); transition: .2s; }
.nav-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.nav-card-icon { font-size: 32px; flex-shrink: 0; }
.nav-card-name { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.nav-card-desc { font-size: 12px; color: var(--text-light); margin-bottom: 4px; }
.nav-card-iso { font-size: 11px; color: var(--text-light); }

/* Buttons */
.btn { display: inline-block; padding: 8px 20px; border: none; border-radius: 6px; font-size: 14px; cursor: pointer; text-decoration: none; transition: .2s; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #2980b9; }
.btn-danger { background: var(--err); color: #fff; }
.btn-danger:hover { background: #c0392b; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 4px 12px; font-size: 12px; }

/* Flash Messages */
.flash { padding: 10px 16px; border-radius: 6px; margin-bottom: 12px; }
.flash-success { background: #d4edda; color: #155724; }
.flash-warning { background: #fff3cd; color: #856404; }
.flash-info { background: #d1ecf1; color: #0c5460; }

/* Empty Hint */
.empty-hint { color: var(--text-light); text-align: center; padding: 40px; font-size: 14px; }

/* Quality History Tabs */
.qh-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 16px; border-bottom: 2px solid var(--border); padding-bottom: 0; }
.qh-tab { padding: 10px 18px; background: transparent; border: none; border-bottom: 3px solid transparent; cursor: pointer; font-size: 13px; color: var(--text-light); transition: .2s; font-family: inherit; }
.qh-tab:hover { color: var(--accent); background: rgba(52,152,219,.05); }
.qh-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.qh-tab-content { display: none; }
.qh-tab-content.active { display: block; }

/* Quality History Sub-tabs */
.qh-sub-tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.qh-sub-tab { padding: 6px 14px; background: #eef2f7; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text); transition: .2s; font-family: inherit; }
.qh-sub-tab:hover { background: #e2e8f0; }
.qh-sub-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.qh-insp-content { display: none; }
.qh-insp-content.active { display: block; }

/* Quality History Sections */
.qh-section { margin-bottom: 24px; }
.qh-section h3 { font-size: 15px; margin-bottom: 10px; color: var(--primary); border-left: 4px solid var(--accent); padding-left: 8px; }

/* Quality History KPI Cards */
.qh-kpi-row { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.qh-kpi-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 14px 20px; flex: 1; min-width: 120px; text-align: center; }
.qh-kpi-label { font-size: 12px; color: var(--text-light); margin-bottom: 4px; }
.qh-kpi-value { font-size: 28px; font-weight: 700; color: var(--accent); }

/* Quality History Chart */
.qh-chart-container { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }

/* Quality History Photo Grid */
.qh-photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.qh-photo-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.qh-photo-card img { width: 100%; height: 160px; object-fit: cover; cursor: pointer; border-bottom: 1px solid var(--border); }
.qh-photo-card img:hover { opacity: .85; }
.qh-photo-info { padding: 8px 10px; font-size: 12px; line-height: 1.5; color: var(--text); }
.qh-photo-info div { margin-bottom: 2px; }

/* Quality History Batch Table */
.qh-batch-table { font-size: 12px; }
.qh-batch-table th, .qh-batch-table td { white-space: nowrap; }

/* Cell error highlight */
.cell-err { color: var(--err); font-weight: 600; }

/* Responsive —— 电脑 / 平板 / 手机适配（v3.1） */

/* 小笔记本断点 ≤1400px：顶栏项目收紧，确保全部单行不折行、不横向溢出 */
@media (max-width: 1400px) {
    .top-nav { gap: 0; }
    .top-nav a { padding: 8px 8px; }
}

/* 平板断点 ≤1024px：侧边栏转为抽屉式，左上角显示汉堡按钮 */
@media (max-width: 1024px) {
    .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
    .sidebar {
        position: fixed;
        top: 52px;
        left: 0;
        bottom: 0;
        width: 260px;
        height: auto;
        z-index: 900;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: 2px 0 16px rgba(0,0,0,.15);
        border-right: 1px solid var(--border);
    }
    .sidebar.open { transform: translateX(0); }
    .nav-meta { display: none; }
    .nav-item { padding: 12px 18px; font-size: 14px; }
    .content { padding: 16px; }
    /* 触控友好（平板 + 手机）：输入控件放大、字体 16px 防 iOS 自动缩放、按钮加大点按目标 */
    .input-field input, .input-field select,
    .dh-form-field input, .dh-form-field select, .dh-form-field textarea {
        font-size: 16px;
        padding: 10px 12px;
    }
    .btn { padding: 10px 18px; min-height: 40px; }
    .btn-sm { min-height: 36px; }
    .input-field input[type="number"] { min-height: 40px; }
}

/* 手机断点 ≤768px */
@media (max-width: 768px) {
    .top-bar-inner { padding: 0 10px; }
    .logo-text { font-size: 15px; }
    .top-nav { gap: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .top-nav a { padding: 8px 12px; font-size: 13px; white-space: nowrap; }
    .content { padding: 12px; }
    .page-header h1 { font-size: 20px; }
    .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .quick-link-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
    .qh-kpi-card { min-width: 100px; }
    .qh-photo-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    /* 触控友好：输入控件放大、字体 16px 防 iOS 自动缩放 */
    .input-field input, .input-field select,
    .dh-form-field input, .dh-form-field select, .dh-form-field textarea {
        font-size: 16px;
        padding: 10px 12px;
    }
    .btn { padding: 10px 18px; }
    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 8px 10px; }
}
