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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
}

header {
    margin-bottom: 30px;
    color: white;
}

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

.header-left h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.header-left p {
    font-size: 1.1rem;
    opacity: 0.9;
}

.language-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.language-selector label {
    color: white;
    font-weight: 600;
}

.language-selector select {
    padding: 8px 12px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.language-selector select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.8);
    background: rgba(255, 255, 255, 0.2);
}

.language-selector option {
    background: #667eea;
    color: white;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
}

.form-section {
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.form-card h2 {
    margin-bottom: 25px;
    color: #4a5568;
    border-bottom: 3px solid #667eea;
    padding-bottom: 10px;
}

.form-card h3 {
    margin: 25px 0 15px 0;
    color: #667eea;
    font-size: 1.2rem;
}

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

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

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

input, textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s ease;
}

input:focus, textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

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

.preview-section {
    position: sticky;
    top: 20px;
}

.invoice-preview {
    background: white;
    border-radius: 15px;
    padding: 40px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    min-height: 600px;
}

/* ...existing code for other styles... */

input[type="file"] {
    padding: 10px;
    border: 2px dashed #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

input[type="file"]:hover {
    border-color: #667eea;
}

.logo-preview {
    margin-top: 15px;
    position: relative;
    display: inline-block;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px;
    background: #f8fafc;
}

.logo-preview img {
    max-width: 200px;
    max-height: 100px;
    object-fit: contain;
}

.btn-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #e53e3e;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.item-row {
    display: grid;
    grid-template-columns: 2fr 80px 100px 100px 40px;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
    padding: 10px;
    background: #f8fafc;
    border-radius: 8px;
}

.item-amount {
    font-weight: 600;
    color: #667eea;
}

.remove-item {
    background: #e53e3e;
    color: white;
    border: none;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.remove-item:hover {
    background: #c53030;
}

.btn-primary, .btn-secondary {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-right: 10px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f7fafc;
    color: #4a5568;
    border: 2px solid #e2e8f0;
}

.btn-secondary:hover {
    background: #edf2f7;
    border-color: #cbd5e0;
}

.form-actions {
    margin-top: 30px;
    text-align: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.form-actions .btn-primary,
.form-actions .btn-secondary {
    flex: 1;
    min-width: 140px;
    max-width: 200px;
}

/* Signature styles */
.signature-tabs {
    display: flex;
    margin-bottom: 15px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e2e8f0;
}

.signature-tab {
    flex: 1;
    padding: 12px 20px;
    background: #f8fafc;
    border: none;
    cursor: pointer;
    font-weight: 600;
    color: #4a5568;
    transition: all 0.3s ease;
}

.signature-tab.active {
    background: #667eea;
    color: white;
}

.signature-tab:hover:not(.active) {
    background: #edf2f7;
}

.signature-method {
    margin-bottom: 20px;
}

.signature-preview {
    margin-top: 15px;
    position: relative;
    display: inline-block;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px;
    background: #f8fafc;
}

.signature-preview img {
    max-width: 200px;
    max-height: 80px;
    object-fit: contain;
}

.signature-canvas-container {
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    padding: 10px;
}

#signatureCanvas {
    border: 1px dashed #cbd5e0;
    border-radius: 4px;
    cursor: crosshair;
    display: block;
    width: 100%;
    max-width: 400px;
}

.canvas-controls {
    margin-top: 10px;
    display: flex;
    gap: 10px;
}

/* Invoice preview styles */
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 3px solid #667eea;
    min-height: 100px;
}

.invoice-logo {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex: 1;
}

#previewLogo {
    display: block !important;
}

#previewLogo img {
    max-width: 150px;
    max-height: 80px;
    object-fit: contain;
}

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

.invoice-title h1 {
    font-size: 2.5rem;
    color: #667eea;
    margin-bottom: 5px;
}

.invoice-number {
    font-size: 1.2rem;
    color: #4a5568;
    margin-bottom: 15px;
}

.invoice-title .invoice-dates {
    text-align: right;
}

.invoice-title .date-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    min-width: 200px;
}

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

.party-from h3, .party-to h3 {
    color: #667eea;
    margin-bottom: 10px;
    font-size: 1.2rem;
}

.party-details {
    line-height: 1.6;
    color: #4a5568;
}

.invoice-items {
    margin-bottom: 30px;
}

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

.invoice-items th {
    background: #f8fafc;
    padding: 15px;
    text-align: left;
    border-bottom: 2px solid #e2e8f0;
    color: #4a5568;
    font-weight: 600;
}

.invoice-items td {
    padding: 15px;
    border-bottom: 1px solid #e2e8f0;
    color: #4a5568;
}

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

.totals-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #e2e8f0;
}

.totals-row.total {
    font-size: 1.2rem;
    font-weight: 600;
    color: #667eea;
    border-bottom: 3px solid #667eea;
    margin-top: 10px;
}

.invoice-signature {
    margin-top: 40px;
    padding-top: 30px;
    border-top: 2px solid #e2e8f0;
}

.signature-section {
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
}

.signature-details {
    text-align: center;
    min-width: 200px;
}

.signature-image {
    margin-bottom: 10px;
    height: 60px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.signature-image img {
    max-width: 150px;
    max-height: 60px;
    object-fit: contain;
}

.signature-line {
    height: 2px;
    background: #4a5568;
    margin-bottom: 10px;
}

.signer-name {
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 5px;
}

.signer-position {
    color: #718096;
    font-size: 0.9rem;
}

.invoice-notes {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid #e2e8f0;
    color: #4a5568;
    line-height: 1.6;
}

/* Payment information styles */
.payment-details {
    margin-top: 15px;
    padding: 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
}

.invoice-payment {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid #e2e8f0;
}

.invoice-payment h3 {
    color: #667eea;
    margin-bottom: 15px;
    font-size: 1.2rem;
}

.payment-info {
    background: #f8fafc;
    padding: 20px;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
}

.payment-method-display {
    line-height: 1.6;
    color: #4a5568;
}

.bank-details {
    margin-top: 15px;
    padding-left: 20px;
}

.bank-details p {
    margin-bottom: 8px;
}

/* RTL support */
.rtl {
    direction: rtl;
    text-align: right;
}

.rtl .main-content {
    grid-template-columns: 1fr 1fr;
    direction: ltr;
}

.rtl .form-section {
    direction: rtl;
}

.rtl .preview-section {
    direction: rtl;
}

.rtl .form-row {
    direction: rtl;
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
        width: 100%;
        overflow-x: hidden;
    }
    
    .header-content {
        flex-direction: column;
        gap: 15px;
        text-align: center;
        width: 100%;
    }
    
    .header-left h1 {
        font-size: 1.8rem;
    }
    
    .language-selector {
        justify-content: center;
        width: 100%;
    }
    
    .main-content {
        grid-template-columns: 1fr;
        gap: 20px;
        width: 100%;
    }
    
    .form-section, .invoice-preview {
        padding: 20px;
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    
    .form-card {
        width: 100%;
    }
    
    .form-card h2 {
        font-size: 1.3rem;
        margin-bottom: 20px;
    }
    
    .form-card h3 {
        font-size: 1.1rem;
        margin: 20px 0 10px 0;
    }
    
    .form-row {
        grid-template-columns: 1fr;
        gap: 15px;
        width: 100%;
    }
    
    .form-group {
        width: 100%;
    }
    
    input, textarea, select {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    .item-row {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 15px 10px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .item-row input {
        margin-bottom: 5px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .item-amount {
        text-align: center;
        font-size: 1.1rem;
        padding: 8px;
        background: #667eea;
        color: white;
        border-radius: 6px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .remove-item {
        width: 100%;
        padding: 10px;
        margin-top: 5px;
        box-sizing: border-box;
    }
    
    .signature-tabs {
        flex-direction: column;
        width: 100%;
    }
    
    .signature-tab {
        padding: 15px;
        width: 100%;
    }
    
    .signature-canvas-container {
        width: 100%;
        overflow: hidden;
    }
    
    #signatureCanvas {
        width: 100%;
        max-width: 100%;
        height: 120px;
        box-sizing: border-box;
    }
    
    .canvas-controls {
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }
    
    .canvas-controls button {
        width: 100%;
    }
    
    .form-actions {
        text-align: center;
        width: 100%;
    }
    
    .btn-primary, .btn-secondary {
        width: 100%;
        margin: 5px 0;
        padding: 15px;
        font-size: 16px;
        box-sizing: border-box;
    }
    
    .preview-section {
        position: static;
        width: 100%;
        overflow-x: hidden;
    }
    
    .invoice-preview {
        padding: 15px;
        margin-bottom: 20px;
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    
    .invoice-header {
        flex-direction: column;
        gap: 20px;
        text-align: center;
        min-height: auto;
        width: 100%;
    }
    
    .invoice-logo, .invoice-title {
        width: 100%;
        text-align: center;
    }
    
    .invoice-title h1 {
        font-size: 2rem;
    }
    
    .invoice-title .date-item {
        flex-direction: column;
        text-align: center;
        gap: 5px;
        width: 100%;
    }
    
    .invoice-parties {
        grid-template-columns: 1fr;
        gap: 20px;
        width: 100%;
    }
    
    .party-from, .party-to {
        width: 100%;
    }
    
    .invoice-items {
        width: 100%;
        overflow-x: auto;
        margin: 0 -15px;
        padding: 0 15px;
    }
    
    .invoice-items table {
        min-width: 100%;
        width: 100%;
        font-size: 0.9rem;
        table-layout: fixed;
    }
    
    .invoice-items th,
    .invoice-items td {
        padding: 8px 4px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .invoice-items th:first-child,
    .invoice-items td:first-child {
        width: 40%;
    }
    
    .invoice-items th:nth-child(2),
    .invoice-items td:nth-child(2) {
        width: 15%;
    }
    
    .invoice-items th:nth-child(3),
    .invoice-items td:nth-child(3) {
        width: 20%;
    }
    
    .invoice-items th:nth-child(4),
    .invoice-items td:nth-child(4) {
        width: 25%;
    }
    
    .invoice-totals {
        font-size: 0.9rem;
        width: 100%;
        box-sizing: border-box;
    }
    
    .totals-row {
        width: 100%;
        flex-wrap: nowrap;
    }
    
    .totals-row.total {
        font-size: 1.1rem;
    }
    
    .invoice-payment {
        width: 100%;
        box-sizing: border-box;
    }
    
    .payment-info {
        padding: 15px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .bank-details {
        padding-left: 0;
        margin-top: 10px;
        width: 100%;
    }
    
    .signature-section {
        justify-content: center;
        flex-direction: column;
        align-items: center;
        gap: 15px;
        width: 100%;
    }
    
    .signature-details {
        width: 100%;
        max-width: 200px;
    }
    
    .invoice-notes {
        width: 100%;
        box-sizing: border-box;
        word-wrap: break-word;
    }
    
    .logo-preview img {
        max-width: 150px;
        max-height: 80px;
    }
    
    #previewLogo img {
        max-width: 120px;
        max-height: 60px;
    }
}

/* iPhone SE and similar small devices */
@media (max-width: 375px) {
    .container {
        padding: 8px;
        margin: 0;
        width: 100vw;
        max-width: 100vw;
    }
    
    body {
        overflow-x: hidden;
        width: 100vw;
        max-width: 100vw;
    }
    
    .header-left h1 {
        font-size: 1.5rem;
    }
    
    .form-section, .invoice-preview {
        padding: 12px;
        width: calc(100vw - 24px);
        max-width: calc(100vw - 24px);
    }
    
    .form-card h2 {
        font-size: 1.2rem;
    }
    
    .form-card h3 {
        font-size: 1rem;
    }
    
    input, textarea, select {
        padding: 10px;
        font-size: 14px;
        width: 100%;
        max-width: 100%;
    }
    
    .item-row {
        padding: 10px 8px;
    }
    
    .signature-tab {
        padding: 12px;
        font-size: 14px;
    }
    
    #signatureCanvas {
        height: 100px;
        width: 100%;
        max-width: 100%;
    }
    
    .btn-primary, .btn-secondary {
        padding: 12px;
        font-size: 14px;
    }
    
    .invoice-title h1 {
        font-size: 1.6rem;
    }
    
    .invoice-number {
        font-size: 1rem;
    }
    
    .invoice-items {
        margin: 0 -12px;
        padding: 0 12px;
        width: calc(100% + 24px);
    }
    
    .invoice-items table {
        font-size: 0.8rem;
        width: 100%;
        min-width: 100%;
    }
    
    .invoice-items th,
    .invoice-items td {
        padding: 6px 3px;
        font-size: 0.75rem;
    }
    
    .payment-info {
        padding: 10px;
        font-size: 0.9rem;
    }
    
    .invoice-notes {
        font-size: 0.9rem;
    }
    
    .language-selector select {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .language-selector label {
        font-size: 14px;
    }
}

/* Pixel 7 and similar devices */
@media (max-width: 412px) and (max-height: 915px) {
    .container {
        width: 100vw;
        max-width: 100vw;
        padding: 10px;
    }
    
    .form-section, .invoice-preview {
        width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
    }
    
    .invoice-items {
        width: calc(100% + 20px);
        margin: 0 -10px;
        padding: 0 10px;
    }
}

/* iPad Mini portrait */
@media (max-width: 768px) and (max-height: 1024px) and (orientation: portrait) {
    .main-content {
        grid-template-columns: 1fr;
        max-width: 100%;
    }
    
    .invoice-items table {
        font-size: 0.95rem;
    }
    
    .invoice-items th,
    .invoice-items td {
        padding: 10px 6px;
    }
}

/* iPad Mini landscape */
@media (max-width: 1024px) and (max-height: 768px) and (orientation: landscape) {
    .main-content {
        grid-template-columns: 1fr 1fr;
        gap: 15px;
    }
    
    .form-section, .invoice-preview {
        padding: 15px;
    }
}

/* Ensure no horizontal overflow */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Fix for WebKit browsers */
@supports (-webkit-touch-callout: none) {
    .container {
        -webkit-overflow-scrolling: touch;
    }
}

/* Footer styles */
footer {
    margin-top: 50px;
    padding: 20px 0;
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.footer-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
}

.footer-circle {
    font-size: 12px;
    opacity: 0.6;
}

.copyright {
    font-weight: 500;
}

@media (max-width: 768px) {
    footer {
        margin-top: 30px;
        padding: 15px 0;
    }
    
    .footer-content {
        font-size: 12px;
        gap: 8px;
    }
    
    .footer-circle {
        font-size: 10px;
    }
}

/* Scroll to Top Button */
.scroll-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
}

.scroll-to-top:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
    background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
}

.scroll-to-top:active {
    transform: translateY(-1px);
}

.scroll-to-top svg {
    transition: transform 0.3s ease;
}

.scroll-to-top:hover svg {
    transform: translateY(-2px);
}

/* Smooth scroll behavior */
html {
    scroll-behavior: smooth;
}

@media (max-width: 768px) {
    .scroll-to-top {
        bottom: 20px;
        right: 20px;
        width: 45px;
        height: 45px;
    }
    
    .scroll-to-top svg {
        width: 20px;
        height: 20px;
    }
}
