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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f0f2f5;
    color: #333;
    line-height: 1.6;
    min-height: 100vh;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========== Header ========== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 32px;
    background: white;
    border-bottom: 1px solid #e0e0e0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.tabs {
    display: flex;
    background: #f0f2f5;
    border-radius: 8px;
    padding: 4px;
}

.tab {
    padding: 8px 20px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    color: #666;
    transition: all 0.2s;
}

.tab:hover {
    color: #333;
}

.tab.active {
    background: white;
    color: #333;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.btn-export {
    padding: 10px 24px;
    background: #333;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

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

/* ========== Main Content Layout ========== */
.main-content {
    flex: 1;
    display: flex;
    gap: 32px;
    padding: 32px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* ========== Paper (Invoice Sheet) ========== */
.paper {
    flex: 1;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    min-height: 1273px; /* A4 пропорция: 900px × 1.414 */
    max-width: 900px;
    overflow: hidden; /* Обрезаем контент по скругленным углам */
}

.paper-content {
    display: none;
    padding: 0;
}

.paper-content.active {
    display: block;
}

/* Edit mode имеет свой padding */
.edit-content {
    padding: 48px;
}

/* Убираем возможные переопределения для preview */
.preview-content {
    border-radius: 0; /* Контент не должен иметь своих углов */
}

/* ========== Edit Mode Styles ========== */
.invoice-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 40px;
    position: relative;
}

.invoice-title-row {
    grid-template-columns: 1fr !important;
}

.invoice-title-input {
    font-size: 28px;
    font-weight: 700;
    text-align: right;
    border: 1px solid #e0e0e0 !important;
    border-radius: 8px;
    padding: 12px 14px !important;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.invoice-title:hover {
    border-color: #e0e0e0;
}

.invoice-title:focus {
    outline: none;
    border-color: #333;
}

.invoice-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 280px;
}

.invoice-details .form-group {
    display: grid;
    grid-template-columns: 80px 1fr;
    align-items: center;
    gap: 16px;
    margin-bottom: 0;
}

.invoice-details .form-group label,
.invoice-details .form-group .editable-label {
    font-size: 14px;
    font-weight: 500;
    color: #888;
    text-align: left;
    margin-bottom: 0;
}

.editable-label {
    cursor: text;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background 0.2s, color 0.2s;
    outline: none;
    display: inline-block;
    min-width: 60px;
}

.editable-label:hover {
    background: #f5f5f5;
    color: #333;
}

.editable-label:focus {
    background: #e8f4fd;
    color: #333;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

.invoice-details .form-group input,
.invoice-details .form-group select {
    width: 100%;
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: white;
}

.invoice-details .form-group input:focus,
.invoice-details .form-group select:focus {
    outline: none;
    border-color: #333;
}

.invoice-details .form-group input[readonly] {
    background: white;
    color: #333;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 48px;
    margin-bottom: 40px;
}

.parties-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 48px;
    margin-bottom: 40px;
}

.party-section h3 {
    font-size: 12px;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.party-section textarea {
    width: 100%;
    padding: 16px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.6;
    resize: none;
    background: white;
}

.party-section textarea:focus {
    outline: none;
    border-color: #333;
}

.party-section textarea::placeholder {
    color: #bbb;
}

.form-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    margin-bottom: 4px;
    color: #666;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: white;
}

.form-group input:hover,
.form-group select:hover,
.form-group textarea:hover {
    border-color: #ccc;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #333;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}

/* Items Table */
.items-section {
    margin-bottom: 32px;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 12px;
}

.items-table th {
    text-align: left;
    padding: 12px 8px;
    font-size: 12px;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #e0e0e0;
    white-space: nowrap;
}

/* Column widths */
.items-table th:nth-child(1),
.items-table td:nth-child(1) { 
    width: 55%;
    min-width: 180px; /* немного ужимаем Description, чтобы дать место числам */
}

.items-table th:nth-child(2),
.items-table td:nth-child(2) { 
    width: 120px; /* шире Rate */
    min-width: 120px;
}

.items-table th:nth-child(3),
.items-table td:nth-child(3) { 
    width: 90px; /* шире Qty */
    min-width: 90px;
}

.items-table th:nth-child(4),
.items-table td:nth-child(4) { 
    width: 140px; /* больше базовая ширина Amount */
    min-width: 140px;
    white-space: nowrap;
}

.items-table .tax-column {
    width: 50px;
    min-width: 50px;
    text-align: center;
}

.items-table th:last-child,
.items-table td:last-child { 
    width: 40px;
    min-width: 40px;
}

.items-table td {
    padding: 12px 8px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: top;
}

/* Убираем стрелки у number-инпутов в таблице (Rate/Qty) */
.items-table input[type="number"] {
    -moz-appearance: textfield;
}
.items-table input[type="number"]::-webkit-inner-spin-button,
.items-table input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.item-row input[type="text"],
.item-row input[type="number"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.item-row input:focus {
    outline: none;
    border-color: #333;
}

.item-description {
    margin-bottom: 6px;
}

.item-details {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    color: #666;
}

.item-details:focus {
    outline: none;
    border-color: #333;
}

.item-amount {
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
    color: #333;
}

.item-taxable {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #4a6cf7;
}

.btn-remove {
    background: none;
    color: #ccc;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: all 0.2s;
}

.btn-remove:hover {
    background: #fee;
    color: #e53935;
}

.btn-add {
    padding: 10px 20px;
    background: #f0f2f5;
    color: #333;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-add:hover {
    background: #e4e6e9;
}

/* Totals */
.totals-section {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 32px;
}

.totals {
    width: 320px;
}

.total-row input {
    width: 100px;
    padding: 6px 10px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    text-align: right;
}

.total-row input:focus {
    outline: none;
    border-color: #333;
}

.total-final {
    border-bottom: none;
    border-top: 2px solid #333;
    margin-top: 8px;
    padding-top: 16px;
    font-size: 18px;
    font-weight: 600;
}

/* Notes */
.notes-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.notes-section textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.2s;
}

.notes-section textarea:focus {
    outline: none;
    border-color: #333;
}

/* ========== Preview Mode (Invoice Style) ========== */
.preview-content {
    border-radius: 0;
}

#pdfContent {
    padding: 48px;
}

/* Header */
.preview-header {
    display: flex;
    justify-content: space-between;
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid #e0e0e0;
}

.preview-from {
    flex: 1;
}

.preview-company-name {
    font-size: 20px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 12px;
    line-height: 1.2;
}

.preview-text {
    font-size: 14px;
    color: #555;
    line-height: 1.8;
    margin-bottom: 2px;
    min-height: 21px;
}

.preview-text:empty::before {
    content: '';
}

.preview-from .preview-text:first-of-type {
    color: #666;
    margin-top: 4px;
}

.preview-invoice-meta {
    text-align: right;
    min-width: 280px;
}

.preview-invoice-label {
    font-size: 13px;
    font-weight: 600;
    color: #999;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.preview-invoice-number {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 16px;
}

.preview-meta-row {
    display: flex;
    justify-content: flex-end;
    align-items: baseline;
    gap: 16px;
    margin-bottom: 8px;
}

.preview-meta-label {
    font-size: 11px;
    font-weight: 600;
    color: #999;
    letter-spacing: 0.5px;
}

.preview-meta-value {
    font-size: 14px;
    color: #333;
}

.preview-balance-due {
    margin-top: 24px;
    padding-top: 18px;
    border-top: 2px solid #e8e8e8;
    display: none; /* По умолчанию скрыт, показывается только когда total > 0 */
}

.preview-balance-label {
    font-size: 11px;
    font-weight: 700;
    color: #999;
    letter-spacing: 0.8px;
    margin-bottom: 6px;
}

.preview-balance-amount {
    font-size: 20px;
    font-weight: 700;
    color: #1a1a1a;
    letter-spacing: -0.3px;
}

/* Bill To */
.preview-bill-to {
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid #e0e0e0;
}

.preview-section-title {
    font-size: 11px;
    font-weight: 700;
    color: #999;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.preview-from-content,
.preview-bill-content {
    font-size: 14px;
    line-height: 1.6;
    color: #666;
}

.preview-from-content div:first-child,
.preview-bill-content div:first-child {
    font-weight: 500;
    color: #333;
}

/* Items Table - идентично Edit режиму */
.preview-items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    margin-top: 0;
}

.preview-items-table thead {
    border-bottom: 1px solid #e0e0e0;
}

.preview-items-table th {
    text-align: left;
    padding: 12px 8px;
    font-size: 12px;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

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

.preview-items-table tbody tr {
    border-bottom: 1px solid #f0f0f0;
}

.preview-items-table tbody tr:last-child {
    border-bottom: 1px solid #f0f0f0;
}

.preview-items-table td {
    padding: 12px 8px;
    font-size: 14px;
    color: #333;
    vertical-align: top;
}

.preview-items-table td:nth-child(2),
.preview-items-table td:nth-child(3),
.preview-items-table td:nth-child(4) {
    text-align: right;
    white-space: nowrap;
}

/* Preview column widths — соответствуют Edit */
.preview-items-table th:nth-child(1),
.preview-items-table td:nth-child(1) {
    width: 55%;
    min-width: 180px;
}
.preview-items-table th:nth-child(2),
.preview-items-table td:nth-child(2) {
    width: 120px;
    min-width: 120px;
}
.preview-items-table th:nth-child(3),
.preview-items-table td:nth-child(3) {
    width: 90px;
    min-width: 90px;
}
.preview-items-table th:nth-child(4),
.preview-items-table td:nth-child(4) {
    width: 140px;
    min-width: 140px;
}

.preview-items-table .item-desc-details {
    font-size: 13px;
    color: #666;
    display: block;
    margin-top: 4px;
}

/* Totals minimal */
.totals {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 0;
    font-size: 14px;
    color: #333;
    font-weight: 400;
    border: none;
}

.total-row span:first-child {
    font-weight: 700;
}

.total-row span:last-child {
    font-weight: 400;
}

.total-main {
    font-size: 14px;
    color: #222;
}

.balance-due-row {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-size: 14px;
    color: #222;
}

.balance-due-row span:first-child {
    display: block;
    text-align: right;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: #222;
}

.balance-due-row span:last-child {
    display: block;
    text-align: right;
    font-size: 18px;
    font-weight: 700;
    color: #222;
}

.totals-divider {
    border-top: 1px solid #cfcfcf;
    margin: 5px 0;
}

/* Notes */
.preview-notes-section {
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid #e0e0e0;
}

.preview-notes-section #previewNotes {
    font-size: 14px;
    line-height: 1.6;
    color: #666;
    white-space: pre-wrap;
}

/* ========== Sidebar ========== */
.sidebar {
    width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.sidebar-group {
    background: transparent;
    border: none;
    padding: 0;
}

.sidebar-title {
    font-size: 11px;
    font-weight: 700;
    color: #8a8c90;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #dfe1e4;
}

.sidebar-field {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    width: 100%;
}

.sidebar-field label {
    flex: 0 0 100px;
    font-size: 13px;
    color: #666;
    margin: 0;
}

.sidebar-field > select,
.sidebar-field > input:not([type="checkbox"]),
.sidebar-field > .input-with-suffix {
    flex: 1;
    min-width: 0;
}

.sidebar-field-checkbox {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
}

.sidebar-field-checkbox label {
    flex: 0 0 100px;
    font-size: 13px;
    color: #666;
    margin: 0;
}


.sidebar-select {
    width: 100%;
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23999' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    transition: border-color 0.2s;
}

.sidebar-select:hover {
    border-color: #ccc;
}

.sidebar-select:focus {
    outline: none;
    border-color: #333;
}

.sidebar-input {
    width: 100%;
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.sidebar-input:focus {
    outline: none;
    border-color: #333;
}

.input-with-suffix {
    position: relative;
    width: 100%;
}

.input-with-suffix .sidebar-input {
    padding-right: 36px;
}

.input-suffix {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    font-size: 14px;
}

.sidebar-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: #333;
}

.tax-fields,
.discount-fields {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Убираем лишний отступ у последнего поля в группе */
.tax-fields .sidebar-field:last-child,
.tax-fields .sidebar-field-checkbox:last-child,
.discount-fields .sidebar-field:last-child {
    margin-bottom: 0;
}

/* Currency Selector */
.currency-selector {
    position: relative;
}

.currency-selected {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    background: white;
    transition: border-color 0.2s;
}

.currency-selected:hover {
    border-color: #ccc;
}

.currency-selected.open {
    border-color: #333;
}

.currency-code {
    font-weight: 600;
    font-size: 14px;
    flex: 1;
}

.currency-symbol {
    font-size: 14px;
    color: #666;
}

.currency-flag {
    font-size: 18px;
}

.currency-arrow {
    font-size: 10px;
    color: #999;
    transition: transform 0.2s;
}

.currency-selected.open .currency-arrow {
    transform: rotate(180deg);
}

.currency-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s;
    z-index: 100;
}

.currency-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.currency-search {
    width: 100%;
    padding: 12px 14px;
    border: none;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
    outline: none;
    border-radius: 8px 8px 0 0;
}

.currency-options {
    max-height: 240px;
    overflow-y: auto;
}

.currency-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.currency-option:hover {
    background: #f8f9fa;
}

.currency-option.selected {
    background: #f0f2f5;
}

.currency-option .currency-code {
    min-width: 40px;
}

.currency-option .currency-name {
    flex: 1;
    font-size: 13px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========== Responsive ========== */
@media (max-width: 1100px) {
    .main-content {
        flex-direction: column;
        padding: 24px;
    }

    .paper {
        max-width: 100%;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 32px;
    }

    .sidebar-group {
        flex: 1;
        min-width: 250px;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 12px 16px;
    }

    .main-content {
        padding: 16px;
    }

    .paper-content {
        padding: 24px;
    }

    .form-grid,
    .pdf-parties {
        grid-template-columns: 1fr;
        gap: 32px;
    }

    .invoice-details {
        grid-template-columns: 1fr;
    }

    .totals {
        width: 100%;
    }
}
/* Version: 1.0.1 */
