/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #263D42;
    background-color: #F9FAFB;
    font-size: 16px;
}

/* Container and Layout */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.app-header {
    text-align: center;
    margin-bottom: 40px;
}

.app-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: #263D42;
    margin-bottom: 8px;
}

.app-header p {
    font-size: 1.1rem;
    color: #6B7280;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 40px;
}

@media (min-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr 1fr;
        gap: 60px;
    }
}

/* Form Sections */
.form-section {
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

section {
    margin-bottom: 40px;
}

section:last-child {
    margin-bottom: 0;
}

section h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #263D42;
    margin-bottom: 20px;
    border-bottom: 2px solid #ADD7F6;
    padding-bottom: 8px;
}

/* Form Elements */
.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

@media (min-width: 768px) {
    .form-row {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-weight: 500;
    margin-bottom: 6px;
    color: #263D42;
}

.form-group input,
.form-group textarea,
.form-group select {
    padding: 12px 16px;
    border: 2px solid #E5E7EB;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s ease;
    background: white;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #ADD7F6;
    box-shadow: 0 0 0 3px rgba(173, 215, 246, 0.1);
}

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

/* Logo Upload */
.logo-upload {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
}

.upload-btn {
    background: #ADD7F6;
    color: #263D42;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.upload-btn:hover {
    background: #87BFFF;
}

.logo-preview {
    max-width: 200px;
    max-height: 100px;
    border: 2px dashed #E5E7EB;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    color: #6B7280;
}

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

/* Items Table */
.items-table {
    background: white;
    border-radius: 8px;
    overflow: hidden;
}

.table-header {
    display: grid;
    grid-template-columns: 2fr 80px 120px 120px 80px;
    gap: 12px;
    background: #F3F4F6;
    padding: 16px;
    font-weight: 600;
    color: #263D42;
}

.item-row {
    display: grid;
    grid-template-columns: 2fr 80px 120px 120px 80px;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid #E5E7EB;
    align-items: center;
}

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

.item-row input {
    padding: 8px 12px;
    border: 1px solid #E5E7EB;
    border-radius: 6px;
    font-size: 14px;
}

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

.item-total {
    font-weight: 600;
    color: #263D42;
}

.remove-item-btn {
    background: #EF4444;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s ease;
}

.remove-item-btn:hover {
    background: #DC2626;
}

.add-item-btn {
    background: #ADD7F6;
    color: #263D42;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 16px;
    transition: background-color 0.2s ease;
}

.add-item-btn:hover {
    background: #87BFFF;
}

/* Summary Section */
.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #E5E7EB;
}

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

.summary-row.total-row {
    font-size: 1.2rem;
    font-weight: 700;
    color: #263D42;
    border-top: 2px solid #ADD7F6;
    margin-top: 12px;
    padding-top: 16px;
}

.summary-row input {
    width: 100px;
    padding: 8px 12px;
    border: 1px solid #E5E7EB;
    border-radius: 6px;
    text-align: right;
}

.summary-row input:focus {
    outline: none;
    border-color: #ADD7F6;
}

/* Actions */
.generate-btn {
    background: #263D42;
    color: white;
    border: none;
    padding: 16px 32px;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: background-color 0.2s ease;
}

.generate-btn:hover {
    background: #1F2937;
}

.pdf-info {
    margin-top: 12px;
    font-size: 0.9rem;
    color: #6B7280;
    text-align: center;
    line-height: 1.4;
}

/* Invoice Preview */
.preview-section {
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.invoice-document {
    max-width: 100%;
    margin: 0 auto;
    background: white;
    color: #263D42;
}

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

.invoice-logo img {
    max-width: 150px;
    max-height: 80px;
    object-fit: contain;
}

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

.invoice-title h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: #263D42;
    margin-bottom: 16px;
}

.invoice-meta div {
    margin-bottom: 8px;
    font-size: 1rem;
}

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

.party-from h3,
.party-to h3 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: #263D42;
}

.party-from div,
.party-to div {
    line-height: 1.6;
    white-space: pre-line;
}

/* Invoice Items Table */
.invoice-items {
    margin-bottom: 40px;
}

#previewItemsTable {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

#previewItemsTable th,
#previewItemsTable td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #E5E7EB;
}

#previewItemsTable th {
    background: #F3F4F6;
    font-weight: 600;
    color: #263D42;
}

#previewItemsTable td:nth-child(2),
#previewItemsTable td:nth-child(3),
#previewItemsTable td:nth-child(4),
#previewItemsTable th:nth-child(2),
#previewItemsTable th:nth-child(3),
#previewItemsTable th:nth-child(4) {
    text-align: right;
}

/* Invoice Summary */
.invoice-summary {
    display: flex;
    justify-content: flex-end;
}

.summary-table {
    min-width: 300px;
}

.summary-table .summary-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #E5E7EB;
}

.summary-table .summary-row.total {
    font-size: 1.2rem;
    font-weight: 700;
    border-top: 2px solid #263D42;
    border-bottom: 3px double #263D42;
    margin-top: 8px;
    padding-top: 12px;
}

/* Print Styles */
@media print {
    @page {
        margin: 0.5in;
        size: A4;
        @top-left { content: ""; }
        @top-center { content: ""; }
        @top-right { content: ""; }
        @bottom-left { content: ""; }
        @bottom-center { content: ""; }
        @bottom-right { content: ""; }
    }
    
    html {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    body {
        background: white;
        font-size: 12px;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .container {
        max-width: none;
        padding: 0;
    }
    
    .app-header,
    .form-section {
        display: none !important;
    }
    
    .main-content {
        display: block;
    }
    
    .preview-section {
        box-shadow: none;
        padding: 0;
        position: static;
        max-height: none;
        overflow: visible;
    }
    
    .invoice-document {
        max-width: none;
    }
    
    .invoice-header-table,
    .invoice-parties-table {
        border-collapse: collapse !important;
        width: 100% !important;
    }
    
    .invoice-header-table td,
    .invoice-parties-table td {
        border: none !important;
        padding: 0 !important;
        vertical-align: top !important;
    }
    
    .invoice-title h1 {
        font-size: 2rem;
        margin: 0;
    }
    
    #previewItemsTable {
        page-break-inside: avoid;
        width: 100%;
        border-collapse: collapse;
    }
    
    .invoice-summary {
        page-break-inside: avoid;
        display: block;
        text-align: right;
        margin-top: 20px;
    }
    
    .summary-table {
        display: inline-block;
        min-width: 300px;
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .container {
        padding: 16px;
    }
    
    .app-header h1 {
        font-size: 2rem;
    }
    
    .form-section,
    .preview-section {
        padding: 20px;
    }
    
    .table-header,
    .item-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .table-header {
        display: none;
    }
    
    .item-row {
        background: #F9FAFB;
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 16px;
        border: 1px solid #E5E7EB;
    }
    
    .item-row input {
        margin-bottom: 8px;
    }
    
    .invoice-header-preview {
        flex-direction: column;
        text-align: center;
    }
    
    .invoice-title {
        text-align: center;
    }
    
    .invoice-parties {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .summary-table {
        min-width: 100%;
    }
}

@media (max-width: 480px) {
    .app-header h1 {
        font-size: 1.8rem;
    }
    
    .invoice-title h1 {
        font-size: 1.8rem;
    }
    
    #previewItemsTable th,
    #previewItemsTable td {
        padding: 8px 4px;
        font-size: 0.9rem;
    }
}
