@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
    --color-bg: #f8f9fc;
    --color-surface: #ffffff;
    --color-surface-2: #f1f3f9;
    --color-primary: #5b7cff;
    --color-primary-dark: #4a63cc;
    --color-accent: #6366f1;
    --color-accent-2: #8b5cf6;
    --color-success: #10b981;
    --color-text: #1e293b;
    --color-text-dim: #64748b;
    --color-border: #e2e8f0;
    
    --font-main: 'Space Grotesk', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: var(--font-main);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    padding: 20px;
    position: relative;
    overflow-x: hidden;
}

/* Grain effect - subtle */
.grain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.015;
    z-index: 100;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent-2) 100%);
    border-radius: 24px;
    padding: 60px 40px;
    margin-bottom: 40px;
    position: relative;
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
}

.header:hover {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

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

.title {
    font-size: 4rem;
    font-weight: 700;
    line-height: 0.9;
    letter-spacing: -0.03em;
    color: white;
}

.header-badge {
    background: white;
    color: var(--color-primary);
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    border-radius: 20px;
    font-family: var(--font-mono);
    box-shadow: var(--shadow-md);
}

.subtitle {
    font-size: 1.2rem;
    color: rgba(255, 255, 255, 0.9);
    font-family: var(--font-mono);
    letter-spacing: 0.05em;
}

/* Form Wrapper */
.form-wrapper {
    background: var(--color-surface);
    border-radius: 24px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
}

/* Quick Actions Panel */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
    padding: 25px;
    background: linear-gradient(135deg, #f0f9ff 0%, #f5f3ff 100%);
    border-radius: 16px;
    border: 2px solid var(--color-border);
}

.quick-action-card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    border: 2px solid var(--color-border);
    transition: all 0.3s ease;
}

.quick-action-card:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.quick-action-card h3 {
    font-size: 1rem;
    margin-bottom: 15px;
    color: var(--color-text);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.title-icon {
    width: 20px;
    height: 20px;
    color: var(--color-primary);
}

.btn-quick {
    width: 100%;
    padding: 12px 16px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-main);
}

.btn-quick svg {
    width: 18px;
    height: 18px;
}

.btn-quick:hover {
    background: var(--color-primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.quick-hint {
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--color-text-dim);
    text-align: center;
}

.quick-hint span {
    font-weight: 600;
    color: var(--color-primary);
    font-family: var(--font-mono);
}

.client-selector {
    margin-top: 12px;
}

.client-selector select {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface-2);
    font-size: 0.9rem;
    cursor: pointer;
}

/* Auto-save Status */
.auto-save-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    background: var(--color-surface-2);
    border-radius: 8px;
    margin-bottom: 10px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-success);
    animation: pulse 2s infinite;
}

.status-dot.saving {
    background: #f59e0b;
}

.status-dot.error {
    background: #ef4444;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

#autoSaveStatus {
    font-weight: 600;
    color: var(--color-text);
}

/* Client Database Modal */
.client-db-modal {
    max-width: 800px;
}

.client-db-container {
    padding: 40px;
}

.client-db-container h2 {
    margin-bottom: 25px;
    color: var(--color-text);
}

.client-db-actions {
    margin-bottom: 25px;
}

.add-client-form {
    background: var(--color-surface-2);
    padding: 25px;
    border-radius: 12px;
    margin-bottom: 25px;
    border: 2px solid var(--color-border);
}

.add-client-form h3 {
    margin-bottom: 20px;
    color: var(--color-text);
}

.form-actions {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

.client-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 400px;
    overflow-y: auto;
}

.client-item {
    background: white;
    padding: 20px;
    border-radius: 12px;
    border: 2px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

.client-item:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

.client-info h4 {
    margin-bottom: 5px;
    color: var(--color-text);
    font-size: 1.1rem;
}

.client-info p {
    font-size: 0.9rem;
    color: var(--color-text-dim);
    margin: 2px 0;
}

.client-actions {
    display: flex;
    gap: 10px;
}

.btn-client-action {
    padding: 8px 12px;
    border: 2px solid var(--color-border);
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.85rem;
    font-weight: 600;
}

.btn-client-action.use {
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.btn-client-action.use:hover {
    background: var(--color-primary);
    color: white;
}

.btn-client-action.delete {
    color: #ef4444;
    border-color: #fca5a5;
}

.btn-client-action.delete:hover {
    background: #ef4444;
    color: white;
}


/* Section */
.section {
    margin-bottom: 50px;
    padding-bottom: 40px;
    border-bottom: 2px solid var(--color-border);
}

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

.section-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
}

.section-icon {
    background: var(--color-primary);
    color: white;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.section-icon svg {
    width: 24px;
    height: 24px;
}

.section-header h2 {
    font-size: 2rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--color-text);
}

/* Form Grid */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
}

/* Input Group */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group.span-full {
    grid-column: 1 / -1;
}

.input-group label {
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--color-text);
}

.input-group input,
.input-group select,
.input-group textarea {
    background: var(--color-surface-2);
    border: 2px solid var(--color-border);
    border-radius: 12px;
    color: var(--color-text);
    padding: 14px 16px;
    font-size: 1rem;
    font-family: var(--font-main);
    transition: all 0.3s ease;
}

.input-group input:focus,
.input-group select:focus,
.input-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    background: var(--color-surface);
    box-shadow: 0 0 0 3px rgba(91, 124, 255, 0.1);
}

.input-group input[readonly] {
    background: var(--color-surface);
    color: var(--color-primary);
    font-weight: 600;
    border-color: var(--color-primary);
    cursor: not-allowed;
}

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

/* Items */
.items-wrapper {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.item-card {
    background: var(--color-surface-2);
    border: 2px solid var(--color-border);
    border-radius: 16px;
    padding: 25px;
    position: relative;
    transition: all 0.3s ease;
}

.item-card:hover {
    border-color: var(--color-primary);
    box-shadow: 0 4px 12px rgba(91, 124, 255, 0.1);
    transform: translateY(-2px);
}

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

.item-number {
    background: var(--color-primary);
    color: white;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-family: var(--font-mono);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

.item-remove {
    background: white;
    border: 2px solid var(--color-border);
    color: var(--color-text-dim);
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 400;
    border-radius: 10px;
}

.item-remove:hover {
    background: #fee;
    border-color: #fca5a5;
    color: #dc2626;
}

.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.btn-add-item {
    background: white;
    border: 2px dashed var(--color-border);
    color: var(--color-primary);
    padding: 20px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: var(--font-main);
    letter-spacing: 0.02em;
    margin-top: 20px;
    border-radius: 12px;
}

.btn-add-item:hover {
    background: var(--color-primary);
    color: white;
    border-style: solid;
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.btn-add-item span {
    font-size: 1.5rem;
    margin-right: 10px;
}

/* Summary */
.summary-section {
    margin: 40px 0;
}

.summary-card {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent-2) 100%);
    border-radius: 16px;
    padding: 30px;
    max-width: 500px;
    margin-left: auto;
    box-shadow: var(--shadow-lg);
    color: white;
}

.summary-card h3 {
    font-size: 1.5rem;
    margin-bottom: 25px;
    color: white;
    font-weight: 600;
}

.summary-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    font-size: 1.1rem;
}

.summary-row.total-row {
    border-top: 2px solid rgba(255, 255, 255, 0.3);
    margin-top: 10px;
    padding-top: 20px;
    font-size: 1.8rem;
}

.summary-row strong {
    font-family: var(--font-mono);
    font-weight: 700;
}

/* Actions */
.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 40px;
    padding-top: 40px;
    border-top: 2px solid var(--color-border);
}

.btn {
    padding: 18px 30px;
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-main);
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

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

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

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

.btn-secondary:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.btn-icon {
    width: 20px;
    height: 20px;
}

.btn svg {
    flex-shrink: 0;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    background: var(--color-surface);
    border-radius: 24px;
    margin: 3% auto;
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.modal-close {
    position: sticky;
    top: 20px;
    right: 20px;
    float: right;
    background: white;
    color: var(--color-text-dim);
    border: 2px solid var(--color-border);
    border-radius: 10px;
    width: 50px;
    height: 50px;
    font-size: 1.8rem;
    cursor: pointer;
    z-index: 10;
    transition: all 0.3s ease;
    font-weight: 400;
}

.modal-close:hover {
    background: #fee;
    border-color: #fca5a5;
    color: #dc2626;
}

#previewContainer {
    padding: 40px;
}

/* Invoice Preview */
.invoice-preview {
    background: white;
    color: #000;
    padding: 60px;
    font-family: Arial, sans-serif;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 3px solid #000;
}

.invoice-title {
    font-size: 3rem;
    font-weight: 700;
    font-family: var(--font-main);
}

.invoice-number {
    font-size: 1.2rem;
    color: #666;
    margin-top: 10px;
}

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

.party-box h3 {
    font-weight: 700;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.party-box p {
    line-height: 1.6;
    color: #333;
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin: 30px 0;
}

.invoice-table th {
    background: #000;
    color: #fff;
    padding: 12px;
    text-align: left;
    font-weight: 600;
}

.invoice-table td {
    padding: 12px;
    border-bottom: 1px solid #ddd;
}

.invoice-totals {
    margin-left: auto;
    width: 400px;
    border: 2px solid #000;
    padding: 20px;
}

.total-line {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    font-size: 1.1rem;
}

.total-line.final {
    border-top: 3px solid #000;
    margin-top: 10px;
    padding-top: 15px;
    font-weight: 700;
    font-size: 1.5rem;
}

/* Responsive */
@media (max-width: 768px) {
    .title {
        font-size: 2.5rem;
    }
    
    .header {
        padding: 40px 20px;
    }
    
    .header-badge {
        width: 60px;
        height: 60px;
        font-size: 1.5rem;
    }
    
    .form-wrapper {
        padding: 20px;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .item-grid {
        grid-template-columns: 1fr;
    }
    
    .actions-grid {
        grid-template-columns: 1fr;
    }
    
    .invoice-parties {
        grid-template-columns: 1fr;
    }
    
    .invoice-preview {
        padding: 30px 20px;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 12px;
}

::-webkit-scrollbar-track {
    background: var(--color-surface-2);
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary);
}

/* Footer */
.footer {
    margin-top: 60px;
    padding: 40px 0 20px 0;
    border-top: 2px solid var(--color-border);
}

.footer-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
}

.footer-text {
    color: var(--color-text-dim);
    font-size: 0.95rem;
    margin: 0;
}

.github-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--color-text);
    text-decoration: none;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 8px;
    background: var(--color-surface-2);
    transition: all 0.3s ease;
    border: 2px solid var(--color-border);
}

.github-link:hover {
    background: var(--color-text);
    color: white;
    border-color: var(--color-text);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.github-icon {
    width: 20px;
    height: 20px;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.footer-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--color-text-dim);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    padding: 6px 12px;
    border-radius: 6px;
}

.footer-link svg {
    width: 16px;
    height: 16px;
}

.footer-link:hover {
    color: var(--color-primary);
    background: var(--color-surface-2);
}

@media (max-width: 768px) {
    .footer-content {
        flex-direction: column;
        gap: 15px;
    }
    
    .footer-links {
        flex-direction: column;
        align-items: center;
    }
}