:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --info-color: #06b6d4;
    --danger-color: #ef4444;
    --bg-color: #f1f5f9;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color), #1e40af);
    color: white;
    padding: 2rem 0;
    box-shadow: var(--shadow-lg);
}

.logo {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
}

.logo i {
    font-size: 2.5rem;
}

.logo h1 {
    font-size: 2rem;
    font-weight: 700;
}

.tagline {
    font-size: 1rem;
    opacity: 0.9;
    margin-left: 65px;
}

/* Main Content */
.main-content {
    padding: 3rem 0;
}

.invoice-builder {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 30px;
    box-shadow: var(--shadow-lg);
    margin-bottom: 2rem;
}

.form-section {
    margin-bottom: 40px;
    padding-bottom: 30px;
    border-bottom: 2px solid var(--border-color);
}

.form-section:last-of-type {
    border-bottom: none;
}

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

.form-section h2 {
    color: var(--primary-color);
    font-size: 1.5rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

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

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

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

/* Items Container */
#itemsContainer {
    margin-bottom: 20px;
}

.item-row {
    background: #f8fafc;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
    position: relative;
}

.item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.item-number {
    font-weight: 600;
    color: var(--primary-color);
}

.remove-item-btn {
    background: var(--danger-color);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

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

.item-grid {
    display: grid;
    grid-template-columns: 3fr 1fr 1fr 1fr 1fr;
    gap: 15px;
    align-items: end;
}

.item-totals {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 2px dashed var(--border-color);
}

.item-total {
    text-align: center;
}

.item-total label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.item-total span {
    font-weight: 600;
    color: var(--text-color);
    font-size: 1.1rem;
}

/* Totals Section */
.totals-section {
    background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
    border: 2px solid #bae6fd;
    border-radius: 12px;
    padding: 25px;
    margin-top: 30px;
}

.totals-grid {
    margin-bottom: 20px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #bae6fd;
    font-size: 1.1rem;
}

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

.total-row.total-gross {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    padding-top: 15px;
    margin-top: 10px;
    border-top: 3px solid var(--primary-color);
}

.total-words {
    background: white;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    font-style: italic;
    color: var(--text-muted);
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: #1e40af;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-info {
    background: var(--info-color);
    color: white;
}

.btn-info:hover {
    background: #0891b2;
}

.action-buttons {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

/* Invoice Preview */
.invoice-preview {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: none;
    overflow-y: auto;
    padding: 20px;
}

.invoice-preview.active {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.preview-header {
    background: var(--primary-color);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

.preview-header h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.3rem;
}

.btn-close {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

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

.preview-content {
    background: white;
    max-width: 900px;
    width: 100%;
    margin: 20px auto;
    padding: 60px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border-radius: 8px;
}

/* Invoice Preview Styles */
.invoice-document {
    font-family: 'Arial', sans-serif;
}

.invoice-header {
    text-align: center;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 3px solid var(--primary-color);
}

.invoice-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.invoice-number {
    font-size: 1.2rem;
    color: var(--text-muted);
}

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

.party-box {
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
}

.party-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary-color);
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

.party-info p {
    margin: 5px 0;
    line-height: 1.8;
}

.party-info strong {
    display: inline-block;
    min-width: 80px;
}

.invoice-details {
    background: #f8fafc;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 30px;
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.detail-item {
    display: flex;
    justify-content: space-between;
}

.detail-label {
    font-weight: 600;
    color: var(--text-muted);
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
}

.items-table thead {
    background: var(--primary-color);
    color: white;
}

.items-table th,
.items-table td {
    padding: 12px;
    text-align: left;
    border: 1px solid var(--border-color);
}

.items-table th {
    font-weight: 600;
}

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

.items-table tfoot {
    font-weight: 600;
}

.items-table tfoot td {
    background: #f0f9ff;
}

.total-row-final {
    background: var(--primary-color) !important;
    color: white !important;
    font-size: 1.1rem;
}

.invoice-summary {
    background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 30px;
}

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

.summary-row:last-child {
    border-bottom: none;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary-color);
    padding-top: 15px;
    margin-top: 10px;
    border-top: 3px solid var(--primary-color);
}

.words-total {
    text-align: center;
    font-style: italic;
    color: var(--text-muted);
    margin-top: 15px;
}

.invoice-payment {
    background: #fef3c7;
    border-left: 4px solid #f59e0b;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 30px;
}

.invoice-payment h4 {
    color: #92400e;
    margin-bottom: 10px;
}

.invoice-notes {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid var(--border-color);
}

.invoice-notes h4 {
    color: var(--text-muted);
    margin-bottom: 10px;
}

.invoice-footer {
    margin-top: 50px;
    padding-top: 20px;
    border-top: 2px solid var(--border-color);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Footer */
.footer {
    background: #1e293b;
    color: white;
    padding: 2rem 0;
    margin-top: 4rem;
}

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

.footer-links {
    display: flex;
    gap: 20px;
}

.footer-links a {
    color: white;
    text-decoration: none;
    transition: color 0.3s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.footer-links a:hover {
    color: var(--primary-color);
}

/* Responsive */
@media (max-width: 1024px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .item-grid {
        grid-template-columns: 1fr;
    }
    
    .invoice-parties {
        grid-template-columns: 1fr;
    }
    
    .details-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .logo h1 {
        font-size: 1.5rem;
    }
    
    .tagline {
        font-size: 0.9rem;
        margin-left: 50px;
    }
    
    .invoice-builder {
        padding: 20px;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .action-buttons .btn {
        width: 100%;
        justify-content: center;
    }
    
    .preview-content {
        padding: 30px 20px;
    }
    
    .footer .container {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .footer-links {
        flex-direction: column;
        align-items: center;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
    }
    
    .header,
    .footer,
    .action-buttons,
    .preview-header {
        display: none !important;
    }
    
    .invoice-preview {
        position: static;
        display: block;
        background: white;
        padding: 0;
    }
    
    .preview-content {
        max-width: none;
        margin: 0;
        padding: 0;
        box-shadow: none;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.invoice-builder,
.form-section {
    animation: fadeIn 0.5s ease-out;
}
