:root {
    /* Premium Dark Theme for Editor */
    --bg-app: #0f172a;
    --bg-panel: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;

    /* Invoice Paper Theme - Premium */
    --paper-bg: #ffffff;
    --paper-text: #334155;
    --paper-accent: #0f172a;
    /* Deep Slate */
    --paper-accent-light: #f1f5f9;
    --paper-border: #e2e8f0;
    --paper-highlight: #3b82f6;
    /* Bright Blue for highlights */
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100%;
}

/* --- Editor Panel --- */
.editor-panel {
    width: 400px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.editor-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-header h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0;
}

.language-switcher {
    display: flex;
    align-items: center;
}

.editor-header p {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

#invoiceForm {
    padding: 1.5rem;
    flex: 1;
}

.form-section {
    margin-bottom: 2rem;
}

.form-section h2 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-weight: 600;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

input,
select,
textarea {
    width: 100%;
    background-color: var(--bg-app);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.625rem;
    border-radius: 0.375rem;
    font-family: inherit;
    font-size: 0.875rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.item-row {
    background-color: var(--bg-app);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    position: relative;
    animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.item-row-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.btn-remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 0.875rem;
    padding: 0.25rem;
    transition: opacity 0.2s;
}

.btn-remove:hover,
.btn-remove:focus {
    text-decoration: underline;
    opacity: 0.8;
    outline: 2px solid var(--danger);
    outline-offset: 2px;
    border-radius: 2px;
}

.btn-secondary {
    background: none;
    border: 1px dashed var(--border-color);
    color: var(--primary);
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.btn-secondary:hover,
.btn-secondary:focus {
    background-color: rgba(59, 130, 246, 0.1);
    border-color: var(--primary);
}

.btn-secondary:active {
    transform: scale(0.98);
}

.editor-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-panel);
    position: sticky;
    bottom: 0;
}

.footer-buttons-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.btn-primary {
    width: 100%;
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--primary-hover);
}

.btn-primary:active {
    transform: scale(0.98);
}

/* Keyboard navigation improvements */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* --- Preview Panel --- */
.preview-panel {
    flex: 1;
    background-color: #525659;
    /* Browser PDF viewer bg color */
    padding: 2rem;
    overflow-y: auto;
    display: block;
    /* Changed from flex to block to allow proper scrolling/expansion */
}

.preview-wrapper {
    width: 210mm;
    /* A4 width */
    min-height: 297mm;
    /* A4 height */
    background: white;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    margin: 0 auto 2rem auto;
    /* Center horizontally */
}

/* --- Invoice Paper Design --- */
.invoice-paper {
    padding: 15mm;
    color: #333;
    font-size: 10pt;
    line-height: 1.4;
    position: relative;
    min-height: 100%;
    /* Ensure it fills the wrapper */
    height: auto;
    /* Allow it to grow */
    display: flex;
    flex-direction: column;
    font-family: 'Inter', sans-serif;
}

/* Orange Bar */
.header-bar {
    width: 100%;
    height: 8px;
    background-color: #ff6600;
    margin-bottom: 15px;
}

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

.logo {
    max-width: 200px;
    max-height: 80px;
}

.text-logo {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--paper-accent, #0f172a);
    text-align: left;
    line-height: 1.2;
    margin-bottom: 10px;
}

.header-right {
    text-align: right;
    width: 60%;
    /* Give it specific width to align bar */
}

.header-date {
    font-size: 24pt;
    font-weight: 800;
    color: #ff6600;
    margin-bottom: 5px;
}

.header-note {
    font-size: 9pt;
    color: #666;
}

.header-meta-row {
    font-size: 10pt;
    font-weight: 600;
    color: #0f172a;
    padding-top: 5px;
    text-transform: uppercase;
}

.meta-separator {
    margin: 0 5px;
    color: #ccc;
}

/* Info Section */
.info-total-section {
    display: flex;
    justify-content: space-between;
    margin-bottom: 40px;
    align-items: flex-start;
}

.info-col-left {
    width: 45%;
}

.company-info-block {
    border-left: 4px solid #0f172a;
    padding-left: 15px;
    font-size: 9pt;
    color: #444;
    line-height: 1.5;
}

.company-name {
    font-weight: 800;
    color: #0f172a;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.info-col-right {
    width: 45%;
    text-align: left;
}

.customer-info-block-right {
    font-size: 10pt;
    color: #333;
}

.sayin-label {
    font-size: 8pt;
    color: #999;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 5px;
    letter-spacing: 1px;
}

.customer-name-right {
    font-weight: 800;
    font-size: 11pt;
    margin-bottom: 5px;
    color: #0f172a;
    text-transform: uppercase;
}

.customer-address-right {
    margin-bottom: 5px;
    color: #555;
    white-space: pre-line;
}

.customer-phone-right {
    color: #555;
    font-weight: 500;
}

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

.table-header-row {
    display: flex;
    border-bottom: 2px solid #0f172a;
    /* Dark blue border */
    padding-bottom: 10px;
    margin-bottom: 15px;
    font-weight: 700;
    color: #0f172a;
    font-size: 9pt;
    text-transform: uppercase;
}

.th-desc {
    width: 50%;
}

.th-price {
    width: 15%;
    text-align: right;
}

.th-qty {
    width: 15%;
    text-align: center;
}

.th-total {
    width: 20%;
    text-align: right;
}

.item-row-display {
    display: flex;
    padding: 15px 0;
    border-bottom: 1px solid #e2e8f0;
    align-items: center;
}

.item-row-display:last-child {
    border-bottom: none;
}

.col-desc {
    width: 50%;
    padding-left: 0;
    font-weight: 700;
    color: #444;
}

.col-price {
    width: 15%;
    text-align: right;
    color: #444;
    font-size: 9pt;
}

.col-qty {
    width: 15%;
    text-align: center;
    color: #444;
}

.col-total {
    width: 20%;
    text-align: right;
    padding-right: 0;
    font-weight: 700;
    color: #444;
}

/* Totals Section */
.totals-section {
    display: flex;
    justify-content: space-between;
    margin-bottom: 40px;
    align-items: flex-start;
}

.notes-col {
    width: 55%;
    padding-right: 20px;
}

.notes-content {
    font-size: 9pt;
    color: #555;
    white-space: pre-line;
    line-height: 1.4;
}

.totals-col-right {
    width: 40%;
}

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

.totals-table th {
    text-align: left;
    padding: 8px 0;
    font-size: 8pt;
    color: #444;
    font-weight: 700;
    text-transform: uppercase;
}

.totals-table td {
    text-align: right;
    padding: 8px 0;
    font-weight: 800;
    color: #333;
}

.totals-table tr {
    border-bottom: 1px dotted #ccc;
}

.totals-table tr:last-child {
    border-bottom: none;
}

/* Footer */
.invoice-footer {
    margin-top: auto;
    border-top: 1px solid #999;
    padding-top: 20px;
    display: flex;
    align-items: center;
}

.footer-logo {
    margin-right: 20px;
}

.footer-logo-img {
    height: 40px;
}

.footer-logo .text-logo {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: #333;
}

.footer-info {
    font-size: 8pt;
    color: #666;
    line-height: 1.4;
}

.footer-info strong {
    color: #333;
}

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

    body {
        background: white;
        height: auto;
        overflow: visible;
    }

    .app-container {
        display: block;
    }

    .editor-panel {
        display: none;
    }

    .preview-panel {
        padding: 0;
        background: white;
        overflow: visible;
        display: block;
    }

    .preview-wrapper {
        width: 100%;
        box-shadow: none;
        margin: 0;
    }

    .invoice-paper {
        padding: 15mm;
        /* Standard A4 margins */
        min-height: 297mm;
    }

    /* Ensure colors print correctly */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* --- Notification Toast --- */
.notification {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background-color: var(--bg-panel);
    color: var(--text-main);
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    border: 1px solid var(--border-color);
    max-width: 300px;
}

.notification.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.notification-success {
    border-left: 4px solid #10b981;
}

.notification-error {
    border-left: 4px solid var(--danger);
}

.notification-info {
    border-left: 4px solid var(--primary);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .editor-panel {
        width: 100%;
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s;
    }

    .editor-panel.open {
        transform: translateX(0);
    }

    .preview-panel {
        width: 100%;
    }

    .notification {
        right: 1rem;
        left: 1rem;
        max-width: none;
    }
}