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

html, body {
    height: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #191919;
    color: #e5e7eb;
}

/* Kontainer */
.container {
    display: flex;
    height: 100vh;
    gap: 0;
}

/* Toolbar */
.toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #2c3e50;
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    flex-wrap: wrap;
    gap: 15px;
}

.toolbar h1 {
    margin: 0;
    font-size: 24px;
    flex: 1;
    min-width: 200px;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,0.2);
    padding: 8px 15px;
    border-radius: 5px;
}

.zoom-controls input[type="range"] {
    width: 150px;
    cursor: pointer;
}

.zoom-controls span {
    min-width: 45px;
    text-align: center;
    font-weight: bold;
}

.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Painikkeet */
.btn {
    padding: 10px 15px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
}

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

.btn-primary:hover {
    background: #e61515;
    transform: translateY(-2px);
}

.btn-success {
    background: #27ae60;
    color: white;
}

.btn-success:hover {
    background: #229954;
    transform: translateY(-2px);
}

.btn-info {
    background: #e74c3c;
    color: white;
}

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

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

.btn-secondary:hover {
    background: #7f8c8d;
}

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

.btn-warning:hover {
    background: #d68910;
}

/* Yläpalkin painikkeet: yhtenäinen väriteema */
.toolbar .button-group .btn {
    background: #ff1919;
    color: #ffffff;
    border: 1px solid #c81414;
}

.toolbar .button-group .btn:hover {
    background: #e61515;
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(255, 25, 25, 0.25);
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    background: #ff1919;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-icon {
    padding: 4px 8px;
    font-size: 14px;
    background: #ff1919;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 0 2px;
}

.btn-icon:hover {
    background: #e61515;
    transform: scale(1.1);
}

.btn-small:hover {
    background: #e61515;
}

.btn-remove {
    background: #e74c3c;
}

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

.btn-danger {
    background: #e74c3c;
}

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

/* Pää sisällön alue */
.main-wrapper {
    flex: 1;
    margin-top: 70px;
    overflow: auto;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: #191919;
}

/* Laskun kontainer */
.invoice-container {
    max-width: 210mm;
    width: 210mm;
    background: white;
    box-shadow: 0 0 15px rgba(0,0,0,0.1);
    transform-origin: top center;
    transition: transform 0.2s ease;
}

.invoice-page {
    width: 100%;
    min-height: 297mm;
    padding: 15mm;
    background: white;
    position: relative;
    font-size: 12px;
    page-break-after: always;
    box-sizing: border-box;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* PDF-export optimointi (html2pdf) */
.pdf-export-mode .invoice-container {
    width: 210mm !important;
    max-width: 210mm !important;
    margin: 0 auto !important;
    box-shadow: none !important;
    transform: none !important;
    overflow: visible !important;
}

.pdf-export-mode .invoice-page {
    width: 100% !important;
    min-height: 296mm !important;
    height: auto !important;
    padding: 12mm !important;
    margin: 0 !important;
    box-shadow: none !important;
    page-break-after: always !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    overflow: visible !important;
}

.pdf-export-mode .invoice-page:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
}

/* PDF: piilota kaikki painikkeet laskun sisältä */
.pdf-export-mode .invoice-container button,
.pdf-export-mode .invoice-container .btn,
.pdf-export-mode .invoice-container .btn-small,
.pdf-export-mode .invoice-container .btn-icon,
.pdf-export-mode .invoice-container .btn-danger,
.pdf-export-mode .invoice-container .btn-remove {
    display: none !important;
}

/* PDF: piilota myös painikkeiden taustakontit */
.pdf-export-mode .invoice-container .table-controls,
.pdf-export-mode .invoice-container .control-group,
.pdf-export-mode .invoice-container .row-actions {
    display: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* PDF: piilota virtuaaliviivakoodin manuaalinen syöttöosio */
.pdf-export-mode #virtualBarcodeContainer {
    display: none !important;
}

/* PDF: Päivämääräkentät */
.pdf-export-mode input[type="date"].editable-field {
    border: none !important;
    background: transparent !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    color: inherit !important;
    font-family: inherit !important;
    font-size: inherit !important;
}

.pdf-export-mode input[type="date"].editable-field::-webkit-calendar-picker-indicator {
    display: none !important;
}

.pdf-export-mode input[type="date"].editable-field::-webkit-inner-spin-button,
.pdf-export-mode input[type="date"].editable-field::-webkit-clear-button {
    display: none !important;
}


/* ========================================
   PDF EXPORT: Taulukon tuki (uudelleenrakennettu)
   ======================================== */

/* Taulukko-osiot */
.pdf-export-mode .invoice-tables {
    margin-bottom: 20px;
}

.pdf-export-mode .table-section {
    margin-bottom: 15px;
}

/* Taulukon otsikko */
.pdf-export-mode .table-title {
    font-weight: bold;
    font-size: 13px;
    margin-bottom: 8px;
    color: #2c3e50;
    border-bottom: 2px solid #3498db;
    padding-bottom: 5px;
    display: inline-block;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* Taulukon perustyylit */
.pdf-export-mode .invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
    font-size: 11px;
    display: table !important;
}

/* Taulukon sisältö-osa */
.pdf-export-mode .invoice-table tbody {
    display: table-row-group;
}

/* Otsikkorivi PDF:ssä */
.pdf-export-mode .invoice-table tbody tr.invoice-header-row {
    background: #f0f0f0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* Otsikkosolut PDF:ssä */
.pdf-export-mode .invoice-table tbody tr.invoice-header-row td {
    border: 1px solid #bbb !important;
    padding: 8px;
    text-align: left;
    font-weight: bold;
    background: #f0f0f0 !important;
    color: #000 !important;
    opacity: 1 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}

/* Sisältösolut */
.pdf-export-mode .invoice-table td {
    border: 1px solid #ddd;
    padding: 8px;
    vertical-align: middle;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* Parilliset rivit (paitsi otsikkorivi) */
.pdf-export-mode .invoice-table tbody tr:nth-child(even):not(.invoice-header-row) {
    background: #fafafa !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}

.pdf-export-mode .invoice-table tbody tr:nth-child(even):not(.invoice-header-row) td {
    background: #fafafa !important;
    opacity: 1 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}

/* Parittomat rivit (paitsi otsikkorivi) */
.pdf-export-mode .invoice-table tbody tr:nth-child(odd):not(.invoice-header-row) {
    background: #ffffff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}

.pdf-export-mode .invoice-table tbody tr:nth-child(odd):not(.invoice-header-row) td {
    background: #ffffff !important;
    opacity: 1 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}

/* Sarakkeiden leveydet */
.pdf-export-mode .col-description {
    width: 40%;
}

.pdf-export-mode .col-quantity {
    width: 10%;
}

.pdf-export-mode .col-unit {
    width: 10%;
}

.pdf-export-mode .col-price {
    width: 12%;
}

.pdf-export-mode .col-total {
    width: 12%;
    text-align: right;
    font-weight: bold;
}

.pdf-export-mode .col-actions {
    width: 16%;
    text-align: center;
    display: none !important; /* Piilota toimintosarake PDF:ssä */
}

/* Input-kentät: näytä vain arvo, piilota kenttä */
.pdf-export-mode .invoice-table input,
.pdf-export-mode .invoice-table textarea {
    border: none;
    background: transparent;
    padding: 0;
    margin: 0;
    font-size: 11px;
    color: #000;
    font-family: inherit;
    width: 100%;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    -webkit-text-fill-color: #000;
    opacity: 1;
}

/* Tekstin tasaus input-kentissä */
.pdf-export-mode .input-quantity,
.pdf-export-mode .input-price {
    text-align: right;
}

/* Yhteensä-sarake */
.pdf-export-mode .row-total {
    text-align: right;
    font-weight: bold;
    color: #2c3e50;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* Rivien katkeamisen esto */
.pdf-export-mode .invoice-table tbody tr {
    page-break-inside: avoid;
    break-inside: avoid;
}

.pdf-export-mode .invoice-table thead,
.pdf-export-mode .invoice-table tbody tr.invoice-header-row {
    page-break-after: avoid;
    break-after: avoid;
}

/* Taulukkosektiot */
.pdf-export-mode .table-section {
    page-break-inside: avoid;
    break-inside: avoid;
    margin-bottom: 15px;
}

.pdf-export-mode .table-title {
    page-break-after: avoid;
    break-after: avoid;
}

/* Asiakastiedot ja yhteenveto */
.pdf-export-mode .invoice-customer,
.pdf-export-mode .invoice-summary,
.pdf-export-mode .payment-info {
    page-break-inside: avoid;
    break-inside: avoid;
}

/* ======================================== */

/* Laskun header */
.invoice-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
    border-bottom: 2px solid #2c3e50;
    padding-bottom: 15px;
    width: 100%;
}

.invoice-logo-section {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.invoice-logo {
    width: 80px;
    height: 80px;
    object-fit: contain;
    border-radius: 0;
    background: transparent;
    padding: 0;
}

.company-info {
    flex: 1;
}

.company-info .editable-field {
    display: block;
    line-height: 1.4;
}

.company-info .editable-field.small {
    font-size: 11px;
    color: #666;
}

.invoice-details-section {
    text-align: right;
}

.invoice-title {
    font-size: 28px;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 15px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 12px;
}

.detail-label {
    font-weight: bold;
    margin-right: 15px;
}

.reference-number {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

/* Muokattavat kentät */
.editable-field {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    transition: all 0.2s ease;
    min-height: 18px;
    display: inline-block;
}

.editable-field:hover {
    background: #e8f4f8;
    border: 1px solid #3498db;
}

.editable-field:focus {
    outline: 2px solid #3498db;
    background: #ecf6fb;
}

/* Päivämääräkentät */
input[type="date"].editable-field {
    border: 1px solid #ddd;
    padding: 4px 8px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
}

input[type="date"].editable-field:hover {
    border-color: #3498db;
    background: #e8f4f8;
}

input[type="date"].editable-field:focus {
    outline: 2px solid #3498db;
    background: #ecf6fb;
}

input[type="date"].editable-field[readonly] {
    background: #f0f0f0;
    cursor: not-allowed;
    color: #666;
}

input[type="date"].editable-field[readonly]:hover {
    border-color: #ddd;
    background: #f0f0f0;
}

/* Asiakkaan tiedot */
.invoice-customer {
    margin-bottom: 20px;
    padding: 10px 0;
    background: transparent;
    border-radius: 0;
    border-left: none;
}

.section-title {
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 12px;
    text-transform: uppercase;
    color: #2c3e50;
}

.invoice-customer .editable-field {
    display: block;
    line-height: 1.6;
    margin-bottom: 3px;
}

.company-details-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, auto);
    grid-auto-flow: column;
    column-gap: 24px;
    row-gap: 8px;
}

.company-detail-item {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    display: grid;
    grid-template-columns: 95px 1fr;
    column-gap: 8px;
    align-items: baseline;
}

.company-detail-item .editable-field {
    display: block;
    margin: 0;
}

.company-detail-label {
    font-size: 11px;
    text-transform: none;
    letter-spacing: 0;
    color: #5d6d7e;
    font-weight: 600;
    margin-bottom: 0 !important;
}

.company-detail-value {
    font-size: 12px;
    color: #2c3e50;
    font-weight: 500;
    padding-left: 0;
}

/* Taulukot */
.invoice-tables {
    margin-bottom: 20px;
}

.table-section {
    margin-bottom: 15px;
}

.table-title {
    font-weight: bold;
    font-size: 13px;
    margin-bottom: 8px;
    color: #2c3e50;
    border-bottom: 2px solid #3498db;
    padding-bottom: 5px;
    display: inline-block;
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
    font-size: 11px;
}

.invoice-table thead {
    background: #f0f0f0;
}

.invoice-table th {
    border: 1px solid #bbb;
    padding: 8px;
    text-align: left;
    font-weight: bold;
    background: #f0f0f0;
    color: #000;
}

.invoice-table td {
    border: 1px solid #ddd;
    padding: 8px;
    vertical-align: middle;
}

/* Otsikkorivi erityistyyli */
.invoice-table tbody tr.invoice-header-row {
    background: #f0f0f0 !important;
}

.invoice-table tbody tr.invoice-header-row td {
    border: 1px solid #bbb;
    font-weight: bold;
    background: #f0f0f0;
    color: #000;
}

.invoice-table tbody tr.invoice-header-row:hover {
    background: #f0f0f0 !important;
}

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

.invoice-table tbody tr:hover {
    background: #f0f8ff;
}

/* Älä kohdista hoveria otsikkoriville */
.invoice-table tbody tr.invoice-header-row:hover {
    background: #f0f0f0 !important;
}

.col-description {
    width: 40%;
}

.col-quantity {
    width: 10%;
}

.col-unit {
    width: 10%;
}

.col-price {
    width: 12%;
}

.col-total {
    width: 12%;
    text-align: right;
    font-weight: bold;
}

.col-actions {
    width: 16%;
    text-align: center;
}

/* Taulukon Toiminnot-sarake pois käytöstä */
.invoice-table .col-actions,
.invoice-table .row-actions {
    display: none !important;
}

.input-description,
.input-quantity,
.input-unit,
.input-price {
    width: 100%;
    border: none;
    padding: 4px;
    font-size: 11px;
    background: transparent;
}

.input-quantity,
.input-price {
    text-align: right;
}

.input-description:focus,
.input-quantity:focus,
.input-unit:focus,
.input-price:focus {
    outline: 1px solid #3498db;
    background: #fffacd;
}

.row-total {
    text-align: right;
    font-weight: bold;
    color: #2c3e50;
}

.row-actions {
    white-space: nowrap;
    text-align: center;
}

.table-controls {
    display: flex;
    gap: 15px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 5px;
    flex-wrap: wrap;
    align-items: center;
}

.control-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Yhteenveto */
.invoice-summary {
    background: #f0f0f0;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 20px;
    text-align: right;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 12px;
}

.summary-item.total {
    font-size: 14px;
    font-weight: bold;
    border-top: 2px solid #2c3e50;
    padding-top: 10px;
    margin-top: 10px;
    color: #2c3e50;
}

.summary-label {
    flex: 1;
    text-align: left;
}

.editable-vat {
    display: inline;
    min-width: 20px;
    padding: 2px 4px;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.editable-vat:hover {
    background-color: #fffacd;
    outline: 1px dashed #3498db;
}

.editable-vat:focus {
    background-color: #fff;
    outline: 2px solid #3498db;
}

.summary-value {
    font-weight: bold;
    min-width: 80px;
    text-align: right;
}

/* Maksutiedot */
.payment-info {
    margin-top: 15px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 3px;
    background: #fafafa;
}

.payment-info .editable-field {
    display: block;
    margin-bottom: 5px;
    font-size: 11px;
}

/* Tilisiirtolomake */
.tilisiirtolomake-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #ddd;
}

/* Viivakoodi ja disclaimer rivi */
#barcodeAndDisclaimerRow {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
}

#barcodeContainerWrapper {
    flex: 0 0 auto;
    max-width: 50%;
}

/* Responsiveness: pienemmillä ruuduilla allekkain */
@media screen and (max-width: 768px) {
    #barcodeAndDisclaimerRow {
        flex-direction: column;
    }
    
    #barcodeContainerWrapper {
        max-width: 100%;
        width: 100%;
    }
}

.page-break {
    page-break-before: always;
    page-break-after: always;
    break-before: page;
    break-after: page;
    height: 0;
    clear: both;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: #191919;
    border-left: 1px solid #ff1919;
    overflow-y: auto;
    padding: 70px 0 0 0;
    position: fixed;
    right: 0;
    height: 100vh;
    top: 0;
    display: none;
}

.sidebar-content {
    padding: 20px;
}

.sidebar h3 {
    margin-bottom: 15px;
    color: #f9fafb;
    font-size: 14px;
}

.settings-section {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #374151;
}

.settings-section h4 {
    margin-bottom: 10px;
    font-size: 12px;
    color: #cbd5e1;
    text-transform: uppercase;
}

.settings-section label {
    display: flex;
    flex-direction: column;
    margin-bottom: 8px;
    font-size: 11px;
    color: #d1d5db;
}

.settings-section label span {
    margin-bottom: 4px;
    font-weight: 500;
}

.settings-section input,
.settings-section select {
    padding: 6px;
    border: 1px solid #ff1919;
    border-radius: 3px;
    font-size: 11px;
    background: #0d0d0d;
    color: #f9fafb;
}

.settings-section input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
}

/* Taulukko-editori Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-content.table-editor {
    width: 95%;
    height: 90%;
    background: white;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 2px solid #ddd;
    background: linear-gradient(135deg, #ff1919 0%, #191919 100%);
    color: white;
    border-radius: 8px 8px 0 0;
}

.editor-header h2 {
    margin: 0;
    font-size: 24px;
}

.btn-close {
    background: none;
    border: none;
    color: white;
    font-size: 32px;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.editor-toolbar {
    display: flex;
    gap: 10px;
    padding: 15px;
    border-bottom: 1px solid #ddd;
    background: #f8f9fa;
    flex-wrap: wrap;
    align-items: center;
}

.btn-editor {
    padding: 8px 15px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    color: #333;
}

.btn-editor:hover {
    background: #e9ecef;
    border-color: #3498db;
}

.editor-divider {
    width: 1px;
    height: 30px;
    background: #ddd;
}

.color-picker {
    width: 40px;
    height: 35px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

.editor-body {
    flex: 1;
    overflow: auto;
    padding: 20px;
    background: #f5f5f5;
}

.editor-body {
    padding: 15px;
    background: #f8f9fa;
    flex: 1;
    overflow: auto;
}

.editor-instructions {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 4px;
    padding: 10px 15px;
    margin-bottom: 15px;
    color: #856404;
}

.editor-instructions small {
    line-height: 1.6;
}

.editor-instructions strong {
    color: #533f03;
}

.editor-grid-container {
    background: white;
    border: 2px solid #ddd;
    border-radius: 4px;
    overflow: auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    max-height: 500px;
}

.editor-grid {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.editor-grid th,
.editor-grid td {
    border: 1px solid #ddd;
    padding: 0;
    min-width: 120px;
    height: 35px;
    position: relative;
}

.editor-grid th {
    background: #f8f9fa;
    font-weight: bold;
    text-align: center;
    padding: 8px;
    color: #333;
    cursor: pointer;
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 10;
    transition: all 0.2s ease;
}

.editor-grid th:hover {
    background: #e9ecef;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.editor-grid th.selected {
    background: #bbdefb !important;
    outline: 2px solid #2196f3;
    outline-offset: -2px;
}

.editor-grid th[contenteditable="true"]:focus {
    outline: 2px solid #4caf50;
    outline-offset: -2px;
    background: #fff;
}

.editor-grid td {
    background: white;
}

.editor-grid td.row-number {
    cursor: pointer;
    user-select: none;
    position: sticky;
    left: 0;
    z-index: 5;
}

.editor-grid td.row-number:hover {
    background: #e9ecef !important;
}

.editor-grid td.selected {
    outline: 3px solid #2196f3;
    outline-offset: -2px;
    background: #e3f2fd !important;
    box-shadow: inset 0 0 0 1px #2196f3;
}

.editor-cell-input {
    width: 100%;
    height: 100%;
    border: none;
    padding: 8px;
    font-size: 14px;
    font-family: inherit;
    background: transparent;
}

.editor-cell-input:focus {
    outline: 2px solid #3498db;
    outline-offset: -1px;
    background: #fff;
}

.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 15px;
    background: #f8f9fa;
    border-bottom: 2px solid #ddd;
    align-items: center;
}

.btn-editor {
    padding: 8px 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
}

.btn-editor:hover {
    background: #e9ecef;
    border-color: #3498db;
}

.btn-editor:active {
    transform: translateY(1px);
}

.btn-editor i {
    font-size: 14px;
}

.editor-divider {
    width: 1px;
    height: 30px;
    background: #ddd;
    margin: 0 5px;
}

.color-picker {
    width: 40px;
    height: 36px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

.color-picker:hover {
    border-color: #3498db;
}

.context-menu-item {
    padding: 10px 15px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s ease;
    border-bottom: 1px solid #374151;
    color: #e5e7eb;
}

.context-menu-item:last-child {
    border-bottom: none;
}

.context-menu-item:hover {
    background: #2a2a2a;
}

.context-menu-item:active {
    background: #ff1919;
}

.editor-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 20px;
    border-top: 2px solid #ddd;
    background: #f8f9fa;
}

/* Print asetukset */
@media print {
    @page {
        size: A4;
        margin: 0;
    }

    html,
    body {
        width: auto !important;
        height: auto !important;
        background: #fff !important;
    }

    .container {
        display: block !important;
        height: auto !important;
    }

    .toolbar,
    .sidebar,
    .button-group,
    .table-controls,
    .settings-section,
    .zoom-controls {
        display: none !important;
    }

    /* Piilota kaikki lomakkeen sisäiset toimintopainikkeet tulostuksessa */
    .invoice-container button,
    .invoice-container .btn,
    .invoice-container .btn-small,
    .invoice-container .btn-icon,
    .invoice-container .btn-danger,
    .invoice-container .btn-remove {
        display: none !important;
    }

    .main-wrapper {
        margin-top: 0;
        padding: 0;
        background: white;
        overflow: visible !important;
        display: block !important;
        justify-content: initial !important;
        align-items: initial !important;
    }

    .invoice-container {
        width: 210mm;
        max-width: 210mm;
        box-shadow: none;
        margin: 0 auto;
        transform: scale(1) !important;
        overflow: visible !important;
    }

    .invoice-page {
        width: 100%;
        min-height: 297mm;
        height: auto;
        padding: 15mm;
        box-sizing: border-box;
        box-shadow: none;
        page-break-after: always;
        margin: 0;
        overflow: visible !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .invoice-page:last-child {
        page-break-after: auto;
        break-after: auto;
    }

    /* Lukitse laskun alkuosan asettelu tulostuksessa kuten esikatselussa */
    .invoice-header {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 20px !important;
        margin-bottom: 20px !important;
        border-bottom: 2px solid #2c3e50 !important;
        padding-bottom: 15px !important;
        width: 100% !important;
    }

    .invoice-logo-section {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
    }

    .invoice-details-section {
        text-align: right !important;
    }

    .detail-row {
        display: flex !important;
        justify-content: space-between !important;
        margin-bottom: 8px !important;
        font-size: 12px !important;
    }

    .editable-field {
        background: transparent !important;
        border: none !important;
        padding: 2px 4px !important;
        min-height: 18px !important;
        display: inline-block !important;
        line-height: inherit !important;
        cursor: default !important;
    }

    .company-info .editable-field {
        display: block !important;
    }

    .company-detail-item .editable-field {
        display: block !important;
    }

        .company-detail-item {
            display: grid !important;
            grid-template-columns: 95px 1fr !important;
            column-gap: 8px !important;
            align-items: baseline !important;
        }

    /* Päivämääräkentät tulostuksessa */
    input[type="date"].editable-field {
        border: none !important;
        background: transparent !important;
        appearance: none !important;
        -webkit-appearance: none !important;
        -moz-appearance: none !important;
        color: inherit !important;
    }

    input[type="date"].editable-field::-webkit-calendar-picker-indicator {
        display: none !important;
    }

    input[type="date"].editable-field::-webkit-inner-spin-button,
    input[type="date"].editable-field::-webkit-clear-button {
        display: none !important;
    }

    .invoice-header,
    .invoice-details-section,
    .reference-number {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* Taulukkojen sivunvaihto-optimointi */
    .table-section {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        margin-bottom: 20px !important;
    }

    .invoice-table {
        page-break-inside: auto !important;
        break-inside: auto !important;
        width: 100% !important;
    }

    .invoice-table tbody {
        page-break-inside: auto !important;
        break-inside: auto !important;
    }

    .invoice-table tr {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        page-break-after: auto !important;
    }

    .invoice-table thead,
    .invoice-table tbody tr.invoice-header-row {
        page-break-after: avoid !important;
        break-after: avoid !important;
        page-break-inside: avoid !important;
    }

    /* Estä orporivit - pidä vähintään 2 riviä yhdessä */
    .invoice-table tbody tr {
        orphans: 2;
        widows: 2;
    }

    /* Asiakastiedot */
    .invoice-customer {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        page-break-after: avoid !important;
    }

    /* Yhteenvetotiedot */
    .invoice-summary,
    .payment-info {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* Taulukon otsikko */
    .table-title {
        page-break-after: avoid !important;
        break-after: avoid !important;
    }

    .invoice-table input,
    .invoice-table textarea {
        border: none !important;
        background: transparent !important;
    }

    input,
    textarea {
        border: none;
        background: transparent;
    }

    input:focus,
    textarea:focus {
        outline: none;
    }

    /* Viivakoodi print-optimointi */
    #barcodeContainer {
        page-break-inside: avoid !important;
        margin: 10px 0 !important;
        padding: 5px !important;
    }

    #barcodeCanvas {
        max-width: 100% !important;
        height: auto !important;
    }

    #virtualBarcodeContainer {
        page-break-inside: avoid !important;
        margin: 5px 0 !important;
        padding: 3px !important;
        display: none !important;
    }

    #virtualBarcode {
        font-size: 11px !important;
        padding: 5px !important;
    }
}

/* Responsive design */
@media screen and (max-width: 1200px) {
    .sidebar {
        width: 250px;
    }

    .button-group {
        gap: 5px;
    }

    .btn {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    .invoice-container {
        width: 100%;
        max-width: 100%;
    }
    
    .zoom-controls {
        flex-direction: column;
        padding: 6px 10px;
        gap: 5px;
    }
    
    .zoom-controls input[type="range"] {
        width: 100px;
    }
}

@media screen and (max-width: 768px) {
    .toolbar {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }

    .toolbar h1 {
        font-size: 18px;
        text-align: center;
    }

    .button-group {
        width: 100%;
        justify-content: center;
    }

    .btn {
        padding: 8px 10px;
        font-size: 11px;
    }

    .main-wrapper {
        margin-top: 160px;
        padding: 5px;
    }
    
    .invoice-container {
        width: 100%;
        max-width: 100%;
    }

    .invoice-page {
        width: 100%;
        height: auto;
        padding: 10mm;
        font-size: 11px;
    }

    .invoice-header {
        grid-template-columns: 1fr;
        gap: 10px;
    }

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

    .detail-row {
        flex-direction: column;
    }

    .company-details-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: repeat(3, auto);
        grid-auto-flow: column;
    }

    .invoice-table {
        font-size: 10px;
    }

    .invoice-table th,
    .invoice-table td {
        padding: 4px;
    }

    .col-description {
        width: 35%;
    }

    .col-quantity {
        width: 10%;
    }

    .col-unit {
        width: 8%;
    }

    .col-price {
        width: 12%;
    }

    .col-total {
        width: 12%;
    }

    .col-actions {
        width: 23%;
    }
    
    .zoom-controls {
        flex-direction: row;
        width: 100%;
        justify-content: center;
    }
}

@media screen and (max-width: 520px) {
    .company-details-grid {
        grid-template-columns: 1fr;
        grid-template-rows: none;
        grid-auto-flow: row;
    }

    .company-detail-item {
        grid-template-columns: 90px 1fr;
    }
}

/* Tulostus optimointi A4:lle */
@page {
    size: A4;
    margin: 0;
    padding: 0;
}

/* Animaatiot */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.invoice-table tbody tr {
    animation: fadeIn 0.3s ease;
}

/* Scroll bar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Tumma teema (esikatselu pidetään valkoisena) */
.toolbar {
    background: #191919;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}

.zoom-controls {
    background: rgba(255, 255, 255, 0.08);
}

.modal-content.table-editor {
    background: #ffffff;
    color: #333;
}

.editor-toolbar,
.editor-footer {
    background: #f8f9fa;
    border-color: #ddd;
}

.btn-editor {
    background: #ffffff;
    border-color: #ddd;
    color: #333;
}

.btn-editor:hover {
    background: #e9ecef;
    border-color: #ff1919;
}

.editor-divider {
    background: #ddd;
}

.editor-body {
    background: #f8f9fa;
}

.editor-instructions {
    background: #fff3cd;
    border-color: #ffc107;
    color: #856404;
}

.editor-instructions strong {
    color: #fef3c7;
}

.editor-grid-container {
    background: #ffffff;
    border-color: #ff1919;
}

.editor-grid th,
.editor-grid td {
    border-color: #ddd;
}

.editor-grid th {
    background: #f8f9fa;
    color: #333;
}

.editor-grid th:hover,
.editor-grid td.row-number:hover {
    background: #e9ecef !important;
}

.editor-grid td {
    background: #ffffff;
}

.editor-cell-input {
    color: #333;
}

.editor-cell-input:focus,
.editor-grid th[contenteditable="true"]:focus {
    background: #fff;
}

/* Säilytä itse laskun esikatselu valkoisena */
.invoice-container,
.invoice-page {
    background: #ffffff;
    color: #000000;
}

/* Varmista että kaikki laskun sisältö on valkealla taustalla ja tummalla tekstillä */
.invoice-container *,
.invoice-page * {
    color: #333;
}

/* Ylikirjoita tummia taustavärejä laskun sisällä */
.invoice-container .invoice-customer {
    background: transparent;
    color: #2c3e50;
}

.invoice-container .section-title {
    color: #2c3e50;
}

.invoice-container .editable-field {
    color: #2c3e50;
}

.invoice-container .company-detail-label {
    color: #5d6d7e;
}

.invoice-container .company-detail-value {
    color: #2c3e50;
}

/* Laskujen hallinta -modal */
.modal-content.invoice-manager {
    width: 90%;
    max-width: 1200px;
    height: 85%;
    background: #ffffff;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.manager-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 2px solid #ddd;
    background: linear-gradient(135deg, #ff1919 0%, #e61515 100%);
    color: white;
    border-radius: 8px 8px 0 0;
}

.manager-header h2 {
    margin: 0;
    font-size: 24px;
}

.manager-tabs {
    display: flex;
    border-bottom: 2px solid #ddd;
    background: #f8f9fa;
}

.tab-btn {
    padding: 15px 25px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: #e9ecef;
    color: #333;
}

.tab-btn.active {
    color: #ff1919;
    border-bottom-color: #ff1919;
    font-weight: bold;
}

.manager-body {
    flex: 1;
    overflow: auto;
    padding: 20px;
    background: #fff;
}

.tab-content {
    display: none;
}

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

.tab-toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tab-toolbar input[type="text"] {
    flex: 1;
    min-width: 200px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.items-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.invoice-item,
.customer-item,
.template-item {
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
    cursor: pointer;
}

.invoice-item:hover,
.customer-item:hover,
.template-item:hover {
    background: #e9ecef;
    border-color: #ff1919;
    transform: translateX(5px);
}

.item-info {
    flex: 1;
}

.item-title {
    font-weight: bold;
    font-size: 16px;
    color: #2c3e50;
    margin-bottom: 5px;
}

.item-details {
    font-size: 13px;
    color: #666;
}

.item-actions {
    display: flex;
    gap: 8px;
}

.item-actions button {
    padding: 6px 12px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-load {
    background: #ff1919;
    color: white;
}

.btn-load:hover {
    background: #e61515;
}

.btn-delete {
    background: #dc3545;
    color: white;
}

.btn-delete:hover {
    background: #c82333;
}

.customer-form {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.customer-form input {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.empty-state i {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.3;
}

@media screen and (max-width: 768px) {
    .modal-content.invoice-manager {
        width: 95%;
        height: 90%;
    }
    
    .tab-toolbar {
        flex-direction: column;
    }
    
    .customer-form {
        grid-template-columns: 1fr;
    }
}
