/* ================================================================
   阀门样品检验管理系统 - 全局样式
   ================================================================ */

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

:root {
    --primary-color: #007AFF;
    --primary-hover: #0062CC;
    --success-color: #34C759;
    --warning-color: #FF9F0A;
    --danger-color: #FF3B30;
    --sidebar-width: 250px;
    --header-height: 60px;
    --combo-z: 1000;
    --sidebar-bg: #f5f5f7;
    --sidebar-hover: #e5e5ea;
    --sidebar-active: #007AFF;
    --sidebar-text: #1d1d1f;
    --sidebar-text-muted: #6e6e73;
    --bg-color: #f5f5f7;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.08);
    --card-hover-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg-color);
    color: #1d1d1f;
    -webkit-font-smoothing: antialiased;
}

/* ---- 页面切换 ---- */
.page { display: none; }
.page.active { display: block; }

/* ---- 登录页 ---- */
#loginPage {
    justify-content: center; align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f5f5f7 0%, #e5e5ea 50%, #d1d1d6 100%);
}
#loginPage.page.active {
    display: flex;
}
.login-container {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 40px; border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04);
    width: 400px;
}
.login-header { text-align: center; margin-bottom: 30px; }
.login-header h1 { color: #1d1d1f; font-size: 28px; margin-bottom: 10px; font-weight: 600; }
.login-header h2 { color: #6e6e73; font-size: 18px; font-weight: 400; }
.login-form .form-group { margin-bottom: 20px; }
.login-form label { display: block; margin-bottom: 8px; color: #333; font-weight: 500; }
.login-form input { width: 100%; padding: 12px; border: 1px solid #d1d1d6; border-radius: 8px; font-size: 14px; transition: all 0.2s; }
.login-form input:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(0,122,255,0.12); }
.login-footer { text-align: center; margin-top: 20px; color: #8e8e93; font-size: 12px; }

/* ---- 主布局 ---- */
#mainPage {
    min-height: 100vh;
}
#mainPage.page.active {
    display: flex;
}

/* 侧边栏 */
.sidebar {
    width: var(--sidebar-width); background: var(--sidebar-bg); color: var(--sidebar-text);
    display: flex; flex-direction: column;
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 100;
    border-right: 1px solid #e5e5ea;
}
.sidebar-header {
    padding: 10px 12px; border-bottom: 1px solid #e5e5ea;
    text-align: center; background: #ffffff;
}
.sidebar-logo {
    width: 100%; height: auto; max-height: 56px; object-fit: contain;
}
.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-item {
    display: flex; align-items: center; padding: 10px 20px; margin: 2px 8px;
    color: var(--sidebar-text-muted); text-decoration: none; transition: all 0.2s; gap: 10px;
    border-radius: 8px; font-size: 14px;
}
.nav-item:hover { color: var(--sidebar-text); background: var(--sidebar-hover); }
.nav-item.active { color: #ffffff; background: var(--sidebar-active); }
.sidebar-footer { padding: 16px; border-top: 1px solid #e5e5ea; }

/* 主内容区 */
.main-content { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; }

/* 顶部栏 */
.top-bar {
    height: var(--header-height); background: rgba(255,255,255,0.85);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid #e5e5ea;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; position: sticky; top: 0; z-index: 99;
}
.breadcrumb { font-size: 15px; font-weight: 500; color: #1d1d1f; }
.user-info { display: flex; align-items: center; gap: 8px; color: #6e6e73; }

/* 内容页面 */
.content-page { display: none; padding: 24px; flex: 1; }
.content-page.active { display: block; }

.page-header {
    margin-bottom: 24px; display: flex; justify-content: space-between; align-items: center;
}
.page-header h1 { font-size: 28px; font-weight: 700; color: #1d1d1f; }
.page-header p { color: #6e6e73; margin-top: 4px; }
.page-actions { display: flex; gap: 12px; align-items: center; }

/* ---- 按钮 ---- */
.btn {
    padding: 8px 18px; border: none; border-radius: 8px; cursor: pointer;
    font-size: 14px; font-weight: 500; transition: all 0.2s;
    display: inline-flex; align-items: center; gap: 6px;
    letter-spacing: 0.01em;
}
.btn-primary { background: var(--primary-color); color: white; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,122,255,0.3); }
.btn-secondary { background: #e8e8ed; color: #1d1d1f; }
.btn-secondary:hover { background: #d1d1d6; }
.btn-danger { background: var(--danger-color); color: white; }
.btn-danger:hover { background: #e0352b; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(255,59,48,0.3); }
.btn-success { background: var(--success-color); color: white; }
.btn-success:hover { background: #30b350; }
.btn-info { background: #5AC8FA; color: white; }
.btn-info:hover { background: #47b3e8; }
.btn-sm { padding: 4px 12px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }
.btn-warning { background: var(--warning-color); color: white; }
.btn-warning:hover { background: #e08600; }

/* ---- Badge ---- */
.badge { display: inline-block; padding: 2px 8px; font-size: 11px; font-weight: 600; border-radius: 10px; background: #e5e5ea; color: #6e6e73; vertical-align: middle; margin-left: 4px; }
.badge-primary { background: #007AFF; color: white; }
.badge-success { background: #34C759; color: white; }
.badge-danger { background: #FF3B30; color: white; }

/* ---- 统计卡片 ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin-bottom: 24px; }
.stat-card { background: white; padding: 24px; border-radius: 12px; box-shadow: var(--card-shadow); display: flex; align-items: center; gap: 16px; transition: box-shadow 0.2s; }
.stat-card:hover { box-shadow: var(--card-hover-shadow); }
.stat-icon { width: 56px; height: 56px; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: white; font-size: 22px; }
.stat-info h3 { font-size: 28px; margin-bottom: 4px; font-weight: 700; color: #1d1d1f; }
.stat-info p { color: #6e6e73; font-size: 13px; font-weight: 500; }

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

/* 样品录入页：下半部分左右双栏（字段 | 图片） */
.entry-bottom-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-top: 8px;
    padding-top: 20px;
    border-top: 1px solid #f0f0f5;
}
.entry-fields-col { display: flex; flex-direction: column; }
.entry-image-col { display: flex; flex-direction: column; }
@media (max-width: 900px) {
    .entry-bottom-row { grid-template-columns: 1fr; }
}
.card-header {
    padding: 16px 24px; border-bottom: 1px solid #f0f0f5;
    display: flex; justify-content: space-between; align-items: center;
}
.card-header h3 { font-size: 16px; font-weight: 600; color: #1d1d1f; }
.card-body { padding: 24px; }
.header-actions { display: flex; align-items: center; gap: 8px; }

/* ---- 表单 ---- */
.form-container { max-width: 1200px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 6px; color: #1d1d1f; font-weight: 500; font-size: 13px; }
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%; padding: 9px 12px; border: 1px solid #d1d1d6;
    border-radius: 8px; font-size: 14px; transition: all 0.2s; background: #ffffff;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(0,122,255,0.12); }
.form-group input[readonly] { background: #f5f5f7; color: #6e6e73; }

/* ---- 组合搜索框 (Combo Box) ---- */
.combo-box { position: relative; }
.combo-box input { padding-right: 30px !important; }
.combo-arrow {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    color: #999; cursor: pointer; font-size: 12px; pointer-events: auto; z-index: 2;
}
.combo-dropdown {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: white; border: 1px solid #d1d1d6; border-top: none;
    border-radius: 0 0 8px 8px; max-height: 220px; overflow-y: auto;
    z-index: var(--combo-z); list-style: none; padding: 0; margin: 0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}
.combo-dropdown.open { display: block; }
.combo-item {
    padding: 8px 12px; cursor: pointer; font-size: 14px;
    display: flex; justify-content: space-between; align-items: center;
}
.combo-item:hover, .combo-item.active { background: rgba(0,122,255,0.08); color: var(--primary-color); }
.combo-item.no-match { color: #999; cursor: default; pointer-events: none; }
.combo-item .sub-text { font-size: 12px; color: #999; }

/* ---- 表格 ---- */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #f0f0f5; }
.data-table th { background: #f5f5f7; font-weight: 600; color: #6e6e73; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.data-table tbody tr:hover { background: rgba(0,122,255,0.04); }
.data-table .col-narrow { width: 80px; }
.data-table .col-short { width: 100px; }
.data-table .col-wide { min-width: 140px; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.data-table .col-action { width: 60px; text-align: center !important; }

/* 数据库工具条 */
.db-toolbar { margin-bottom: 12px; }
.db-search {
    width: 100%; padding: 8px 12px 8px 32px; border: 1px solid #e8e8e8; border-radius: 6px;
    font-size: 13px; background: #fafafa url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23999'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.415l-3.85-3.85zm-5.44.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") 10px center no-repeat;
    transition: border-color 0.2s, background 0.2s;
}
.db-search:focus { outline: none; border-color: var(--primary-color); background-color: white; }
.table-container { max-height: 420px; overflow: auto; border: 1px solid #e8e8e8; border-radius: 8px; }
.db-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.db-count { font-size: 12px; color: #999; }

/* 设置页数据库并排 / 响应式网格 */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
    gap: 20px;
}
.settings-grid .card { margin-bottom: 0; }
.settings-grid .card.card-full { grid-column: 1 / -1; }
.settings-grid .table-container { max-height: 360px; overflow: auto; }
.settings-grid .data-table { width: auto; min-width: 100%; }
.settings-grid .data-table th,
.settings-grid .data-table td {
    white-space: nowrap;
    min-width: 160px;
}
.settings-grid .data-table th:first-child,
.settings-grid .data-table td:first-child {
    min-width: 90px;
}
.settings-grid .data-table th:last-child,
.settings-grid .data-table td:last-child {
    min-width: 60px;
}

/* 设置页公司信息：并排3组 */
.company-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}
.company-grid .card { margin-bottom: 0; }

@media (max-width: 768px) {
    .settings-grid { grid-template-columns: 1fr; }
    .company-grid { grid-template-columns: 1fr; }
}

/* ---- 图片上传 ---- */
.image-upload-area {
    border: 2px dashed #d9d9d9; border-radius: 8px; padding: 40px;
    text-align: center; cursor: pointer; transition: border-color 0.3s; position: relative;
}
.image-upload-area:hover { border-color: var(--primary-color); }
.image-upload-area input[type="file"] {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer;
}
.upload-placeholder i { font-size: 48px; color: #d9d9d9; margin-bottom: 12px; }
.upload-placeholder p { color: #666; margin-bottom: 4px; }
.upload-placeholder .hint { font-size: 12px; color: #999; }
.image-preview-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; margin-top: 20px; }
.image-preview-item { position: relative; border: 1px solid #e8e8e8; border-radius: 4px; overflow: hidden; }
.image-preview-item img { width: 100%; height: 150px; object-fit: cover; }
.image-preview-item .remove-btn {
    position: absolute; top: 5px; right: 5px; background: rgba(0,0,0,0.5); color: white;
    border: none; border-radius: 50%; width: 24px; height: 24px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* ---- 测量表格 ---- */
.measurement-section { overflow-x: auto; }
#measurementTable { min-width: 1000px; }
#measurementTable th, #measurementTable td { padding: 6px 8px; font-size: 13px; white-space: nowrap; }
#measurementTable th.measure-col { text-align: center; min-width: 80px; background: rgba(0,122,255,0.08); }
#measurementTable td.measure-col { text-align: center; }
#measurementTable input { width: 100%; padding: 5px 6px; border: 1px solid #d9d9d9; border-radius: 3px; font-size: 13px; text-align: center; }
#measurementTable input.measure-name { text-align: left; min-width: 120px; }
#measurementTable input.measure-value { min-width: 70px; }
.measurement-actions { margin-top: 16px; }

/* ---- 搜索框 ---- */
.search-box { position: relative; display: flex; align-items: center; }
.search-box i { position: absolute; left: 12px; color: #999; }
.search-box input { padding: 9px 12px 9px 36px; border: 1px solid #d1d1d6; border-radius: 8px; width: 300px; font-size: 14px; transition: all 0.2s; }
.search-box input:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(0,122,255,0.12); }

/* ---- 状态标签 ---- */
.status-badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.status-qualified { background: rgba(52,199,89,0.12); color: var(--success-color); }
.status-pending { background: rgba(255,159,10,0.12); color: var(--warning-color); }
.status-rejected { background: rgba(255,59,48,0.12); color: var(--danger-color); }

/* ---- 空状态 ---- */
.empty-state { text-align: center; padding: 60px; color: #999; }

/* ---- 统计结果 ---- */
.statistics-result { margin-top: 20px; padding: 20px; background: #fafafa; border-radius: 8px; }
.statistics-result h4 { margin-bottom: 12px; color: #333; }
.stat-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #e8e8e8; }
.stat-row:last-child { border-bottom: none; }

/* ---- 公司选择器 ---- */
.company-selector { display: flex; align-items: center; }
.company-selector select {
    padding: 6px 12px; border: 1px solid #d9d9d9; border-radius: 4px;
    font-size: 14px; min-width: 280px;
}

/* 报告显隐复选框 */
.report-toggle {
    display: flex; align-items: center; gap: 4px;
    font-size: 13px; color: #555; cursor: pointer; user-select: none;
    white-space: nowrap;
}
.report-toggle input[type="checkbox"] { cursor: pointer; margin: 0; }

/* ---- 横版报告 ---- */
.report-landscape-wrapper {
    background: #e8e8ed; padding: 20px; border-radius: 12px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.report-landscape {
    width: 1122px; min-height: 793px;
    background: white; margin: 0 auto; padding: 30px 40px 60px 40px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    font-size: 13px; display: flex; flex-direction: column; position: relative;
}
.report-landscape .company-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    border-bottom: 2px solid #1d1d1f; padding-bottom: 12px; margin-bottom: 20px;
}
.report-landscape .company-header .company-info { text-align: left; }
.report-landscape .company-header .company-info h2 { font-size: 18px; margin-bottom: 4px; color: #1d1d1f; }
.report-landscape .company-header .company-info p { font-size: 12px; color: #6e6e73; }
.report-landscape .company-header .report-title { text-align: right; }
.report-landscape .company-header .report-title h1 { font-size: 20px; color: #1d1d1f; margin-bottom: 4px; }
.report-landscape .company-header .report-title .lang { font-size: 14px; color: #6e6e73; }

.report-landscape .report-meta {
    display: grid; grid-template-columns: 1fr 1fr 1fr;
    gap: 10px 30px; margin-bottom: 20px; padding: 12px 16px;
    background: #f5f5f7; border-radius: 8px;
}
.report-landscape .report-meta .meta-item { font-size: 13px; }
.report-landscape .report-meta .meta-item strong { color: #1d1d1f; margin-right: 6px; }

.report-landscape .report-section { margin-bottom: 20px; }
.report-landscape .report-section h3 {
    font-size: 15px; font-weight: 600; color: #1d1d1f;
    border-bottom: 1px solid #e5e5ea; padding-bottom: 6px; margin-bottom: 12px;
}
.report-landscape table {
    width: 100%; border-collapse: collapse; font-size: 12px;
}
.report-landscape table th {
    background: #1d1d1f; color: white; padding: 8px 6px; text-align: center;
    font-weight: 500; border: 1px solid #1d1d1f;
}
.report-landscape table td {
    padding: 6px; border: 1px solid #e5e5ea; text-align: center;
}
.report-landscape table td.left { text-align: left; }
.report-landscape table tr.out-of-tolerance { background: #fff1f0; }
.report-landscape table tr.out-of-tolerance td { color: var(--danger-color); font-weight: 500; }

.report-landscape .report-footer {
    margin-top: auto;
    padding-top: 10px; border-top: 1px solid #e5e5ea;
    display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: #999;
    position: absolute; bottom: 16px; left: 40px; right: 40px;
    background: white;
}
.report-landscape .footer-out-of-tolerance { font-size: 10px; color: #b0b0b0; }
.report-landscape .footer-motto {
    text-align: center; flex: 1; font-style: italic; color: #999; font-size: 11px;
    letter-spacing: 0.02em;
}
.report-landscape .footer-signature { text-align: right; color: #b0b0b0; font-size: 10px; }
.out-of-tolerance-note {
    text-align: right; font-size: 10px; color: #b0b0b0; margin-top: 6px;
}

/* 打印样式 */
@media print {
    body { background: white; }
    .sidebar, .top-bar, .page-header, .btn, .report-landscape-wrapper { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .content-page { padding: 0 !important; }
    .report-landscape {
        width: 100%; min-height: auto; box-shadow: none; padding: 20px 30px;
    }
}

/* ---- 图表容器 ---- */
.analytics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(500px, 1fr)); gap: 20px; }
.analytics-grid .card { min-height: 400px; }
.analytics-grid canvas { max-height: 300px; }

/* ---- 响应式 ---- */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .main-content { margin-left: 0; }
    .form-row { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr; }
    .analytics-grid { grid-template-columns: 1fr; }
}

/* ---- 加载动画 ---- */
.loading {
    display: inline-block; width: 20px; height: 20px;
    border: 3px solid #f3f3f3; border-top: 3px solid var(--primary-color);
    border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* ---- 弹窗 ---- */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4); z-index: 2000;
    display: flex; align-items: center; justify-content: center;
}
.modal-content {
    background: white; border-radius: 12px; width: 400px; max-width: 90vw;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid #e8e8e8;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-body .form-group { margin-bottom: 14px; }
.modal-body .form-group label { display: block; margin-bottom: 4px; font-size: 13px; color: #555; }
.modal-body .form-group input,
.modal-body .form-group select {
    width: 100%; padding: 8px 12px; border: 1px solid #d9d9d9; border-radius: 6px;
    font-size: 14px;
}
.modal-body .form-group input:focus,
.modal-body .form-group select:focus {
    outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
}
.modal-footer {
    display: flex; justify-content: flex-end; gap: 8px;
    padding: 12px 20px; border-top: 1px solid #e8e8e8;
}
