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

:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #16a34a;
    --danger-color: #dc2626;
    --border-color: #e2e8f0;
    --bg-light: #f8fafc;
    --text-dark: #1e293b;
    --text-muted: #64748b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 1rem 0;
    color: var(--text-dark);
}

.container {
    max-width: 100%;
    margin: 0 auto;
    background: white;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 2rem;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.logo-title {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-logo {
    width: 60px;
    height: 60px;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
    transition: transform 0.3s ease;
}

.header-logo:hover {
    transform: scale(1.05) rotate(2deg);
}

header h1 {
    font-size: 2.5rem;
    margin: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.language-selector {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.5);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
    height: 48px;
    display: flex;
    align-items: center;
}

.language-selector:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.8);
}

.language-selector:focus {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 1);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
}

.language-selector option {
    background: #1e293b;
    color: white;
    padding: 0.5rem;
}

.currency-selector {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.5);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
    height: 48px;
    display: flex;
    align-items: center;
}

.currency-selector:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.8);
}

.currency-selector:focus {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 1);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
}

.currency-selector option {
    background: #1e293b;
    color: white;
    padding: 0.5rem;
}

.subtitle {
    font-size: 1rem;
    opacity: 0.95;
    margin-bottom: 1rem;
}

.btn-test {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.5);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-test:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.8);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        text-align: center;
    }

    .logo-title {
        flex-direction: column;
        gap: 0.5rem;
    }

    .header-logo {
        width: 50px;
        height: 50px;
    }

    header h1 {
        font-size: 2rem;
    }

    .header-actions {
        flex-direction: column;
        width: 100%;
    }

    .language-selector,
    .btn-test {
        width: 100%;
    }
}

.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    padding: 1.5rem 1rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* Form Section */
.form-section {
    width: 100%;
}

.form-section h2 {
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    font-size: 1.75rem;
}

.form-group {
    background: var(--bg-light);
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

.form-group h3 {
    color: var(--text-dark);
    margin-bottom: 1rem;
    font-size: 1.25rem;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.5rem;
}

.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.input-row:last-child {
    margin-bottom: 0;
}

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

.input-group label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-dark);
    font-size: 0.9rem;
}

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

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

.button-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Logo Upload */
.logo-upload-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.logo-preview {
    margin-top: 0.5rem;
    min-height: 80px;
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-light);
    position: relative;
    transition: all 0.3s ease;
}

.logo-preview.drag-over {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.logo-placeholder {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
    padding: 1rem;
    user-select: none;
}

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

.logo-preview.has-logo {
    border-style: solid;
}

.logo-preview .remove-logo {
    position: absolute;
    top: 5px;
    right: 5px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-preview .remove-logo:hover {
    background: #c82333;
}

.invoice-logo {
    max-width: 120px;
    max-height: 45px;
    object-fit: contain;
}

/* Item Row */
.item-row {
    background: white;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

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

.item-header h4 {
    color: var(--text-dark);
    font-size: 1rem;
}

.item-controls {
    display: grid;
    grid-template-columns: 0.8fr 2fr 0.8fr 0.6fr 1fr 0.8fr 0.8fr;
    gap: 0.5rem;
}

.item-controls .input-group label {
    font-size: 0.85rem;
}

.item-controls input,
.item-controls select {
    padding: 0.6rem;
    font-size: 0.9rem;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-danger {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

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

.btn-primary:hover {
    background: #1d4ed8;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
    font-size: 0.9rem;
    padding: 0.6rem 1.2rem;
}

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

.btn-danger {
    background: var(--danger-color);
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.btn-danger:hover {
    background: #b91c1c;
}

.actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    background: white;
    padding: 1.5rem;
}

/* Preview Section */
.preview-section {
    background: var(--bg-light);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    width: 100%;
}

.preview-section h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.invoice-document {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    min-height: 400px;
    font-size: 0.95rem;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem;
    font-style: italic;
}

/* Invoice Preview Styles */
.invoice-header {
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.invoice-title-section {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.invoice-title {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary-color);
}

.invoice-number {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary-color);
}

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

.party-info {
    background: var(--bg-light);
    padding: 0.6rem;
    border-radius: 6px;
}

.party-info h3 {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.4rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3rem;
}

.party-info p {
    margin: 0.15rem 0;
    font-size: 0.8rem;
    line-height: 1.3;
}

.party-info strong {
    font-weight: 600;
    color: var(--text-dark);
    display: inline-block;
    min-width: 90px;
}

.invoice-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem;
    margin-bottom: 1rem;
    font-size: 0.8rem;
}

.invoice-details p {
    margin: 0.15rem 0;
    line-height: 1.3;
}

.invoice-details strong {
    font-weight: 600;
}

/* Items Table */
.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    font-size: 0.75rem;
}

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

.items-table th {
    padding: 0.4rem 0.3rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.7rem;
}

.items-table td {
    padding: 0.4rem 0.3rem;
    border-bottom: 1px solid var(--border-color);
    line-height: 1.3;
    vertical-align: top;
}

.items-table tbody tr:hover {
    background: var(--bg-light);
}

.items-table .text-right {
    text-align: right;
}

.items-table .text-center {
    text-align: center;
}

/* Summary */
.invoice-summary {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

.summary-table {
    width: 300px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
}

.summary-row.total {
    background: var(--primary-color);
    color: white;
    font-weight: bold;
    font-size: 0.9rem;
    border-radius: 6px;
    margin-top: 0.3rem;
    padding: 0.5rem;
}

.summary-row:not(.total) {
    border-bottom: 1px solid var(--border-color);
}

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

/* Loading Spinner */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.loading-overlay.show {
    display: flex;
}

.spinner-container {
    text-align: center;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    color: white;
    font-size: 1.1rem;
    font-weight: 500;
    margin: 0;
}

/* Print Styles */
@media print {
    body {
        background: white;
        padding: 0;
    }

    .container {
        box-shadow: none;
        border-radius: 0;
    }

    header,
    .form-section,
    .preview-section h2 {
        display: none;
    }

    .main-content {
        display: block;
        padding: 0;
    }

    .invoice-document {
        box-shadow: none;
        padding: 1rem;
    }
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .container {
        border-radius: 0;
        padding: 0.5rem;
    }

    header {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .main-content {
        grid-template-columns: 1fr;
        padding: 0.5rem;
    }

    .form-section, .preview-section {
        padding: 1rem;
    }

    .input-row,
    .item-controls,
    .invoice-parties,
    .invoice-details {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .actions .btn {
        width: 100%;
    }

    .summary-table {
        width: 100%;
    }

    .invoice-title {
        font-size: 1.5rem;
    }

    .items-table {
        font-size: 0.75rem;
        overflow-x: auto;
        display: block;
    }

    .items-table th,
    .items-table td {
        padding: 0.5rem 0.25rem;
    }

    .spinner {
        width: 40px;
        height: 40px;
    }

    .loading-text {
        font-size: 0.9rem;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    header h1 {
        font-size: 1.2rem;
    }

    .form-section h2,
    .preview-section h2 {
        font-size: 1.2rem;
    }

    .invoice-title {
        font-size: 1.2rem;
    }

    .items-table {
        font-size: 0.7rem;
    }

    .btn {
        font-size: 0.9rem;
        padding: 0.6rem 1rem;
    }
}
