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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 800px;
    margin: 5px auto;
    background: white;
    border-radius: 12px;
    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: 12px 20px;
    text-align: center;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content {
    flex: 1;
    text-align: center;
}

.btn-back {
    background: rgba(255,255,255,0.2);
    color: white;
    border: 2px solid white;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: all 0.3s;
    text-decoration: none;
}

.btn-back:hover {
    background: rgba(255,255,255,0.3);
}

.header h1 {
    font-size: 18px;
    margin-bottom: 3px;
}

.header p {
    font-size: 12px;
    opacity: 0.9;
}

.form-container {
    padding: 15px 20px;
}

.section {
    margin-bottom: 18px;
}

.section:last-of-type {
    margin-bottom: 8px;
}

.section-title {
    font-size: 15px;
    color: #667eea;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 2px solid #667eea;
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-group {
    margin-bottom: 12px;
}

label {
    display: block;
    margin-bottom: 4px;
    color: #333;
    font-weight: 500;
    font-size: 12px;
}

input, select {
    width: 100%;
    padding: 8px 10px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 13px;
    transition: all 0.3s;
}

input:focus, select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.btn-generate {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 5px;
}

.btn-generate:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
}

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

.btn-generate:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.loading {
    display: none;
    text-align: center;
    padding: 12px;
    color: #667eea;
    font-weight: 600;
    font-size: 13px;
}

.success {
    display: none;
    text-align: center;
    padding: 12px;
    background: #d4edda;
    color: #155724;
    border-radius: 6px;
    margin-top: 12px;
    font-weight: 600;
    font-size: 13px;
}

.error {
    display: none;
    text-align: center;
    padding: 12px;
    background: #f8d7da;
    color: #721c24;
    border-radius: 6px;
    margin-top: 12px;
    font-weight: 600;
    font-size: 13px;
}

#loadingLibraries {
    text-align: center;
    padding: 20px;
    color: #667eea;
    font-size: 14px;
}

@media (max-width: 768px) {
    .row {
        grid-template-columns: 1fr;
    }

    .form-container {
        padding: 20px;
    }
}

/* Template selector */
.template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.template-card { background: #f8f9fa; border: 2px solid #e0e0e0; border-radius: 8px; padding: 10px; cursor: pointer; text-align: center; transition: all 0.3s; font-size: 12px; }
.template-card:hover { border-color: #667eea; background: #f0f0ff; }
.template-card.active { border-color: #667eea; background: linear-gradient(135deg, rgba(102,126,234,0.1), rgba(118,75,162,0.1)); }
.template-card .template-icon { font-size: 24px; display: block; margin-bottom: 4px; }
.template-card .template-name { font-weight: 600; color: #333; font-size: 11px; }
.b2b-fields { display: none; margin-top: 12px; }
.b2b-fields.visible { display: block; }
.loan-select-box { background: #e7f3ff; padding: 10px; border-radius: 6px; margin-bottom: 12px; font-size: 12px; }

/* Contract preview modal */
.contract-modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 9999; overflow-y: auto; }
.contract-modal-overlay.active { display: block; }
.contract-modal { max-width: 800px; margin: 20px auto; background: white; border-radius: 12px; overflow: hidden; }
.contract-modal-header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 12px 20px; display: flex; justify-content: space-between; align-items: center; }
.contract-modal-header h3 { font-size: 15px; }
.contract-modal-body { padding: 30px 40px; font-family: 'Times New Roman', serif; font-size: 14px; line-height: 1.6; color: #333; }
.contract-modal-actions { padding: 15px 20px; border-top: 1px solid #e0e0e0; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.contract-modal-actions button { padding: 10px 20px; border: none; border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 13px; }
.btn-print { background: #667eea; color: white; }
.btn-close-modal { background: #6c757d; color: white; }
.btn-save-contract { background: #28a745; color: white; }
@media print {
    body * { visibility: hidden; }
    .contract-modal-overlay, .contract-modal, .contract-modal-body, .contract-modal-body * { visibility: visible; }
    .contract-modal { position: absolute; left: 0; top: 0; margin: 0; border-radius: 0; box-shadow: none; }
    .contract-modal-header, .contract-modal-actions { display: none !important; }
    .contract-modal-body { padding: 20px 40px; }
}

/* Dark Mode */
body.dark-mode { background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); }
body.dark-mode .container { background: #0f0f23; color: #e0e0e0; }
body.dark-mode .header { }
body.dark-mode .content { color: #e0e0e0; }
body.dark-mode input, body.dark-mode select, body.dark-mode textarea { background: #16213e; color: #e0e0e0; border-color: #333; }
body.dark-mode .card-item, body.dark-mode .summary-card { border-color: #333; }
body.dark-mode .template-card { background: #1a1a2e; border-color: #333; }
body.dark-mode .template-card .template-name { color: #e0e0e0; }
body.dark-mode .loan-select-box { background: #16213e; color: #9fa8da; }

