:root {
    --primary: #6B4EFF;
    --primary-light: #EDE9FF;
    --primary-dark: #5A3FE0;
    --gradient-start: #6B4EFF;
    --gradient-end: #9F8CFF;

    --surface: #FFFFFF;
    --background: #FAFBFF;
    --surface-variant: #F3F4F8;

    --text-main: #1A1A2E;
    --text-secondary: #6B7280;
    --border: #E5E7EB;

    --success: #34A853;
    --error: #EA4335;

    /* Spacing & Radius */
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 8px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
    --shadow-paper: 0 2px 8px rgba(0, 0, 0, 0.1), 0 8px 32px rgba(0, 0, 0, 0.1);

    /* Transitions */
    --ease-elastic: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --ease-standard: cubic-bezier(0.4, 0.0, 0.2, 1);
}

[data-theme="dark"] {
    --primary: #8E7BFF;
    --primary-dark: #7A66F0;
    --primary-light: #2D235C;
    --surface: #1E1E2E;
    --background: #111118;
    --surface-variant: #2A2A3C;
    --text-main: #E8E8F0;
    --text-secondary: #9CA3AF;
    --border: #3A3A4C;
    --gradient-start: #6B4EFF;
    --gradient-end: #9F8CFF;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--background);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

/* --- Layout --- */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* --- Left Pane: Editor --- */
.editor-pane {
    width: 600px;
    min-width: 600px;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    z-index: 10;
    box-shadow: var(--shadow-sm);
    position: relative;
    transition: background-color 0.3s;
}

.brand-header {
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 700;
}

.logo-icon {
    background: var(--primary-light);
    color: var(--primary);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 1rem;
}

.logo-text span {
    color: var(--primary);
}

.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
}

.theme-toggle:hover {
    background: var(--surface-variant);
    color: var(--primary);
}

[data-theme="light"] .moon-icon {
    display: block;
}

[data-theme="light"] .sun-icon {
    display: none;
}

[data-theme="dark"] .moon-icon {
    display: none;
}

[data-theme="dark"] .sun-icon {
    display: block;
}

/* Wizard Progress */
.wizard-progress {
    display: flex;
    gap: 0.5rem;
    padding: 0 2rem 2rem 2rem;
}

.step-dot {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--surface-variant);
    transition: all 0.3s var(--ease-standard);
}

.step-dot.active {
    background: var(--primary);
    width: 60px;
}

/* Wizard Content */
.wizard-content {
    flex: 1;
    overflow-y: auto;
    padding: 0 2rem 2rem 2rem;
    position: relative;
}

.wizard-step {
    display: none;
    flex-direction: column;
    animation: fadeIn 0.4s var(--ease-standard);
}

.wizard-step.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.step-title {
    font-size: 2rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
    background: linear-gradient(135deg, var(--text-main) 0%, var(--text-secondary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.step-subtitle {
    color: var(--text-secondary);
    margin: 0 0 2rem 0;
    font-size: 1rem;
}

/* Animations */
.animate-in {
    opacity: 0;
    transform: translateY(10px);
    animation: slideUp 0.5s var(--ease-standard) forwards;
}

.delay-1 {
    animation-delay: 0.1s;
}

.delay-2 {
    animation-delay: 0.2s;
}

.delay-3 {
    animation-delay: 0.3s;
}

@keyframes slideUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Form Elements */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.google-input {
    width: 100%;
    padding: 1rem 1.25rem;
    font-family: inherit;
    font-size: 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-main);
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.google-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
}

textarea.google-input {
    resize: vertical;
    min-height: 100px;
}

.google-select {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
    background: var(--surface);
    color: var(--text-main);
    font-family: inherit;
    cursor: pointer;
}

/* Logo Upload */
.logo-upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    background: var(--background);
}

.logo-upload-zone:hover {
    border-color: var(--primary);
    background: var(--surface-variant);
}

.upload-icon {
    font-size: 1.5rem;
}

.upload-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.logo-preview {
    max-width: 100px;
    max-height: 100px;
    border-radius: var(--radius-sm);
    margin-top: 0.5rem;
}

.remove-logo {
    position: absolute;
    top: 5px;
    right: 5px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 100px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: 1rem;
    transition: transform 0.1s var(--ease-standard), box-shadow 0.2s;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-icon {
    stroke-width: 2.5;
}

.btn-primary:hover {
    box-shadow: 0 4px 12px rgba(107, 78, 255, 0.4);
    transform: translateY(-2px);
    background: var(--primary-dark);
}

.btn-secondary {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary-light);
    padding: 0.75rem 1.5rem;
    border-radius: 100px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: 1rem;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--primary-light);
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
}

.btn-text:hover {
    color: var(--text-main);
    background: var(--surface-variant);
}

.wizard-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
    gap: 1rem;
}

/* Switch & Totals Config */
.totals-config {
    background: var(--background);
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-top: 1.5rem;
}

.switch-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.switch-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border);
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary);
}

input:checked+.slider:before {
    transform: translateX(16px);
}

.small {
    width: 60px;
    padding: 0.5rem;
    text-align: right;
}

.suffix {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-left: 0.5rem;
}

/* Line Items */
.line-item-header {
    display: grid;
    grid-template-columns: 3fr 80px 100px 30px;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.line-item-header span:nth-child(2),
.line-item-header span:nth-child(3) {
    text-align: center;
}

.line-item-row {
    display: grid;
    grid-template-columns: 3fr 80px 100px 30px;
    gap: 0.5rem;
    align-items: start;
    margin-bottom: 0.5rem;
    animation: fadeIn 0.3s;
}

.line-item-row input:nth-child(2),
.line-item-row input:nth-child(3) {
    text-align: center;
}

.remove-item {
    background: none;
    border: none;
    color: var(--error);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0;
    margin-top: 0.75rem;
    opacity: 0.5;
}

.remove-item:hover {
    opacity: 1;
}

.divider {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

/* --- Right Pane: Preview --- */
.preview-pane {
    flex: 1;
    background: var(--surface-variant);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 3rem;
    position: relative;
    overflow: hidden;
    transition: background-color 0.3s;
}

.invoice-paper {
    width: 100%;
    max-width: 794px;
    /* A4 Width in px (approx) */
    aspect-ratio: 1 / 1.414;
    /* A4 Ratio */
    background: white;
    /* Always white paper */
    color: black;
    /* Always black text on paper */
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-paper);
    padding: 4rem;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transform-origin: center;
    transition: transform 0.3s ease;
    overflow: hidden;
}

/* Paper Styles (Resetting variables for paper context) */
.paper-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 3rem;
}

.paper-logo {
    max-height: 80px;
    margin-bottom: 1rem;
}

.paper-from h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: #111;
}

.paper-from p {
    margin: 0.25rem 0;
    font-size: 0.9rem;
    color: #555;
    white-space: pre-line;
}

.paper-title {
    font-size: 2.5rem;
    font-weight: 800;
    color: #111;
    letter-spacing: -1px;
    margin: 0 0 1rem 0;
    text-transform: uppercase;
}

.meta-grid {
    display: grid;
    grid-template-columns: auto auto;
    gap: 0.5rem 1.5rem;
    text-align: right;
}

.meta-label {
    font-size: 0.75rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.meta-value {
    font-weight: 600;
    color: #111;
}

.paper-client {
    margin-bottom: 2rem;
}

.paper-client h3 {
    margin: 0.5rem 0 0.25rem 0;
    font-size: 1.1rem;
    color: #111;
}

.paper-client p {
    margin: 0;
    color: #555;
    font-size: 0.9rem;
}

.paper-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.paper-table th {
    text-align: left;
    padding: 0.75rem 0;
    color: #666;
    font-size: 0.75rem;
    border-bottom: 2px solid #eee;
    text-transform: uppercase;
    font-weight: 600;
}

.paper-table td {
    padding: 1rem 0;
    border-bottom: 1px solid #eee;
    font-size: 0.95rem;
    color: #222;
}

.col-qty,
.col-price,
.col-total {
    text-align: right;
}

.paper-totals {
    margin-top: auto;
    align-self: flex-end;
    width: 250px;
    padding-top: 1rem;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    font-weight: 500;
    font-size: 0.95rem;
    color: #444;
}

.grand-total {
    font-size: 1.25rem;
    font-weight: 700;
    color: #000;
    border-top: 2px solid #000;
    padding-top: 1rem;
    margin-top: 0.5rem;
}

.paper-notes {
    margin-top: 3rem;
    padding-top: 1rem;
    border-top: 1px solid #eee;
}

.paper-notes p {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: #555;
    white-space: pre-line;
}

.paper-footer {
    margin-top: 2rem;
    text-align: center;
    color: #aaa;
    font-size: 0.75rem;
}

/* Floating Action Bar */
.fab-bar {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 1rem;
    background: var(--surface);
    padding: 0.5rem;
    border-radius: 100px;
    box-shadow: var(--shadow-lg);
    z-index: 20;
    transition: all 0.3s;
}

.fab-btn {
    height: 48px;
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: background 0.2s;
    padding: 0 1rem;
    color: var(--text-main);
    font-weight: 500;
    gap: 0.5rem;
}

.fab-btn:hover {
    background: var(--surface-variant);
}

.fab-btn.primary {
    background: var(--primary);
    color: white;
    padding: 0 1.5rem;
}

.fab-btn.primary:hover {
    background: var(--primary-dark);
}

.app-footer {
    margin-top: auto;
    padding-top: 2rem;
    display: flex;
    gap: 1rem;
    font-size: 0.875rem;
}

.app-footer a {
    color: var(--text-secondary);
    text-decoration: none;
}

.app-footer a:hover {
    text-decoration: underline;
}

.trust-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.hidden {
    display: none !important;
}

.clear-form-link {
    color: var(--error) !important;
    font-weight: 500;
}

/* Responsive */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
        overflow: auto;
    }

    .editor-pane {
        width: 100%;
        min-width: auto;
        border-right: none;
        height: auto;
    }

    .preview-pane {
        padding: 1rem;
        overflow: visible;
        min-height: 500px;
    }

    .invoice-paper {
        transform: scale(1);
        max-width: 100%;
        padding: 2rem;
    }

    .fab-bar {
        position: fixed;
        bottom: 1rem;
    }

    body {
        overflow: auto;
    }
}