/* CSS Reset and Variables */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Screens */
.screen {
    display: none;
}

.screen.active {
    display: block;
}

/* Auth Screen */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    background: var(--surface);
    padding: 40px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.auth-card h1 {
    color: var(--primary-color);
    margin-bottom: 8px;
    font-size: 2rem;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.error-message {
    background: #fef2f2;
    color: var(--danger-color);
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 16px;
    display: none;
}

.error-message.show {
    display: block;
}

/* Forms */
.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text-primary);
}

.input-group input,
.input-group textarea,
.input-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.input-group input:focus,
.input-group textarea:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Buttons */
.btn-primary,
.btn-secondary {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--background);
}

.text-link {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 14px;
}

.text-link:hover {
    text-decoration: underline;
}

/* Navigation */
.nav-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
}

.nav-brand h2 {
    color: var(--primary-color);
    font-size: 1.5rem;
}

.nav-links {
    display: flex;
    gap: 24px;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.2s;
}

.nav-link:hover,
.nav-link.active {
    color: var(--primary-color);
    background: var(--background);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

#user-display {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Search Container */
.search-container {
    background: var(--surface);
    padding: 24px 32px;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 12px;
}

.search-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Views */
.view {
    display: none;
    padding: 32px;
    max-width: 1400px;
    margin: 0 auto;
}

.view.active {
    display: block;
}

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.view-header h2 {
    font-size: 1.875rem;
}

.view-actions {
    display: flex;
    gap: 12px;
}

.view-description {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--surface);
    padding: 24px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-card h3 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 8px;
}

.stat-card p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Lists */
.recent-opportunities,
.opportunities-list,
.workspaces-list,
.contexts-list,
.states-list {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 24px;
}

.recent-opportunities h3 {
    margin-bottom: 20px;
}

.opportunity-card,
.workspace-card,
.context-card,
.state-card {
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 16px;
    transition: all 0.2s;
    cursor: pointer;
}

.opportunity-card:hover,
.workspace-card:hover,
.context-card:hover,
.state-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 12px;
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.card-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.card-actions {
    display: flex;
    gap: 8px;
}

.card-btn {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.score-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.score-high {
    background: #d1fae5;
    color: #065f46;
}

.score-medium {
    background: #fef3c7;
    color: #92400e;
}

.score-low {
    background: #fee2e2;
    color: #991b1b;
}

.score-unscored {
    background: var(--background);
    color: var(--text-secondary);
}

/* Filters */
.filters-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    padding: 20px;
    background: var(--surface);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.filter-select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
}

/* US Map */
.us-map-container {
    background: var(--surface);
    padding: 32px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 32px;
    overflow: auto;
}

#us-map {
    width: 100%;
    height: auto;
}

.state-path {
    fill: var(--border);
    stroke: var(--surface);
    stroke-width: 1;
    cursor: pointer;
    transition: fill 0.2s;
}

.state-path:hover {
    fill: var(--primary-color);
}

.state-path.has-portal {
    fill: var(--success-color);
}

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1100;
}

.modal-overlay.active {
    display: block;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1101;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    padding: 20px;
}

.modal.active {
    display: flex;
}

#prompt-modal .modal-content {
    max-width: 480px;
}

#prompt-modal .modal-actions {
    justify-content: flex-end;
}

.modal-content {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 90vw;
    max-width: 600px;
}

.modal-content.large {
    max-width: 1200px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal form {
    padding: 24px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* Toasts */
#toast-container {
    pointer-events: none;
}
.fg-toast {
    pointer-events: auto;
}

/* Workspace */
.workspace-container {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 24px;
    padding: 24px;
    min-height: 500px;
}

.workspace-sidebar {
    border-right: 1px solid var(--border);
    padding-right: 24px;
}

.workspace-sidebar h4 {
    margin: 20px 0 12px 0;
    color: var(--text-primary);
}

.full-width {
    width: 100%;
    margin-bottom: 8px;
}

.workspace-editor {
    display: flex;
    flex-direction: column;
}

.editor-toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px;
    background: var(--background);
    border-radius: 6px;
}

.toolbar-select {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
}

.workspace-layout {
    display: flex;
    gap: 16px;
}

.workspace-textarea {
    flex: 1;
}

.workspace-sidepanels {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 340px;
}

.workspace-ai-panel,
.workspace-chat-panel {
    background: #0f0f1a;
    border: 1px solid #1f1f2e;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.workspace-chat-panel {
    min-height: 280px;
}

.workspace-ai-panel .panel-header,
.workspace-chat-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #1f1f2e;
    font-weight: 600;
}

.panel-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
}

.chat-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-message {
    display: flex;
    gap: 12px;
    background: #111124;
    border-radius: 8px;
    padding: 12px 14px;
    border: 1px solid #1f1f2e;
}

.chat-message .chat-meta {
    font-size: 12px;
    color: #9ca3af;
    margin-bottom: 6px;
}

.chat-message .chat-text {
    font-size: 14px;
    line-height: 1.5;
    color: #e5e7eb;
}

.chat-footer {
    padding: 12px 16px;
    border-top: 1px solid #1f1f2e;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-footer textarea {
    width: 100%;
    border-radius: 6px;
    border: 1px solid #1f1f2e;
    padding: 10px 12px;
    background: #050510;
    color: #e0e7ff;
    resize: vertical;
}

.chat-actions {
    display: flex;
    justify-content: flex-end;
}

.chat-grant-list {
    background: #0f0f1a;
    border: 1px solid #1f1f2e;
    border-radius: 8px;
    padding: 12px;
    max-height: 200px;
    overflow-y: auto;
}

.chat-grant-item {
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #e5e7eb;
}

.chat-grant-item:hover {
    background: #1b1b35;
}

#master-chat-modal .workspace-layout {
    flex-direction: row;
}

.workspace-ai-panel .panel-footer {
    padding: 12px 16px;
    border-top: 1px solid #1f1f2e;
}

.icon-button {
    background: none;
    border: none;
    color: #a5b4fc;
    cursor: pointer;
    font-size: 14px;
}

.icon-button:hover {
    color: #c7d2fe;
}

.user-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #4f46e5;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    margin-left: 8px;
}

.workspace-actions {
    margin-top: 16px;
    display: flex;
    justify-content: flex-end;
}

.workspace-meta {
    margin-top: 12px;
    font-size: 13px;
    color: #a5b4fc;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-warning {
    background: #3f1d1d;
    color: #fca5a5;
    border: 1px solid #f87171;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
}

.ai-meta {
    margin-top: 12px;
    font-size: 12px;
    color: #9ca3af;
}

.context-option {
    border: 1px solid #1f1f2e;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 10px;
    background: #0f0f1a;
}

.context-option label {
    display: flex;
    gap: 12px;
    cursor: pointer;
}

.context-option input {
    margin-top: 4px;
}

.modal .user-badge {
    margin-left: 0;
}

.selected-context {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border: 1px solid #1f1f2e;
    border-radius: 6px;
    background: #0f0f1a;
    margin-bottom: 8px;
    gap: 10px;
}

/* Utility Classes */
.mb-2 {
    margin-bottom: 8px;
}

.mb-4 {
    margin-bottom: 16px;
}

.text-sm {
    font-size: 14px;
}

.text-secondary {
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
    .nav-bar {
        flex-direction: column;
        gap: 16px;
    }
    
    .nav-links {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .workspace-container {
        grid-template-columns: 1fr;
    }
    
    .workspace-sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding-right: 0;
        padding-bottom: 24px;
    }
    
    .filters-bar {
        flex-wrap: wrap;
    }

    .workspace-ai-panel {
        order: -1;
    }
}

@media (max-width: 1024px) {
    .workspace-layout {
        flex-direction: column;
    }

    .workspace-sidepanels {
        width: 100%;
    }

    .workspace-chat-panel,
    .workspace-ai-panel {
        min-height: 220px;
    }

    #master-chat-modal .workspace-layout {
        flex-direction: column;
    }
}
