/* БАЗОВЫЕ СТИЛИ */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Montserrat', sans-serif; }
body { background-color: #e2e8f0; color: #333; padding: 20px; display: flex; justify-content: center; line-height: 1.5; font-size: 14px; }
.a4-page { background-color: #fff; width: 100%; max-width: 900px; min-height: 1270px; border-radius: 4px; padding: 40px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); display: flex; flex-direction: column; }

/* ШАПКА */
.header { margin-bottom: 5px; }
.header-top-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 5px; }
.header-top-row h1 { font-size: 22px; color: #2c3e50; font-weight: 700; white-space: nowrap; line-height: 1.2; }
.subtitle { color: #7f8c8d; font-size: 14px; margin-top: 0; margin-bottom: 5px; }

/* РАСТЯНУТОЕ ПОЛЕ ПРИМЕЧАНИЯ */
.note-container { flex: 1; max-width: 350px; }
.note-container input { width: 100%; padding: 12px 15px; border: 1px solid #dce1e5; border-radius: 8px; font-size: 14px; color: #2c3e50; outline: none; transition: border-color 0.3s; background-color: #f8fafc; }
.note-container input:focus { border-color: #3a86ff; background-color: #fff; box-shadow: 0 0 0 3px rgba(58, 134, 255, 0.1); }

/* 2 КОЛОНКИ */
.main-content { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; align-items: start; margin-top: 0; }
.input-column, .result-column { width: 100%; }

/* СТИЛИ ФОРМЫ */
.card { margin-bottom: 20px; padding-bottom: 10px; border-bottom: 1px dashed #eef2f5; }
.card:last-of-type { border-bottom: none; margin-bottom: 10px; }

/* Убираем стрелки у числовых полей */
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

/* Два инпута в ряд (Город и Толщина) */
.row-inputs { display: flex; gap: 15px; }
.row-inputs .select-container { flex: 1; width: 50%; }

/* Групповые поля */
.inline-input-group { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 15px; }
.inline-input-group label { margin-bottom: 0; font-weight: 600; color: #34495e; font-size: 14px; flex: 1; }
.inline-input-group input[type="number"] { width: 110px; padding: 8px 10px; border: 1px solid #dce1e5; border-radius: 8px; font-size: 16px; color: #3a86ff; font-weight: 600; text-align: center; outline: none; transition: border-color 0.3s; flex-shrink: 0; }
.inline-input-group input[type="number"]:focus { border-color: #3a86ff; box-shadow: 0 0 0 3px rgba(58, 134, 255, 0.1); }
.inline-input-group select { width: 130px; padding: 8px 10px; border: 1px solid #dce1e5; border-radius: 8px; font-size: 14px; color: #3a86ff; font-weight: 600; text-align: center; outline: none; transition: border-color 0.3s; background-color: #fff; cursor: pointer; flex-shrink: 0; }
.inline-input-group select:focus { border-color: #3a86ff; box-shadow: 0 0 0 3px rgba(58, 134, 255, 0.1); }

/* Полноширинные селекты */
.select-container label { display: block; margin-bottom: 6px; font-weight: 600; color: #34495e; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.select-container select { width: 100%; padding: 10px; border: 1px solid #dce1e5; border-radius: 8px; font-size: 14px; color: #2c3e50; outline: none; transition: border-color 0.3s; background-color: #fff; cursor: pointer; }
.select-container select:focus { border-color: #3a86ff; box-shadow: 0 0 0 3px rgba(58, 134, 255, 0.1); }

/* СЛАЙДЕРЫ */
.slider-wrapper { position: relative; margin-bottom: 5px; }
.slider { -webkit-appearance: none; width: 100%; height: 6px; background: #e0e0e0; border-radius: 5px; outline: none; margin-top: 10px; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: #3a86ff; cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }

/* ОБЩАЯ ШКАЛА */
.slider-values { display: flex; justify-content: space-between; margin-top: 8px; padding: 0 11px; }
.slider-values span { font-size: 12px; color: #95a5a6; text-align: center; width: 30px; margin: 0 -15px; }

/* ПРЕДУПРЕЖДЕНИЯ */
.warning-text { color: #e74c3c; font-size: 13px; margin-top: -5px; margin-bottom: 5px; display: none; font-weight: 600; }
.warning-text.visible { display: block; }

/* РАДИОКНОПКИ */
.radio-container { margin-bottom: 12px; }
.radio-container p { font-weight: 600; color: #34495e; margin-bottom: 8px; font-size: 14px; }
.radio-container input[type="radio"] { display: none; }
.radio-container label { display: inline-block; position: relative; padding-left: 28px; margin-right: 20px; cursor: pointer; font-weight: 500; color: #555; }
.radio-container label::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; border: 2px solid #bdc3c7; border-radius: 50%; transition: 0.2s; }
.radio-container input[type="radio"]:checked + label::before { border-color: #3a86ff; background: #3a86ff; box-shadow: inset 0 0 0 3px #fff; }

/* Стили для заблокированных радиокнопок */
.radio-container input[type="radio"]:disabled + label { color: #a0aec0; cursor: not-allowed; opacity: 0.6; }
.radio-container input[type="radio"]:disabled + label::before { border-color: #e2e8f0; background: #edf2f7; }
.radio-container input[type="radio"]:disabled:checked + label::before { background: #cbd5e0; }

/* КНОПКИ */
.button { display: block; width: 100%; padding: 14px; background-color: #3a86ff; color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; transition: background 0.3s; margin-top: 15px; }
.button:hover { background-color: #2b6cb0; }
.btn-add { background-color: #38a169; margin-top: 10px; }
.btn-add:hover { background-color: #2f855a; }

/* ЗАГЛУШКА СПРАВА */
.placeholder-text { text-align: center; padding: 60px 20px; color: #a0aec0; border: 2px dashed #e2e8f0; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 400px;}
.hidden { display: none !important; }

/* ИНФО О ГОРОДЕ */
.city-info { margin-top: 15px; padding: 10px 12px; background-color: #f0f7ff; border-left: 4px solid #3a86ff; border-radius: 4px; font-size: 13px; color: #4a5568; line-height: 1.5; display: none; }
.city-info.visible { display: block; }
.city-info strong { color: #2c3e50; font-weight: 600; }

/* КОРЗИНА */
#cart-section { margin-top: 30px; border-top: 2px dashed #e2e8f0; padding-top: 15px; }
.cart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.cart-title { font-size: 18px; color: #2d3748; font-weight: 700; }
.btn-clear { background: #e53e3e; color: white; border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 500; }
.btn-clear:hover { background: #c53030; }

/* ОБЩИЕ СТИЛИ КАРТОЧКИ */
.order-card { background: #fff; border: 2px solid #e2e8f0; border-radius: 8px; padding: 15px; margin-bottom: 15px; page-break-inside: avoid; position: relative; }
.order-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; border-bottom: 2px solid #f7fafc; padding-bottom: 8px; }
.order-title-box { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.order-header h3 { font-size: 16px; color: #2d3748; margin: 0; font-weight: 600; }

/* Стиль для города в карточке */
.city-display { font-size: 13px; color: #718096; font-weight: 500; margin-left: 5px; }

.page-indicator { font-size: 12px; color: #718096; background: #edf2f7; padding: 3px 8px; border-radius: 20px; font-weight: 600; }
.note-display { font-size: 13px; color: #e53e3e; font-weight: 600; margin-left: 8px; }
.order-actions { display: flex; gap: 12px; }
.btn-action { background: none; border: none; cursor: pointer; font-size: 13px; font-weight: 600; text-decoration: underline; }
.btn-edit { color: #3182ce; }
.btn-delete { color: #e53e3e; }

/* ТЕКСТ В КАРТОЧКЕ */
.order-info { font-size: 14px; color: #4a5568; line-height: 1.5; }
.order-info ul { list-style: none; padding: 0; margin-bottom: 10px; background: #f8fafc; padding: 10px; border-radius: 6px; }
.order-info li::before { content: "•"; color: #a0aec0; margin-right: 6px; }
.order-info p { margin-bottom: 5px; }
.order-info strong { color: #1a202c; font-weight: 600; }

/* ПОДВАЛ КАРТОЧКИ */
.order-footer { border-top: 2px dashed #e2e8f0; padding-top: 10px; margin-top: 10px; text-align: left; }
.order-footer .total-line { display: flex; justify-content: space-between; margin-bottom: 0; font-size: 15px; color: #2d3748; font-weight: 600; }
.order-footer .total-line span { color: #3182ce; }

/* --- СВОДНАЯ ТАБЛИЦА --- */
.summary-table { width: 100%; border-collapse: collapse; margin-top: 10px; margin-bottom: 15px; page-break-inside: avoid; border: 1px solid #cbd5e0; table-layout: fixed; }
.summary-table th { background: #f8fafc; padding: 8px; font-size: 13px; color: #4a5568; font-weight: 600; border: 1px solid #cbd5e0; }
.summary-table td { padding: 8px; font-size: 14px; vertical-align: middle; border: 1px solid #cbd5e0; }

/* Выравнивание таблицы */
.summary-table th.col-center, .summary-table td.col-center { text-align: center; }
.summary-table th.col-right, .summary-table td.col-right { text-align: right; }

/* Ширины колонок: Товары шире, Цена и Стоимость уже */
.summary-table th.col-price, 
.summary-table th.col-cost { width: 16%; }

.summary-table th.col-num { width: 40px; }
.summary-table th.col-qty { width: 60px; }
.summary-table th.col-unit { width: 60px; }

/* ГРАНД ТОТАЛ */
.grand-total-box { border: 3px solid #3182ce; padding: 15px; border-radius: 8px; text-align: center; background: #f0f7ff; margin-bottom: 20px; }
.grand-total-box h2 { font-size: 18px; margin-bottom: 5px; color: #2d3748; font-weight: 600; }
.grand-total-box h2:last-child { margin-bottom: 0; }
.grand-total-box h2 span { font-size: 22px; color: #3182ce; font-weight: 700; }

/* КНОПКИ ЭКСПОРТА */
.export-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.btn-export { display: flex; align-items: center; justify-content: center; padding: 14px; border: none; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; transition: background 0.3s; color: white; }
.btn-print { flex: 2; min-width: 250px; background-color: #3182ce; }
.btn-print:hover { background-color: #2b6cb0; }
.btn-word { flex: 1; min-width: 130px; background-color: #2b579a; font-size: 14px; }
.btn-word:hover { background-color: #1e3f70; }
.btn-excel { flex: 1; min-width: 130px; background-color: #217346; font-size: 14px; }
.btn-excel:hover { background-color: #164f2f; }

/* --- ПРЕДПРОСМОТР И КОРЗИНА --- */
#preview-container .order-body-grid { display: block; }
#preview-container .order-image-container { 
    width: 100%; 
    max-width: 100%; 
    margin: 15px auto; 
    aspect-ratio: 1 / 1; 
    background: #f8fafc; 
    border-radius: 6px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    overflow: hidden; 
    border: 1px solid #edf2f7; 
}

.cart-item .order-body-grid { display: grid; grid-template-columns: 1fr 180px; gap: 15px; align-items: start; }
.cart-item .order-image-container { width: 100%; aspect-ratio: 1 / 1; background: #f8fafc; border-radius: 6px; display: flex; align-items: center; justify-content: center; overflow: hidden; border: 1px solid #edf2f7; }
.order-image-container img { width: 100%; height: 100%; object-fit: contain; }
.no-image-text { padding: 10px; text-align: center; font-size: 13px; color: #718096; font-weight: 600; line-height: 1.4; }

/* АДАПТИВ */
@media (max-width: 768px) {
    .a4-page { padding: 20px; min-height: auto; }
    .main-content { grid-template-columns: 1fr; gap: 20px; }
    .header-top-row { flex-direction: column; align-items: flex-start; gap: 10px; }
    .header-top-row h1 { white-space: normal; font-size: 18px; }
    .note-container { width: 100%; max-width: 100%; }
    .order-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .cart-item .order-body-grid { grid-template-columns: 1fr; }
    .inline-input-group { flex-direction: column; align-items: flex-start; gap: 5px; }
    .inline-input-group input[type="number"], .inline-input-group select { width: 100%; max-width: 100%; }
    .summary-table th.col-center, .summary-table td.col-center { text-align: left; }
    .summary-table th.col-right, .summary-table td.col-right { text-align: left; }
    .row-inputs { flex-direction: column; }
    .export-actions { flex-direction: column; }
    .btn-export { width: 100%; }
}

/* =========================================
   ПЕЧАТЬ НА ЛИСТ А4 (КНИЖНАЯ)
   ========================================= */
@media print {
    @page { size: A4 portrait; margin: 10mm; }
    body { background: #fff; padding: 0; display: block; }
    .no-print, button, .input-column, .placeholder-text, .slider-wrapper, .cart-header, .note-container, .export-actions { display: none !important; }
    .a4-page { box-shadow: none; max-width: 100%; width: 100%; min-height: auto; padding: 0; border-radius: 0; }
    .main-content { display: block; }
    #preview-container { display: block; }
    body.has-cart #preview-container { display: none; }
    #cart-section { border-top: none; padding-top: 0; margin-top: 0; }
    .cart-title { display: none; }
    .order-card { border: 1px solid #000; padding: 10px; margin-bottom: 10px; page-break-inside: avoid; }
    .order-header { margin-bottom: 8px; padding-bottom: 4px; border-bottom: 1px solid #000; }
    .order-header h3 { font-size: 13pt; }
    .page-indicator { font-size: 9pt; border: 1px solid #000; background: none; padding: 2px 6px; }
    .city-display { font-size: 10pt; color: #333; }
    .order-body-grid, .cart-item .order-body-grid { display: grid; grid-template-columns: 1fr 140px; gap: 10px; }
    .order-image-container, #preview-container .order-image-container { border: 1px solid #000; max-width: 100%; margin: 0; aspect-ratio: 1 / 1; }
    .order-info { font-size: 10pt; line-height: 1.3; }
    .order-info ul { padding: 5px 8px; margin-bottom: 8px; border: 1px solid #ccc; background: none; }
    .order-info p { margin-bottom: 4px; }
    .order-footer { border-top: 1px dashed #000; padding-top: 8px; margin-top: 8px; }
    .order-footer .total-line { font-size: 11pt; }
    .summary-table { border: 1px solid #000 !important; margin-top: 10px; page-break-inside: avoid; table-layout: fixed !important; }
    .summary-table th { border: 1px solid #000 !important; background: #eee; font-size: 9pt; padding: 4px; }
    .summary-table td { border: 1px solid #000 !important; font-size: 9pt; padding: 4px; }
    .summary-table th.col-center, .summary-table td.col-center { text-align: center !important; }
    .summary-table th.col-right, .summary-table td.col-right { text-align: right !important; }
    .grand-total-box { border: 2px solid #000; padding: 10px; margin-top: 10px; margin-bottom: 15px; background: none; page-break-inside: avoid; }
    .grand-total-box h2 { font-size: 12pt; margin-bottom: 4px; }
    .grand-total-box h2 span { font-size: 16pt; }
}