* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #f5f5f5;
    margin: 0;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    background: #fff;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

h1 {
    text-align: center;
    color: #2c3e50;
    margin-bottom: 30px;
}

fieldset {
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 20px;
    margin-bottom: 20px;
    min-width: 0;
}

legend {
    font-weight: 600;
    color: #2c3e50;
    padding: 0 10px;
}

.form-row {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
}

.form-group {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    flex: 100%;
}

label {
    font-size: 14px;
    color: #666;
    margin-bottom: 5px;
}

input, select {
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.2s;
}

input:focus, select:focus {
    outline: none;
    border-color: #3498db;
}

input::placeholder {
    color: #aaa;
}

/* Убираем стрелки только у поля цены */
.item-price::-webkit-outer-spin-button,
.item-price::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.item-price {
    -moz-appearance: textfield;
}

/* Подсветка ошибок */
input.error, select.error {
    border-color: #e74c3c;
    background-color: #fdf2f2;
    animation: shake 0.3s ease-in-out;
}

input.error:focus {
    border-color: #c0392b;
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.2);
}

.error-message {
    color: #e74c3c;
    font-size: 12px;
    margin-top: 4px;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Таблица услуг */
#itemsContainer {
    margin-bottom: 15px;
    overflow-x: auto;
}

.item-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 10px;
    min-width: 0;
}

.item-row input {
    min-width: 0;
}

.item-name {
    flex: 1 1 200px;
    min-width: 120px;
}

.item-unit {
    flex: 0 0 60px;
    text-align: center;
}

.item-qty {
    flex: 0 0 90px;
    text-align: center;
}

.item-price {
    flex: 0 0 90px;
    text-align: right;
}

.item-sum {
    flex: 0 0 90px;
    text-align: right;
    font-weight: 600;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 4px;
    white-space: nowrap;
}

.btn-remove {
    flex: 0 0 32px;
    background: #e74c3c;
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

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

/* Кнопки */
.btn-primary {
    background: #3498db;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-secondary {
    background: #ecf0f1;
    color: #333;
    border: 1px solid #bdc3c7;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

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

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.main-actions {
    justify-content: center;
    margin-top: 30px;
}

/* Итого */
.totals {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 6px;
    margin-top: 20px;
}

.total-row {
    display: flex;
    justify-content: flex-end;
    gap: 20px;
    margin-bottom: 8px;
    font-size: 16px;
}

.total-final {
    font-size: 18px;
    font-weight: 700;
    color: #2c3e50;
    border-top: 1px solid #ddd;
    padding-top: 10px;
    margin-top: 10px;
}

/* Модальное окно */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    overflow: auto;
}

.modal-content {
    background: white;
    max-width: 850px;
    margin: 30px auto;
    padding: 20px;
    border-radius: 8px;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    cursor: pointer;
    color: #666;
}

.modal-close:hover {
    color: #333;
}

.modal-actions {
    text-align: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #ddd;
}

/* Стили для печатной версии счёта */
.invoice {
    font-family: 'Times New Roman', Times, serif;
    font-size: 12px;
    color: #000;
    padding: 20px;
    background: white;
}

.invoice-header {
    border: 2px solid #000;
    margin-bottom: 20px;
}

.invoice-header table {
    width: 100%;
    border-collapse: collapse;
}

.invoice-header td {
    padding: 5px 8px;
    border: 1px solid #000;
    vertical-align: top;
}

.invoice-header .label {
    font-size: 10px;
    color: #666;
}

.invoice-title {
    text-align: center;
    font-size: 16px;
    font-weight: bold;
    margin: 20px 0;
}

.invoice-parties {
    margin-bottom: 20px;
}

.invoice-parties p {
    margin: 5px 0;
}

.invoice-parties .label {
    font-weight: bold;
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.invoice-table th,
.invoice-table td {
    border: 1px solid #000;
    padding: 6px 8px;
    text-align: left;
}

.invoice-table th {
    background: #f0f0f0;
    font-weight: bold;
    text-align: center;
}

.invoice-table td.number {
    text-align: center;
}

.invoice-table td.amount {
    text-align: right;
}

.invoice-totals {
    text-align: right;
    margin-bottom: 20px;
}

.invoice-totals p {
    margin: 5px 0;
}

.invoice-totals .final {
    font-weight: bold;
    font-size: 14px;
}

.invoice-words {
    margin-bottom: 30px;
    font-style: italic;
}

.invoice-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 40px;
}

/* Скрытый шаблон для PDF */
.invoice-template-hidden {
    display: none;
}

#invoiceTemplate {
    background: white;
}

#invoiceTemplate .invoice {
    width: 190mm;
    padding: 10mm;
}

.invoice-signature {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.invoice-signature .line {
    width: 150px;
    border-bottom: 1px solid #000;
}

/* Адаптив */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    .form-row {
        flex-direction: column;
        gap: 10px;
    }

    .item-row {
        flex-wrap: wrap;
    }

    .item-name {
        flex: 1 1 100%;
        min-width: 100%;
    }

    .item-unit,
    .item-qty,
    .item-price,
    .item-sum {
        flex: 1 1 auto;
        min-width: 60px;
    }
}
