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

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --light-bg: #f8fafc;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --white: #ffffff;
    --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    --shadow-lg: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
    --border-radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--light-bg);
    margin: 0;
    padding: 0;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.5rem 2rem;
    box-shadow: var(--shadow-lg);
    margin-bottom: 2rem;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

.header-nav {
    display: flex;
    gap: 1rem;
}

.nav-link {
    color: white;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    font-weight: 600;
    font-size: 0.95rem;
    transition: background 0.3s;
    cursor: pointer;
}

.nav-link:hover, .nav-link.active {
    background: rgba(255,255,255,0.2);
}

.main-header {
    text-align: center;
}

.profile-page-header {
    text-align: center;
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem 2rem;
}

/* Search Section */
.search-section {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.search-box {
    position: relative;
    margin-bottom: 1rem;
}

.search-box input {
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: border-color 0.3s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.search-button {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.3s;
}

.search-button:hover {
    background: var(--primary-hover);
}

.filters {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.filter-group {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-weight: 600;
    color: var(--text-secondary);
}

.filter-group input,
.filter-group select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
}

/* Results Section */
.results-section {
    margin-bottom: 2rem;
}

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

.results-header h2 {
    font-size: 1.8rem;
    color: var(--text-primary);
}

.sort-options {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sort-options label {
    color: var(--text-secondary);
    font-weight: 600;
}

.sort-options select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
}

.ai-sort-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    white-space: nowrap;
}

.ai-sort-btn:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
}

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

.ai-sort-progress {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--light-bg);
    border-radius: var(--border-radius);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.ai-sort-progress.hidden {
    display: none;
}

.ai-score-reason {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0.25rem 0 0.5rem 0;
    font-style: italic;
}

.opportunities-list {
    display: grid;
    grid-gap: 1.5rem;
}

.opportunity-card {
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow);
}

.opportunity-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.opportunity-card h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
    cursor: pointer;
    transition: color 0.2s;
}

.opportunity-card h3:hover {
    color: var(--primary-hover);
}

.opportunity-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.meta-item i {
    color: var(--secondary-color);
}

.opportunity-description {
    color: var(--text-primary);
    margin-bottom: 1rem;
    line-height: 1.6;
}

.opportunity-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-start;
}

.opportunity-description-full {
    background: var(--light-bg);
    padding: 1rem 1.25rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    max-height: 300px;
    overflow-y: auto;
}

.opportunity-description-full h4 {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.opportunity-description-full #opportunity-description-text {
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.apply-button {
    display: none;
    background: var(--success-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background 0.3s;
}
.apply-button:hover {
    background: #059669;
}

/* View Details - primary action */

/* AI Autofill Button */
.ai-autofill-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 1rem 1.5rem;
    margin-bottom: 0.75rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.02em;
}
.ai-autofill-btn:hover:not(:disabled) {
    opacity: 0.95;
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}
.ai-autofill-btn:active:not(:disabled) {
    transform: translateY(0);
}

/* Spinner inside button */
.ai-autofill-btn .spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Generating state */
.ai-autofill-btn.generating {
    opacity: 0.85;
    cursor: wait;
    border: 2px solid rgba(255,255,255,0.2);
}

/* Disabled but not generating (error state) */
.ai-autofill-btn:disabled:not(.generating) {
    opacity: 0.5;
    cursor: not-allowed;
}

/* AI Autofill Status */
.ai-autofill-status {
    display: none;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.5;
}
.ai-autofill-status.info {
    background: linear-gradient(135deg, #eef2ff, #e0e7ff);
    color: #3730a3;
    border: 2px solid #a5b4fc;
}
.ai-autofill-status.success {
    background: linear-gradient(135deg, #ecfdf5, #d1fae5);
    color: #065f46;
    border: 2px solid #6ee7b7;
}
.ai-autofill-status.warning {
    background: linear-gradient(135deg, #fffbeb, #fef3c7);
    color: #92400e;
    border: 2px solid #fcd34d;
}
.ai-autofill-status.error {
    background: linear-gradient(135deg, #fef2f2, #fee2e2);
    color: #991b1b;
    border: 2px solid #fca5a5;
}

.view-details {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 1000;
    overflow-y: auto;
    padding: 1rem;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--white);
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    position: relative;
}

.modal-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.close-modal {
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    transition: background 0.3s;
}

.close-modal:hover {
    background: rgba(255,255,255,0.4);
}

.modal-body {
    padding: 1.5rem;
}

.opportunity-details {
    background: var(--light-bg);
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
}

.opportunity-details h3 {
    margin-bottom: 0.75rem;
    font-size: 1.3rem;
    color: var(--primary-color);
}

.detail-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.detail-label {
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 140px;
}

.detail-value {
    color: var(--text-primary);
}

/* Application Form */
.application-form {
    display: block;
}

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.form-group input,
.form-group textarea,
.form-group select {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.3s;
}

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

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

.form-group input[type="number"] {
    -moz-appearance: textfield;
}

.form-group input[type="number"]::-webkit-inner-spin-button,
.form-group input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.form-submit-btn,
.generate-button {
    background: var(--success-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background 0.3s, transform 0.1s;
}

.form-submit-btn:hover,
.generate-button:hover {
    background: #059669;
}

.form-submit-btn:active,
.generate-button:active {
    transform: scale(0.98);
}

/* Buttons */
.cancel-button {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background 0.3s, opacity 0.3s;
}

.cancel-button:hover {
    opacity: 0.9;
}

.save-profile-button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background 0.3s;
}

.save-profile-button:hover {
    background: var(--primary-hover);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-start;
    flex-wrap: wrap;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* AI Generate trigger inline */
.ai-generate-trigger-inline {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 0.65rem 1.2rem;
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}

.ai-generate-trigger-inline:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Profile page */
.profile-container {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.profile-header {
    text-align: center;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 1rem;
}

.profile-header h2 {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.profile-message {
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    font-weight: 600;
    display: none;
}

.profile-message.success {
    display: block;
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.print-page-button {
    background: var(--text-secondary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 600;
    transition: opacity 0.3s;
}

.print-page-button:hover {
    opacity: 0.9;
}

/* Profile Form */
.profile-form {
    display: block;
}

.profile-form fieldset {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    background: #fafbfc;
}

.profile-form fieldset legend {
    font-weight: 700;
    color: var(--primary-color);
    padding: 0 0.5rem;
}

/* Pagination */
.pagination {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.pagination button,
.pagination .page-num {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    background: var(--white);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination .page-num.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Application preview */
.application-preview {
    display: block;
}

.application-content {
    line-height: 1.8;
    font-size: 1rem;
    color: var(--text-primary);
}

.application-preview h2 { margin: 0.5rem 0 1rem; }
.application-preview h3 { margin: 1.4rem 0 0.5rem; color: var(--primary-color); }
.application-preview h4 { margin: 1rem 0 0.5rem; }
.application-preview p { margin-bottom: 1rem; }
.application-preview ul, .application-preview ol { margin: 0.5rem 0 1rem 1.5rem; }
.application-preview li { margin-bottom: 0.5rem; }
.application-preview code { background: #f1f5f9; padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.9em; }
.application-preview pre { background: #f1f5f9; padding: 1rem; border-radius: var(--border-radius); overflow-x: auto; }

.download-pdf {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.65rem 1.2rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 600;
}

.download-pdf:hover { opacity: 0.9; }

.edit-application {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.65rem 1.2rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 600;
}

.edit-application:hover { opacity: 0.9; }

/* Loading / spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(37,99,235,0.3);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Utility */
.hidden { display: none !important; }

/* Print styles */
@media print {
    header, .opportunity-actions, .modal-body, .pagination { display: none !important; }
    body { background: white; }
    .opportunity-card { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
}
