:root {
    --primary: #1a5fb4;
    --primary-dark: #104a8e;
    --success: #26a269;
    --warning: #e5a50a;
    --danger: #e01b24;
    --bg: #f6f8fb;
    --card: #ffffff;
    --text: #1c1c1c;
    --text-muted: #666;
    --border: #d8dee9;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }

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

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

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

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

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

.login-header { text-align: center; margin-bottom: 28px; }
.login-header h1 { font-size: 20px; margin: 0 0 6px; color: var(--primary-dark); }
.login-header p { margin: 0; color: var(--text-muted); font-size: 15px; }

.login-form .form-group { margin-bottom: 18px; }
.login-form label { display: block; margin-bottom: 6px; font-size: 14px; color: var(--text-muted); }
.login-form input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
}

.login-hint { margin-top: 24px; font-size: 12px; color: var(--text-muted); text-align: center; }
.login-hint p { margin: 4px 0; }

/* 顶部导航 */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}
.brand strong { color: var(--primary); font-size: 18px; }
.brand span { color: var(--text-muted); margin-left: 8px; font-size: 14px; }
.user { display: flex; align-items: center; gap: 12px; font-size: 14px; }

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
}
.btn:hover { background: #f0f4f8; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b71c1c; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-light { background: #f0f4f8; }

/* 页面标题 */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 24px 0 20px;
    gap: 16px;
    flex-wrap: wrap;
}
.page-header h2 { margin: 0; font-size: 22px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* 流转单详情页：操作栏置顶，与顶部导航一起冻结 */
.record-detail .page-header {
    position: sticky;
    top: 56px;
    z-index: 90;
    background: var(--bg);
    padding: 12px 20px;
    margin: 0 -20px 20px;
    border-bottom: 1px solid var(--border);
}

/* 汇总行 */
.items-table tfoot .summary-row {
    background: #f0f4f8;
    font-weight: 700;
}
.items-table tfoot .summary-row td {
    border-top: 2px solid var(--border);
}
.items-table tfoot .summary-row td[data-sum-field] {
    text-align: right;
    color: var(--primary-dark);
}
.items-table tfoot .summary-row td.summary-label {
    text-align: right;
    padding-right: 4px;
    color: var(--text);
}
.items-table tfoot .summary-row td.weight-over-limit {
    color: #d32f2f;
    font-weight: bold;
}

/* 提示 */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.alert-success { background: #e8f5e9; color: #1b5e20; border: 1px solid #c8e6c9; }
.alert-error { background: #ffebee; color: #b71c1c; border: 1px solid #ffcdd2; }

/* 筛选栏 */
.filter-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.filter-bar input,
.filter-bar select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    min-width: 180px;
}

/* 表格 */
.table-responsive { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 14px;
}
.data-table th,
.data-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table th { background: #f0f4f8; color: var(--text-muted); font-weight: 600; }
.data-table tr:hover { background: #fafbfc; }
.sort-link {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.sort-link:hover { text-decoration: underline; }
.sort-icon { font-size: 12px; }
.sort-inactive { color: #cbd5e1; }
.sort-active { color: #0f172a; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
}
.badge-draft { background: #e3f2fd; color: #1565c0; }
.badge-in_progress { background: #fff3e0; color: #ef6c00; }
.badge-completed { background: #e8f5e9; color: #2e7d32; }
.badge-danger { background: #ffebee; color: #c62828; }

/* 消息通知 */
.notification-badge {
    display: inline-block;
    background: #c62828;
    color: #fff;
    border-radius: 10px;
    padding: 1px 6px;
    font-size: 11px;
    margin-left: 4px;
    line-height: 1.4;
}
.record-change-badge {
    margin-left: 6px;
    font-size: 11px;
    white-space: nowrap;
}
.notification-list .notification-item {
    transition: background 0.15s;
}
.notification-list .notification-item:hover {
    background: #f8fafc;
}
.notification-list .notification-item.unread {
    background: #fff8e1;
}
.notification-list .notification-item.unread:hover {
    background: #fff3e0;
}
.notification-popup-item:hover {
    background: #f8fafc;
}

/* 进度条 */
.progress-bar {
    width: 120px;
    height: 8px;
    background: #e0e6ed;
    border-radius: 4px;
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}
.progress-bar-lg { width: 240px; height: 10px; }
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), #4cd97a);
    transition: width .3s;
}

/* 表单区块 */
.record-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}
.form-section {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    border-top: 4px solid var(--primary);
}
.form-section.readonly {
    border-top-color: var(--border);
    background: #fafbfc;
}
.form-section.editable {
    border-top-color: var(--success);
}
.section-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.section-status {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #ffebee;
    color: #c62828;
    font-weight: 500;
}
.section-status.done { background: #e8f5e9; color: #2e7d32; }
.section-lock {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #eceff1;
    color: #546e7a;
    margin-left: auto;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
}
.form-group { display: flex; flex-direction: column; }
.form-group label {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 5px;
}
.form-group input,
.form-group textarea,
.form-group select {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: #fff;
}
.form-group input[readonly],
.form-group textarea[readonly] {
    background: #f0f2f5;
    color: var(--text-muted);
}
.form-group textarea { resize: vertical; min-height: 60px; }

.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }

/* 产品明细表格 */
.items-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}
.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 900px;
    table-layout: fixed;
}
.items-table th,
.items-table td {
    border: 1px solid var(--border);
    padding: 6px 8px;
    text-align: left;
    vertical-align: middle;
    overflow-wrap: break-word;
}
.items-table th {
    background: #f0f4f8;
    font-weight: 600;
    white-space: normal;
    word-break: break-word;
    vertical-align: bottom;
    width: auto;
    min-width: 60px;
    max-width: 110px;
}
.items-table td input,
.items-table td textarea {
    width: 100%;
    padding: 5px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
}
.items-table input[readonly],
.items-table textarea[readonly] {
    background: #f3f4f6;
    color: #6b7280;
    cursor: not-allowed;
}

.calculated-cell {
    background: #f0f9ff;
    color: #0369a1;
    font-weight: 500;
    text-align: center;
    padding: 8px;
}

.help-list {
    margin: 0;
    padding-left: 20px;
    line-height: 1.8;
}

.help-list li {
    margin-bottom: 8px;
}
.items-table td textarea {
    resize: vertical;
    min-height: 34px;
}
.items-table .row-num {
    text-align: center;
    background: #f8fafc;
    font-weight: 600;
}
.import-bar {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* 打印样式 */
@media print {
    .no-print, .topbar, .page-actions, .section-lock, .section-status,
    .form-section.editable, .form-section.readonly { display: none !important; }

    body { background: #fff; }
    .container { max-width: 100%; padding: 0; }
    .form-section { box-shadow: none; border: 1px solid #333; page-break-inside: avoid; }
    .record-grid { display: block; }
}

.print-body { background: #fff; }
.print-toolbar {
    padding: 12px 20px;
    background: #f0f4f8;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 10px;
}
.print-sheet {
    max-width: 1000px;
    margin: 30px auto;
    padding: 30px;
    background: #fff;
}
.print-title { text-align: center; margin-bottom: 24px; }
.print-title h1 { font-size: 22px; margin: 0 0 6px; }
.print-title h2 { font-size: 18px; margin: 0; color: var(--text-muted); font-weight: normal; }
.print-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 16px 32px;
    font-size: 13px;
    margin-bottom: 20px;
    color: var(--text-muted);
}
.print-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.print-table th,
.print-table td {
    border: 1px solid #333;
    padding: 8px 10px;
    text-align: left;
}
.print-table th {
    background: #f0f4f8;
    white-space: normal;
    word-break: break-word;
}
.print-dept {
    background: #f8fafc;
    font-weight: 600;
    text-align: center;
    vertical-align: middle;
}
.print-footer {
    margin-top: 30px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}
.print-hint {
    padding: 10px 20px;
    background: #fffbeb;
    border-bottom: 1px solid #fcd34d;
    color: #92400e;
    font-size: 13px;
}

/* 打印分页：A4 纵向，每大节另起一页，页脚右侧页码 */
@media print {
    @page {
        size: A4 portrait;
        margin: 15mm 15mm 20mm 15mm;
        @bottom-right {
            content: counter(page) "/" counter(pages);
            font-size: 12px;
        }
    }

    .print-page {
        page-break-before: always;
        min-height: 257mm; /* A4 可打印区域高度近似值 */
    }
    .print-page:first-child {
        page-break-before: auto;
    }

    /* 避免表格在分页时被截断 */
    .print-table {
        page-break-inside: auto;
    }
    .print-table tr {
        page-break-inside: avoid;
    }
    .print-table thead {
        display: table-header-group;
    }
}

/* 打印时隐藏通用页脚，避免与 @page 页脚重复 */
@media print {
    .print-sheet > .print-footer {
        display: none;
    }
}

/* 看板图表样式 */
.chart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; margin: 20px 0; }
@media (max-width: 900px) { .chart-grid { grid-template-columns: 1fr; } }
.chart-card { background: #fff; border: 1px solid #e0e0e0; border-radius: 8px; padding: 20px; min-height: 360px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.chart-card h3 { margin: 0 0 12px 0; font-size: 16px; color: #333; }
.chart-card canvas { max-height: 300px; }
.chart-empty { text-align: center; color: #999; padding: 80px 0; font-size: 14px; }
.chart-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
