/* css/style.css */

/* Reset and Base Styles */
.sig-container * {
    box-sizing: border-box;
}

.sig-container {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    background: #f8fafc;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.sig-header {
    text-align: center;
    margin-bottom: 30px;
}

.sig-header h2 {
    color: #0a2540;
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0 0 10px 0;
}

.sig-header p {
    color: #64748b;
    font-size: 1.1rem;
    margin: 0;
}

/* Layout */
.sig-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
}

/* Form Styles */
.sig-form-section {
    background: white;
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sig-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e2e8f0;
}

.sig-section:last-child {
    border-bottom: none;
}

.sig-section h3 {
    color: #0a2540;
    font-size: 1.3rem;
    font-weight: 600;
    margin: 0 0 15px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid #e2e8f0;
}

.sig-form-group {
    margin-bottom: 15px;
}

.sig-form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.sig-form-group label {
    display: block;
    font-weight: 500;
    color: #374151;
    margin-bottom: 5px;
}

.sig-form-group input,
.sig-form-group textarea,
.sig-form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.sig-form-group input:focus,
.sig-form-group textarea:focus,
.sig-form-group select:focus {
    outline: none;
    border-color: #0a2540;
    box-shadow: 0 0 0 3px rgba(10, 37, 64, 0.1);
}

/* Logo Preview */
.sig-logo-preview {
    margin-top: 10px;
    min-height: 60px;
    border: 2px dashed #d1d5db;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9fafb;
}

.sig-logo-preview img {
    max-height: 60px;
    max-width: 200px;
    object-fit: contain;
}

/* Items Section */
.sig-items-header {
    display: grid;
    grid-template-columns: 2fr 80px 100px 100px 40px;
    gap: 10px;
    padding: 10px 0;
    font-weight: 600;
    color: #374151;
    border-bottom: 2px solid #e2e8f0;
    margin-bottom: 10px;
}

.sig-item-row {
    display: grid;
    grid-template-columns: 2fr 80px 100px 100px 40px;
    gap: 10px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #f1f5f9;
}

.sig-item-row input {
    margin: 0;
}

.item-total-display {
    font-weight: 600;
    color: #059669;
}

.sig-btn-remove {
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 4px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.sig-btn-remove:hover {
    background: #dc2626;
}

/* Buttons */
.sig-btn-primary,
.sig-btn-secondary,
.sig-btn-toggle {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.sig-btn-primary {
    background: #0a2540;
    color: white;
    box-shadow: 0 2px 4px rgba(10, 37, 64, 0.2);
}

.sig-btn-primary:hover:not(:disabled) {
    background: #23415e;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(10, 37, 64, 0.3);
}

.sig-btn-primary:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.sig-btn-secondary {
    background: #f1f5f9;
    color: #0a2540;
    border: 1px solid #d1d5db;
}

.sig-btn-secondary:hover {
    background: #e2e8f0;
    border-color: #9ca3af;
}

.sig-btn-toggle {
    background: #374151;
    color: white;
    padding: 8px 12px;
    font-size: 16px;
}

.sig-btn-toggle:hover {
    background: #4b5563;
}

.sig-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    padding-top: 20px;
    border-top: 2px solid #e2e8f0;
}

/* Preview Section */
.sig-preview-section {
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 20px;
}

.sig-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px 15px;
    border-bottom: 1px solid #e2e8f0;
}

.sig-preview-header h3 {
    color: #0a2540;
    font-size: 1.3rem;
    font-weight: 600;
    margin: 0;
}

.sig-invoice-preview {
    padding: 25px;
    min-height: 600px;
    background: white;
}

.sig-preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 400px;
    color: #9ca3af;
    font-style: italic;
}

/* Invoice Preview Styles - Enhanced for PDF Generation */
.invoice-content {
    max-width: 210mm;
    margin: 0 auto;
    background: white !important;
    font-size: 14px;
    line-height: 1.5;
    color: #374151 !important;
    font-family: 'Inter', Arial, sans-serif !important;
    padding: 20px;
    box-sizing: border-box;
    min-height: 600px;
    position: relative;
    z-index: 1;
}

/* Ensure all text is visible in PDF */
.invoice-content * {
    color: inherit !important;
    background: transparent !important;
}

.invoice-content .company-name,
.invoice-content .invoice-title h1,
.invoice-content .party-info h4,
.invoice-content .totals-row.total {
    color: #0a2540 !important;
}

.invoice-content .invoice-table th {
    background: #0a2540 !important;
    color: white !important;
}

.invoice-content .invoice-notes {
    background: #f8fafc !important;
    border-left: 4px solid #0a2540 !important;
}

.invoice-content .invoice-notes h4 {
    color: #0a2540 !important;
}

/* PDF-specific styles */
@media print, screen {
    .invoice-content {
        -webkit-print-color-adjust: exact !important;
        color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* Ensure proper rendering */
.invoice-content img {
    max-width: 100% !important;
    height: auto !important;
    display: block !important;
}

.invoice-content table {
    width: 100% !important;
    border-collapse: collapse !important;
    table-layout: fixed !important;
}

.invoice-content table td,
.invoice-content table th {
    word-wrap: break-word !important;
    padding: 8px !important;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #e2e8f0;
}

.company-info {
    flex: 1;
}

.company-logo {
    margin-bottom: 15px;
}

.company-logo img {
    max-height: 60px;
    max-width: 200px;
    object-fit: contain;
}

.company-name {
    font-size: 24px;
    font-weight: 700;
    color: #0a2540;
    margin: 0 0 5px 0;
}

.company-details {
    color: #64748b;
    font-size: 13px;
}

.invoice-title {
    text-align: right;
    flex: 0 0 auto;
}

.invoice-title h1 {
    font-size: 36px;
    font-weight: 700;
    color: #0a2540;
    margin: 0 0 10px 0;
}

.invoice-meta {
    color: #64748b;
    font-size: 13px;
}

.invoice-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    margin-bottom: 30px;
}

.party-info h4 {
    font-size: 14px;
    font-weight: 600;
    color: #0a2540;
    margin: 0 0 8px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.party-details {
    color: #374151;
    font-size: 14px;
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.invoice-table th {
    background: #0a2540;
    color: white;
    padding: 12px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.invoice-table td {
    padding: 12px;
    border-bottom: 1px solid #f1f5f9;
}

.invoice-table tr:last-child td {
    border-bottom: none;
}

.invoice-table tr:nth-child(even) {
    background: #f8fafc;
}

.text-right {
    text-align: right;
}

.text-center {
    text-align: center;
}

.invoice-totals {
    margin-left: auto;
    width: 300px;
    margin-bottom: 30px;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #f1f5f9;
}

.totals-row.total {
    font-weight: 700;
    font-size: 18px;
    color: #0a2540;
    border-top: 2px solid #0a2540;
    border-bottom: 2px solid #0a2540;
    margin-top: 10px;
    padding-top: 12px;
    padding-bottom: 12px;
}

.invoice-notes {
    background: #f8fafc;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid #0a2540;
}

.invoice-notes h4 {
    font-size: 14px;
    font-weight: 600;
    color: #0a2540;
    margin: 0 0 8px 0;
}

.invoice-notes p {
    margin: 0;
    color: #64748b;
    font-size: 13px;
    line-height: 1.6;
}

/* Dark Mode */
.sig-preview-section.dark-mode .invoice-content {
    background: #1f2937;
    color: #e5e7eb;
}

.sig-preview-section.dark-mode .invoice-header {
    border-bottom-color: #374151;
}

.sig-preview-section.dark-mode .company-name {
    color: #60a5fa;
}

.sig-preview-section.dark-mode .invoice-title h1 {
    color: #60a5fa;
}

.sig-preview-section.dark-mode .party-info h4 {
    color: #60a5fa;
}

.sig-preview-section.dark-mode .invoice-table th {
    background: #374151;
}

.sig-preview-section.dark-mode .invoice-table tr:nth-child(even) {
    background: #374151;
}

.sig-preview-section.dark-mode .totals-row.total {
    color: #60a5fa;
    border-color: #60a5fa;
}

.sig-preview-section.dark-mode .invoice-notes {
    background: #374151;
    border-left-color: #60a5fa;
}

.sig-preview-section.dark-mode .invoice-notes h4 {
    color: #60a5fa;
}

/* Modal Styles */
.sig-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.sig-modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sig-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid #e2e8f0;
}

.sig-modal-header h4 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #0a2540;
}

.sig-modal-close {
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    color: #9ca3af;
    transition: color 0.2s;
}

.sig-modal-close:hover {
    color: #374151;
}

.sig-modal-body {
    padding: 25px;
}

.sig-modal-footer {
    padding: 20px 25px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Loading States */
.sig-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.sig-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #e2e8f0;
    border-top-color: #0a2540;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Success/Error Messages */
.sig-message {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-weight: 500;
}

.sig-message.success {
    background-color: #d1fae5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

.sig-message.error {
    background-color: #fee2e2;
    color: #dc2626;
    border: 1px solid #fca5a5;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .sig-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .sig-preview-section {
        position: static;
    }
    
    .sig-form-row {
        grid-template-columns: 1fr;
    }
    
    .sig-items-header,
    .sig-item-row {
        grid-template-columns: 2fr 60px 80px 80px 30px;
        gap: 8px;
    }
}

@media (max-width: 768px) {
    .sig-container {
        padding: 15px;
    }
    
    .sig-header h2 {
        font-size: 2rem;
    }
    
    .sig-form-section,
    .sig-invoice-preview {
        padding: 20px;
    }
    
    .sig-actions {
        flex-direction: column;
    }
    
    .sig-actions button {
        width: 100%;
    }
    
    .sig-items-header {
        display: none;
    }
    
    .sig-item-row {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 15px;
        background: #f8fafc;
        border-radius: 8px;
        margin-bottom: 10px;
        border: 1px solid #e2e8f0;
    }
    
    .sig-item-row input {
        margin-bottom: 8px;
    }
    
    .sig-item-row::before {
        content: 'Description:';
        font-weight: 600;
        color: #374151;
        font-size: 12px;
        text-transform: uppercase;
        order: -1;
    }
    
    .invoice-header {
        flex-direction: column;
        gap: 20px;
    }
    
    .invoice-title {
        text-align: left;
    }
    
    .invoice-parties {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .invoice-totals {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .sig-header h2 {
        font-size: 1.75rem;
    }
    
    .sig-modal-content {
        width: 95%;
        margin: 5% auto;
    }
    
    .invoice-table {
        font-size: 12px;
    }
    
    .invoice-table th,
    .invoice-table td {
        padding: 8px 6px;
    }
}

/* Print Styles */
@media print {
    .sig-container {
        background: white;
        box-shadow: none;
        padding: 0;
        max-width: none;
    }
    
    .sig-layout {
        grid-template-columns: 1fr;
    }
    
    .sig-form-section {
        display: none;
    }
    
    .sig-preview-header {
        display: none;
    }
    
    .sig-invoice-preview {
        padding: 0;
    }
    
    .invoice-content {
        max-width: none;
        font-size: 12px;
    }
    
    .sig-preview-section {
        box-shadow: none;
        border-radius: 0;
    }
}

/* RTL Support */
[dir="rtl"] .sig-container {
    direction: rtl;
}

[dir="rtl"] .invoice-header {
    flex-direction: row-reverse;
}

[dir="rtl"] .invoice-title {
    text-align: left;
}

[dir="rtl"] .invoice-table th,
[dir="rtl"] .invoice-table td {
    text-align: right;
}

[dir="rtl"] .invoice-table th:last-child,
[dir="rtl"] .invoice-table td:last-child {
    text-align: left;
}

[dir="rtl"] .invoice-totals {
    margin-left: 0;
    margin-right: auto;
}

/* Animation for smooth transitions */
.sig-form-group input,
.sig-form-group textarea,
.sig-form-group select,
.sig-btn-primary,
.sig-btn-secondary {
    transition: all 0.2s ease;
}

/* Focus styles for accessibility */
.sig-form-group input:focus,
.sig-form-group textarea:focus,
.sig-form-group select:focus,
.sig-btn-primary:focus,
.sig-btn-secondary:focus {
    outline: 2px solid #0a2540;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .sig-container {
        border: 2px solid #000;
    }
    
    .sig-btn-primary {
        border: 2px solid #000;
    }
    
    .invoice-table th {
        border: 1px solid #000;
    }
}