@page {
    size: A4 portrait;
    margin: 0;
}

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

body {
    font-family: system-ui, Helvetica, Arial, sans-serif;
    font-size: 12px;
    color: #000;
    line-height: 1.3;
    margin: 0;
    padding: 40px 50px;
    background-color: #f8f9fa;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
    background-color: #fff;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    margin-top: 20px;
    margin-bottom: 20px;
    position: relative;
}

/* Watermark */
.container::before {
    content: "CIRCUITOLOG";
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
    font-size: 90px;
    color: rgba(34, 197, 94, 0.02);
    font-weight: bold;
    z-index: -1;
    pointer-events: none;
}

/* Header Section */
.header-section {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 20px;
    padding-bottom: 20px;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

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

.company-title {
    font-size: 20px;
    font-weight: bold;
    color: #000;
}

h1 {
    text-align: center;
    color: #22c55e;
    margin-bottom: 30px;
    font-size: 2.5rem;
    font-weight: 300;
}

h2 {
    color: #34495e;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #22c55e;
    font-size: 1.4rem;
    font-weight: 400;
}

.section {
    margin-bottom: 40px;
    padding: 20px;
    background-color: #fafafa;
    border-radius: 6px;
    border-left: 4px solid #22c55e;
}

.form-group {
    margin-bottom: 20px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #555;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 4px;
    font-size: 16px;
    transition: border-color 0.3s ease;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #22c55e;
    box-shadow: 0 0 5px rgba(34, 197, 94, 0.3);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

.item-row {
    display: grid;
    grid-template-columns: 55% 15% 15% 15%;
    gap: 15px;
    align-items: end;
    padding: 20px;
    background-color: #fff;
    border-radius: 6px;
    margin-bottom: 15px;
    border: 1px solid #e0e0e0;
}

.item-total {
    font-weight: bold;
    color: #22c55e;
    font-size: 1.1rem;
    padding: 12px;
    background-color: #ecf0f1;
    border-radius: 4px;
    text-align: center;
}

.total-section {
    background-color: #fff;
    padding: 30px;
    border-radius: 6px;
    border: 2px solid #22c55e;
}

.totals {
    margin-top: 20px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
    font-size: 1.1rem;
}

.total-final {
    font-weight: bold;
    font-size: 1.3rem;
    color: #2c3e50;
    border-bottom: none;
    border-top: 2px solid #22c55e;
    margin-top: 10px;
    padding-top: 20px;
}

.btn-primary,
.btn-secondary,
.btn-demo {
    padding: 12px 30px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 5px;
}

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

.btn-primary:hover {
    background-color: #16a34a;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
    margin-right: 10px;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn-demo {
    background-color: #f39c12;
    color: white;
}

.btn-demo:hover {
    background-color: #e67e22;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn-preset {
    background-color: #8e44ad;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    margin: 2px;
}

.btn-preset:hover {
    background-color: #7d3c98;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.buttons {
    text-align: center;
    margin-top: 40px;
    padding: 20px;
}

#addItem {
    margin-top: 20px;
    background-color: #22c55e;
}

#addItem:hover {
    background-color: #16a34a;
}

.btn-remove {
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    cursor: pointer;
    margin-left: 10px;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

/* Preview Styles */
.preview {
    margin-top: 40px;
    padding: 30px;
    background-color: #fff;
    border: 2px solid #22c55e;
    border-radius: 8px;
}

.preview.hidden {
    display: none;
}

#previewContent {
    margin-bottom: 30px;
    padding: 40px 50px;
    background-color: #fff;
    border-radius: 6px;
    font-size: 12px;
    line-height: 1.3;
    font-family: system-ui, Helvetica, Arial, sans-serif;
    color: #000;
    width: 210mm;
    min-height: 297mm;
    position: relative;
    box-sizing: border-box;
}

/* Invoice Styles for Preview and PDF */
.invoice-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
    font-size: 90px;
    color: rgba(34, 197, 94, 0.02);
    font-weight: bold;
    z-index: -1;
    pointer-events: none;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
}

.invoice-to {
    flex: 1;
}

.invoice-to h3 {
    color: #000;
    margin-bottom: 10px;
    font-size: 14px;
}

.invoice-company {
    flex: 1;
    text-align: right;
}

.invoice-logo-section {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 15px;
    margin-bottom: 20px;
}

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

.invoice-company-name {
    font-size: 20px;
    font-weight: bold;
    color: #000;
}

.invoice-number-block {
    background-color: #22c55e;
    color: white;
    padding: 10px;
    text-align: center;
    font-weight: bold;
    width: 150px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
}

.invoice-company-details {
    text-align: right;
    margin-top: 30px;
    font-size: 12px;
}

.invoice-company-details .company-name {
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 5px;
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin: 30px 0;
}

.invoice-table th {
    background-color: #22c55e;
    color: white;
    font-weight: bold;
    padding: 12px 8px;
    text-align: left;
}

.invoice-table th:nth-child(2),
.invoice-table th:nth-child(3),
.invoice-table th:nth-child(4),
.invoice-table td:nth-child(2),
.invoice-table td:nth-child(3),
.invoice-table td:nth-child(4) {
    text-align: right;
}

.invoice-table td {
    padding: 10px 8px;
    border-bottom: 1px solid #ddd;
}

.invoice-table tbody tr:nth-child(even) {
    background-color: #f9f9f9;
}

.invoice-totals {
    text-align: right;
    margin: 20px 0;
    font-size: 12px;
}

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

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

.invoice-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 50px;
    padding-top: 20px;
    border-top: 1px solid #22c55e;
    font-size: 12px;
}

.invoice-footer-left {
    flex: 1;
}

.invoice-footer-right {
    flex: 1;
    text-align: right;
}

.invoice-footer a {
    color: #22c55e;
    text-decoration: none;
}

@media (max-width: 768px) {
    .container {
        margin: 10px;
        padding: 15px;
    }
    
    .form-row {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .item-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .btn-primary,
    .btn-secondary,
    .btn-demo {
        width: 100%;
        margin: 5px 0;
    }
    
    .buttons {
        text-align: stretch;
    }

    .invoice-header {
        flex-direction: column;
        gap: 20px;
    }

    .invoice-company {
        text-align: left;
    }

    .invoice-logo-section {
        justify-content: flex-start;
    }

    .invoice-number-block {
        margin-left: 0;
    }

    .invoice-company-details {
        text-align: left;
    }

    .invoice-footer {
        flex-direction: column;
        gap: 20px;
    }

    .invoice-footer-right {
        text-align: left;
    }
}

@media print {
    body {
        background: white;
        padding: 40px 50px;
        font-size: 12px;
        color: #000;
        line-height: 1.3;
    }
    
    .container {
        box-shadow: none;
        margin: 0;
        padding: 0;
        background: white;
    }
    
    .buttons,
    .btn-primary,
    .btn-secondary,
    #addItem,
    #closePreview,
    .section,
    h1,
    h2,
    form {
        display: none !important;
    }

    .preview {
        display: block !important;
        margin: 0;
        padding: 0;
        border: none;
        background: white;
    }

    #previewContent {
        padding: 0;
        margin: 0;
        background: white;
        min-height: auto;
    }
}

/* Presets Section */
.presets-section {
    margin-bottom: 40px;
    padding: 20px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #8e44ad;
}

.presets-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
}

#companyPresetSelect {
    min-width: 250px;
    flex: 1;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: white;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
    margin-bottom: 20px;
    color: #2c3e50;
    border-bottom: 2px solid #8e44ad;
    padding-bottom: 10px;
}

.preset-company-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin: 20px 0;
}

.preset-company-fields .form-group {
    margin-bottom: 15px;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

/* Logo Preview */
.logo-preview {
    margin-top: 10px;
    padding: 10px;
    border: 2px dashed #ddd;
    border-radius: 8px;
    text-align: center;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f9f9f9;
}

.logo-preview img,
.logo-preview svg {
    max-width: 60px;
    max-height: 60px;
    object-fit: contain;
}

.logo-preview.has-logo {
    border-color: #22c55e;
    background-color: #f0fdf4;
}

.logo-preview.empty::before {
    content: "No logo uploaded";
    color: #666;
    font-style: italic;
}

/* Color Picker Styles */
.color-picker-container {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

#presetBrandColor {
    width: 60px;
    height: 40px;
    border: 2px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
}

.color-presets {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.color-preset {
    width: 30px;
    height: 30px;
    border: 2px solid #ddd;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.color-preset:hover {
    transform: scale(1.1);
    border-color: #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.color-preset.active {
    border-color: #333;
    border-width: 3px;
}

.color-preset.active::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 12px;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

/* Responsive Modal */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        padding: 20px;
        max-height: 90vh;
    }
    
    .preset-company-fields {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .presets-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    #companyPresetSelect {
        min-width: auto;
        width: 100%;
    }
    
    .btn-preset {
        width: 100%;
        margin: 2px 0;
    }
}

/* INVOICE WATERMARK */

#previewContent {
    position: relative;
    background-color: white;
    overflow: hidden;
}

#previewContent::before {
    content: "";
    
    position: absolute;
    top: 50%;
    left: 50%;
    
    width: 500px;
    height: 500px;

    transform: translate(-50%, -50%);

    background-image: url("watermark-logo.png");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;

    opacity: 0.08;

    pointer-events: none;
    z-index: 0;
}

/* чтобы весь контент был поверх watermark */
#previewContent * {
    position: relative;
    z-index: 1;
}