:root {
    --bg-primary: #f8f9fb;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f3f5;
    --text-primary: #1a1d21;
    --text-secondary: #5c6370;
    --text-muted: #8b919a;
    --accent: #1e3a5f;
    --accent-light: #2a4a73;
    --accent-glow: rgba(30, 58, 95, 0.15);
    --border: #e1e4e8;
    --border-focus: #1e3a5f;
    --success: #22c55e;
    --danger: #ef4444;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

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

body {
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: 1400px;
    margin: 0 auto;
}

.brand-icon {
    font-size: 2rem;
    animation: gentle-bounce 2s ease-in-out infinite;
}

@keyframes gentle-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.tagline {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 400;
}

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

.form-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    animation: fadeSlideIn 0.3s ease-out;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.input-group {
    margin-bottom: 1rem;
}

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

.input-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.required-star {
    color: var(--danger);
}

.input-field {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9rem;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.input-field:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-field::placeholder {
    color: var(--text-muted);
}

.input-field.textarea {
    resize: vertical;
    min-height: 60px;
}

.input-field.select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235c6370' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.input-with-prefix {
    display: flex;
    align-items: stretch;
}

.input-prefix {
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-right: none;
    border-radius: var(--radius-md) 0 0 var(--radius-md);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.input-field.with-prefix {
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.details-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.line-items-header {
    display: grid;
    grid-template-columns: 1fr 100px 80px 100px 32px;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.line-items-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.line-item-row {
    display: grid;
    grid-template-columns: 1fr 100px 80px 100px 32px;
    gap: 0.75rem;
    align-items: center;
    animation: fadeSlideIn 0.2s ease-out;
}

.line-item-total {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: right;
}

.remove-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.remove-btn:hover:not(:disabled) {
    background: var(--danger);
    color: white;
}

.remove-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.add-item-btn {
    width: 100%;
    padding: 0.75rem;
    margin-top: 0.75rem;
    border: 2px dashed var(--border);
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.add-item-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

.totals-section {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.tax-input {
    flex: 0 0 120px;
}

.calculated-totals {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.calc-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.calc-value {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 500;
}

.calc-row.grand {
    padding-top: 0.75rem;
    border-top: 2px solid var(--accent);
    margin-top: 0.5rem;
}

.calc-row.grand span:first-child {
    font-weight: 600;
    color: var(--text-primary);
}

.grand-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}

.form-actions {
    display: flex;
    gap: 1rem;
}

.btn {
    flex: 1;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: var(--shadow-md);
}

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

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
    color: var(--text-primary);
}

.btn-icon {
    font-size: 1.1rem;
}

/* Preview Panel */
.preview-panel {
    position: sticky;
    top: 5rem;
    height: fit-content;
}

.preview-title-bar {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.preview-wrapper {
    background: #e8e8e8;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.invoice-preview {
    background: white;
    padding: 2rem;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    font-size: 0.85rem;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 3px solid var(--accent);
}

.preview-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.1em;
}

.invoice-num {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.preview-dates {
    text-align: right;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.preview-dates p {
    margin-bottom: 0.25rem;
}

.due-date {
    font-weight: 600;
    color: var(--text-primary);
}

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

.party-block h3 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.party-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.party-address {
    white-space: pre-line;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.preview-items {
    margin-bottom: 1.5rem;
}

.items-header {
    display: grid;
    grid-template-columns: 1fr 80px 50px 80px;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.items-row {
    display: grid;
    grid-template-columns: 1fr 80px 50px 80px;
    gap: 0.5rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--bg-tertiary);
    font-size: 0.8rem;
}

.col-rate,
.col-qty,
.col-total {
    text-align: right;
    font-family: 'IBM Plex Mono', monospace;
}

.preview-totals {
    margin-left: auto;
    width: 200px;
    margin-bottom: 1.5rem;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.totals-row span:last-child {
    font-family: 'IBM Plex Mono', monospace;
}

.totals-row.grand-total {
    border-top: 2px solid var(--accent);
    margin-top: 0.5rem;
    padding-top: 0.75rem;
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent);
}

.preview-notes {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.5rem;
}

.preview-notes h4 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.preview-notes p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: pre-line;
}

.preview-footer {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    margin-top: auto;
}

.app-footer a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    transition: color 0.2s ease;
}

.app-footer a:hover {
    color: var(--accent);
}

/* Toast */
.toast-notification {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--text-primary);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: slideInUp 0.3s ease-out;
    z-index: 1000;
}

.toast-icon {
    width: 24px;
    height: 24px;
    background: var(--success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        padding: 1.5rem;
    }

    .preview-panel {
        position: relative;
        top: 0;
    }

    .details-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .main-content {
        padding: 1rem;
        gap: 1rem;
    }

    .form-section {
        padding: 1rem;
    }

    .line-items-header,
    .line-item-row {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .line-items-header {
        display: none;
    }

    .line-item-row {
        background: var(--bg-tertiary);
        padding: 1rem;
        border-radius: var(--radius-md);
        position: relative;
    }

    .line-item-desc {
        grid-column: 1 / -1;
    }

    .line-item-rate,
    .line-item-qty,
    .line-item-total {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .line-item-rate::before {
        content: 'Rate:';
        font-size: 0.75rem;
        color: var(--text-muted);
    }

    .line-item-qty::before {
        content: 'Qty:';
        font-size: 0.75rem;
        color: var(--text-muted);
    }

    .line-item-total::before {
        content: 'Total:';
        font-size: 0.75rem;
        color: var(--text-muted);
    }

    .remove-btn {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
    }

    .totals-section {
        flex-direction: column;
        gap: 1rem;
    }

    .tax-input {
        flex: none;
        width: 100%;
    }

    .form-actions {
        flex-direction: column;
    }

    .preview-wrapper {
        padding: 0.75rem;
    }

    .invoice-preview {
        padding: 1rem;
        font-size: 0.75rem;
    }

    .preview-header h1 {
        font-size: 1.25rem;
    }

    .preview-parties {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .items-header,
    .items-row {
        grid-template-columns: 1fr 60px 40px 60px;
        font-size: 0.7rem;
    }

    .preview-totals {
        width: 100%;
    }

    .toast-notification {
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
    }
}