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

body {
    font-family: 'Roboto', sans-serif;
    background-color: #f5f7fa; 
    color: #333; 
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

.app-container {
    display: flex;
    min-height: 100vh;
    height: 100vh;
    gap: 0; 
}

/* LEFT HALF SECTION */
.input-panel {
    flex: 1; /* Takes 50% width */
    background-color: #ffffff;
    padding: 2rem; 
    margin: 1rem; 
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    overflow-x: hidden; /* Added to prevent horizontal scrolling */
}

.input-panel,
.invoice-preview {
    min-width: 0; /* CRITICAL for flexbox on real browsers */
}

.input-header h2 {
    font-size: 1.5rem;
    font-weight: 500;
    color: #1a73e8; 
    margin-bottom: 1.5rem;
}

.items-container {
    flex-grow: 1;
    overflow-y: auto; /* Scroll if many items */
    overflow-x: hidden; /* Ensure no horizontal overflow here */
}

.item-row {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
    gap: 0.5rem;
    min-width: 0;
}

.item-row input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    background-color: #fafafa;
    min-width: 0;
    word-wrap: break-word; /* Added to handle long text in inputs */
}

.item-row input:focus {
    outline: none;
    border-color: #1a73e8;
    box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}

.remove-item {
    background-color: #ff4444; /* Red for remove */
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
    flex-shrink: 0; /* Prevent shrinking */
}

.remove-item:hover {
    background-color: #cc0000;
}

.add-item {
    background-color: #1a73e8; /* Blue for add */
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    margin-top: 1rem;
    transition: background-color 0.2s;
    align-self: flex-start; /* Align to start to avoid overflow */
}

.add-item:hover {
    background-color: #1557b0;
}

.grand-total {
    margin-top: 1.5rem;
    font-size: 1.25rem;
    font-weight: 500;
    color: #1a73e8;
    text-align: center;
}

/* RIGHT HALF SECTION */
.invoice-preview {
    flex: 1; /* Takes 50% width */
    background-color: #ffffff; 
    padding: 2rem; 
    margin: 1rem; 
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); 
    border-radius: 8px; 
    overflow-y: auto; /* Scroll if needed */
    overflow-x: hidden; /* Added for consistency */
}

.invoice-header {
    text-align: center;
    margin-bottom: 2rem;
}

.invoice-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: #1a73e8;
    margin-bottom: 0.5rem;
}

.invoice-subtitle {
    font-size: 0.9rem;
    color: #666;
    font-weight: 300;
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    table-layout: fixed; /* Added to prevent table from causing overflow */
}

.invoice-table th {
    background-color: #f0f0f0;
    padding: 0.75rem;
    text-align: left;
    font-weight: 500;
    color: #333;
    border-bottom: 2px solid #ddd;
    word-wrap: break-word; /* Handle long text */
}

.invoice-table td {
    padding: 0.75rem;
    border-bottom: 1px solid #eee;
    word-wrap: break-word; /* Handle long text */
}

.invoice-row:nth-child(even) {
    background-color: #fafafa; /* Alternating row colors */
}

.invoice-divider {
    border: none;
    height: 1px;
    background-color: #ddd;
    margin: 1rem 0;
}

.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.25rem;
    font-weight: 700;
    color: #1a73e8;
    padding: 1rem 0;
}

.total-label {
    font-weight: 500;
}

.total-amount {
    font-weight: 700;
}

/* Download PDF Button Styling */
.download-pdf {
    background-color: #1a73e8; 
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 500;
    font-family: 'Roboto', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(26, 115, 232, 0.2);
    margin-top: auto; /* Push to bottom of invoice-preview */
    align-self: center; 
    min-width: 160px; 
}

.download-pdf:hover {
    background-color: #1557b0;
    box-shadow: 0 4px 8px rgba(26, 115, 232, 0.3);
    transform: translateY(-1px); /* Subtle lift effect */
}

.download-pdf:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(26, 115, 232, 0.2);
}

.download-pdf:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.4);
}

/* =========================
   RESPONSIVE MEDIA QUERIES
   ========================= */

/* Tablets & below */
@media (max-width: 1024px) {
    body {
        overflow: auto; /* allow scrolling on smaller screens */
        height: auto;
    }

    .app-container {
        flex-direction: column;
        min-height: auto;
        height: auto;
    }

    .input-panel,
    .invoice-preview {
        flex: none;
        width: auto;
        margin: 1rem;
    }

    .invoice-header h1 {
        font-size: 1.75rem;
    }
}

/* Large phones & small tablets */
@media (max-width: 768px) {
    .input-panel,
    .invoice-preview {
        padding: 1.5rem;
    }

    .item-row {
        flex-direction: column;
        align-items: stretch;
    }

    .item-row input {
        width: 100%;
    }

    .remove-item {
        width: 100%;
    }

    .total-row {
        font-size: 1.1rem;
    }

    .download-pdf {
        width: 100%;
        align-self: stretch;
    }
}

/* Mobile devices */
@media (max-width: 480px) {
    .input-header h2 {
        font-size: 1.25rem;
        text-align: center;
    }

    .invoice-header h1 {
        font-size: 1.5rem;
    }

    .invoice-subtitle {
        font-size: 0.8rem;
    }

    .invoice-table th,
    .invoice-table td {
        padding: 0.5rem;
        font-size: 0.85rem;
    }

    .grand-total {
        font-size: 1.1rem;
    }

    .total-row {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }
}
