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

html, body {
    height: 100%;
}

body {
    font-family: "Microsoft YaHei", "SimSun", Arial, sans-serif;
    background: #ececec;
    color: #333;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
    align-items: stretch;
}

/* 左侧表单：略窄、紧凑，自身单独滚动 */
.sidebar {
    width: 320px;
    flex: 0 0 320px;
    background: #fff;
    height: 100vh;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 8px rgba(0,0,0,0.08);
    z-index: 2;
}

.sidebar h1 {
    font-size: 16px;
    margin: 0;
    color: #c74444;
    border-bottom: 2px solid #c74444;
    padding: 10px 12px 8px;
    flex: 0 0 auto;
}

.sidebar-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px 12px 12px;
}

.button-group {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 8px 12px 10px;
    border-top: 1px solid #eee;
    background: #fff;
}

.form-section {
    margin-bottom: 10px;
}

.form-section h3 {
    font-size: 12px;
    color: #666;
    margin-bottom: 6px;
    border-left: 3px solid #c74444;
    padding-left: 6px;
}

.form-section.collapsible .section-header {
    cursor: pointer;
    user-select: none;
    background: #f0f0f0;
    padding: 6px 8px;
    border-radius: 3px;
    transition: background 0.2s;
    font-size: 12px;
    margin-bottom: 0;
    border-left: none;
    color: #444;
}

.form-section.collapsible .section-header:hover {
    background: #e8e8e8;
}

.form-section.collapsible .section-content {
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.3s ease;
    padding-top: 6px;
}

.form-section.collapsible.collapsed .section-content {
    max-height: 0;
    padding-top: 0;
}

.form-section.collapsible .toggle-icon {
    display: inline-block;
    transition: transform 0.3s;
}

.form-section.collapsible.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.subhead {
    margin: 8px 0 6px;
    font-size: 11px;
    color: #666;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 8px;
}

.form-grid .form-group.full {
    grid-column: 1 / -1;
}

.contact-item,
.cargo-item {
    background: #f9f9f9;
    padding: 6px 8px;
    margin-bottom: 6px;
    border-radius: 3px;
    border: 1px solid #e0e0e0;
}

.contact-item-header,
.cargo-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.contact-item-header strong,
.cargo-item-header strong {
    font-size: 11px;
    color: #333;
}

.cargo-item-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 6px;
}

.cargo-item-grid .form-group {
    margin-bottom: 0;
}

.cargo-item-grid .form-group.full {
    grid-column: 1 / -1;
}

.cargo-item-grid label,
.form-grid label {
    font-size: 11px;
}

.field-hint {
    font-weight: normal;
    font-size: 10px;
    color: #888;
    margin-left: 2px;
}

.btn-remove {
    background: #d9534f;
    color: white;
    border: none;
    padding: 1px 6px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
}

.btn-remove:hover {
    background: #c9302c;
}

.btn-small {
    padding: 5px 8px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
    margin-top: 6px;
}

.inline-actions {
    margin-top: 6px;
    display: flex;
    gap: 5px;
}

.inline-actions .btn {
    flex: 1;
    min-width: 0;
}

.form-group {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 11px;
    margin-bottom: 2px;
    color: #555;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 4px 7px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 12px;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #c74444;
}

.form-group input[readonly],
.total-input {
    background: #ffffcc;
    cursor: not-allowed;
    font-weight: bold;
}

.btn {
    padding: 8px 10px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: #c74444;
    color: white;
}

.btn-primary:hover {
    background: #a53636;
}

.btn-secondary {
    background: #666;
    color: white;
}

.btn-secondary:hover {
    background: #555;
}

/* 右侧预览：占满剩余宽度，独立滚动，同时展示两联 */
.preview-container {
    flex: 1 1 auto;
    min-width: 0;
    height: 100vh;
    overflow-y: auto;
    padding: 12px 18px 28px;
    background: #e6e6e6;
}

.preview-toolbar {
    position: sticky;
    top: 0;
    z-index: 1;
    background: linear-gradient(#e6e6e6 70%, rgba(230,230,230,0));
    padding-bottom: 10px;
    margin-bottom: 4px;
}

.preview-container h2 {
    font-size: 16px;
    margin-bottom: 2px;
    color: #333;
}

.preview-hint {
    font-size: 12px;
    color: #666;
}

.preview-copies {
    display: flex;
    flex-direction: column;
    gap: 22px;
    align-items: stretch;
}

.preview-copy-wrap {
    width: 100%;
}

.copy-caption {
    font-size: 13px;
    font-weight: bold;
    letter-spacing: 1px;
    margin-bottom: 6px;
    padding: 4px 10px;
    border-radius: 3px;
    display: inline-block;
}

.stub-caption {
    background: #eee;
    color: #333;
    border: 1px solid #ccc;
}

.customer-caption {
    background: #f8d4d4;
    color: #8b1c1c;
    border: 1px solid #e0a0a0;
}

.waybill-scale {
    width: 100%;
    display: flex;
    justify-content: center;
}

/* 运单样式：屏幕可放大，打印仍用 A5 实际尺寸 */
.waybill {
    width: 210mm;
    min-height: 148mm;
    height: auto;
    background: white;
    margin: 0 auto;
    padding: 8mm 12mm 8mm 8mm;
    box-shadow: 0 2px 12px rgba(0,0,0,0.12);
    position: relative;
    font-size: 11px;
}

.waybill-stub {
    background: #fafafa;
}

.waybill-customer {
    background: #fff6f6;
    box-shadow: 0 2px 12px rgba(199, 68, 68, 0.18);
}

.copy-banner {
    text-align: center;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 6px;
    padding: 2px 0;
    margin-bottom: 2px;
    border: 1px solid #000;
}

.waybill-stub .copy-banner {
    background: #efefef;
    color: #333;
}

.waybill-customer .copy-banner {
    background: #f4c7c7;
    color: #8b1c1c;
}

.waybill-customer .waybill-header {
    border-color: #8b1c1c;
}

/* 侧边标签 */
.side-labels {
    position: absolute;
    right: 1mm;
    left: auto;
    top: 32mm;
    display: flex;
    flex-direction: column;
    gap: 2mm;
    z-index: 2;
}

.side-label {
    width: 8mm;
    padding: 3mm 1mm;
    text-align: center;
    font-size: 9px;
    font-weight: bold;
    line-height: 1.5;
    border: 1px solid #000;
}

.side-label.white {
    background: #fff;
}

.side-label.red {
    background: #ffd0d0;
    color: #8b1c1c;
}

.side-label span {
    display: block;
    font-size: 10px;
    margin-top: 2px;
}

/* 表头 */
.waybill-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 2px solid #000;
    padding: 5px 10px;
    margin-bottom: 2px;
}

.logo {
    width: 60px;
    height: 60px;
}

.logo svg {
    width: 100%;
    height: 100%;
}

.company-name {
    flex: 1;
    text-align: center;
    padding: 0 10px;
}

.company-name h1 {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 2px;
}

.agreement-type {
    font-size: 14px;
    font-weight: normal;
}

.company-name-en {
    font-size: 10px;
    color: #666;
}

.waybill-number {
    text-align: right;
    font-size: 10px;
}

.waybill-number div {
    margin-bottom: 3px;
}

/* 表格通用样式 */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2px;
}

table td,
table th {
    border: 1px solid #000;
    padding: 3px 5px;
    text-align: left;
}

table th {
    background: #f5f5f5;
    font-weight: bold;
    text-align: center;
}

table .label {
    background: #f9f9f9;
    font-weight: bold;
    white-space: nowrap;
}

.info-table td {
    padding: 2px 5px;
}

.info-table .label {
    width: 80px;
}

.cargo-table th {
    font-size: 10px;
    padding: 2px 3px;
}

.cargo-table td {
    text-align: center;
    min-height: 30px;
}

.fee-table th {
    font-size: 9px;
    padding: 2px 3px;
}

.fee-table td {
    text-align: center;
    font-size: 10px;
}

.bottom-info td {
    vertical-align: top;
}

.notice-cell {
    padding: 3px 5px !important;
}

.notice-wrap {
    display: flex;
    gap: 6px;
    align-items: flex-start;
}

.important-notice {
    text-align: center;
    color: #c74444;
    font-weight: bold;
    font-size: 10px;
    line-height: 1.45;
    flex: 0 0 auto;
    padding-right: 4px;
    border-right: 1px solid #000;
}

.important-notice div {
    margin: 0;
}

.special-declaration {
    flex: 1;
    font-size: 8px;
    line-height: 1.4;
    color: #333;
}

.signature-line {
    margin-top: 6px;
    border-top: 1px solid #ccc;
    padding-top: 4px;
    font-size: 10px;
}

.staff-info {
    display: flex;
    gap: 50px;
    padding: 5px 10px;
    border: 1px solid #000;
    border-top: none;
    font-size: 10px;
}

.footer-contacts {
    margin-top: 5px;
    padding: 5px;
    border: 1px solid #ccc;
    background: #fafafa;
    font-size: 8px;
    line-height: 1.6;
}

.waybill-customer .footer-contacts {
    background: #fff0f0;
    border-color: #e0b0b0;
}

.contact-row {
    margin-bottom: 2px;
}

.contact-row strong {
    color: #333;
}

/* 打印：只出两页 A5 横向运单，隐藏表单；屏幕缩放不带入打印 */
@media print {
    html, body {
        height: auto;
        overflow: visible;
        background: white;
    }

    .sidebar,
    .preview-toolbar,
    .copy-caption {
        display: none !important;
    }

    .preview-container {
        height: auto;
        overflow: visible;
        margin: 0;
        padding: 0;
        background: white;
    }

    .preview-copies {
        display: block;
        gap: 0;
    }

    .preview-copy-wrap,
    .waybill-scale {
        width: auto;
        display: block;
        zoom: 1 !important;
    }

    .waybill {
        width: 210mm;
        min-height: 148mm;
        height: auto;
        box-shadow: none;
        margin: 0;
        overflow: visible;
        page-break-after: always;
        break-after: page;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .preview-copy-wrap:last-child .waybill {
        page-break-after: auto;
        break-after: auto;
    }

    .cargo-table,
    .cargo-table tr,
    .cargo-table td,
    .cargo-table th {
        page-break-inside: avoid;
    }

    @page {
        size: A5 landscape;
        margin: 0;
    }
}

/* 窄屏才上下堆叠，桌面保持左右工作台 */
@media screen and (max-width: 1024px) {
    html, body {
        height: auto;
        overflow: auto;
    }

    .container {
        flex-direction: column;
        height: auto;
    }

    .sidebar {
        width: 100%;
        flex: none;
        height: auto;
        max-height: none;
        box-shadow: none;
    }

    .sidebar-scroll {
        overflow: visible;
    }

    .preview-container {
        height: auto;
        overflow: visible;
    }
}
