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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    text-align: center;
    color: white;
    margin-bottom: 40px;
    padding: 30px 0;
    position: relative;
}

header h1 {
    font-size: 3em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.subtitle {
    font-size: 1.2em;
    opacity: 0.9;
}

.logout-link {
    position: absolute;
    top: 30px;
    right: 0;
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border: 2px solid white;
    border-radius: 20px;
    font-size: 0.9em;
    transition: all 0.3s;
}

.logout-link:hover {
    background: white;
    color: #667eea;
}

.dashboard {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.card {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.card h2 {
    margin-bottom: 20px;
    color: #667eea;
    font-size: 1.8em;
}

.card h3 {
    margin: 20px 0 10px;
    color: #555;
    font-size: 1.3em;
}

#portfolio-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 25px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    padding: 15px;
    background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%);
    border-radius: 10px;
}

.stat-label {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 1.8em;
    font-weight: bold;
    color: #333;
}

.position-item {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    margin-bottom: 8px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.position-symbol {
    font-weight: bold;
    color: #667eea;
    font-size: 1.1em;
}

.position-name {
    font-weight: 600;
    color: #1f2937;
    font-size: 1em;
    margin-bottom: 2px;
}

.position-ticker {
    font-size: 0.85em;
    color: #6b7280;
}

.position-value {
    font-weight: 600;
    font-size: 1em;
    color: #1f2937;
}

.position-pnl {
    font-size: 0.85em;
}

.position-pnl.positive {
    color: #10b981;
}

.position-pnl.negative {
    color: #ef4444;
}

.portfolio-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.search-box {
    flex: 1;
    padding: 10px 15px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 1em;
    transition: border-color 0.3s;
}

.search-box:focus {
    outline: none;
    border-color: #667eea;
}

.sort-select {
    padding: 10px 15px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 1em;
    background: white;
    cursor: pointer;
    transition: border-color 0.3s;
}

.sort-select:focus {
    outline: none;
    border-color: #667eea;
}

.risk-score-container {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

.risk-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 150px;
    height: 150px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    box-shadow: 0 5px 15px rgba(16, 185, 129, 0.3);
}

.risk-score.medium {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    box-shadow: 0 5px 15px rgba(245, 158, 11, 0.3);
}

.risk-score.high {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 5px 15px rgba(239, 68, 68, 0.3);
}

.score-value {
    font-size: 3em;
    font-weight: bold;
}

.score-label {
    font-size: 0.9em;
}

.alert-item {
    padding: 12px;
    margin-bottom: 8px;
    background: #fef3c7;
    border-left: 4px solid #f59e0b;
    border-radius: 8px;
}

.alert-item.danger {
    background: #fef2f2;
    border-left-color: #ef4444;
}

.alert-item.success {
    background: #ecfdf5;
    border-left-color: #10b981;
}

.action-section {
    margin-bottom: 20px;
}

.investment-card {
    max-width: 800px;
    margin: 0 auto;
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.form-group input {
    width: 100%;
    padding: 12px;
    font-size: 1.1em;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    transition: border-color 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.btn {
    padding: 15px 30px;
    font-size: 1.1em;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-block;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: white;
    color: #667eea;
    border: 2px solid #667eea;
    margin: 0 5px;
}

.btn-secondary:hover {
    background: #667eea;
    color: white;
}

.loading {
    text-align: center;
    padding: 40px;
}

.spinner {
    border: 4px solid #f3f4f6;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.recommendation-item {
    padding: 15px;
    margin-bottom: 12px;
    background: #f0fdf4;
    border-left: 4px solid #10b981;
    border-radius: 8px;
}

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

.recommendation-symbol {
    font-weight: bold;
    font-size: 1.2em;
    color: #667eea;
}

.recommendation-action {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: 600;
}

.recommendation-action.buy {
    background: #10b981;
    color: white;
}

.recommendation-action.sell {
    background: #ef4444;
    color: white;
}

.recommendation-reasoning {
    color: #666;
    margin-top: 8px;
    font-size: 0.95em;
}

.trade-item {
    padding: 12px;
    margin-bottom: 8px;
    background: #dbeafe;
    border-left: 4px solid #3b82f6;
    border-radius: 8px;
}

.error-item {
    padding: 12px;
    margin-bottom: 8px;
    background: #fee2e2;
    border-left: 4px solid #ef4444;
    border-radius: 8px;
    color: #dc2626;
}

.controls {
    text-align: center;
    margin: 30px 0;
}

.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: white;
    padding: 30px;
    border-radius: 15px;
    max-width: 800px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.close {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 2em;
    font-weight: bold;
    color: #999;
    cursor: pointer;
}

.close:hover {
    color: #333;
}

.empty-state {
    color: #999;
    text-align: center;
    padding: 20px;
    font-style: italic;
}

footer {
    text-align: center;
    color: white;
    margin-top: 40px;
    padding: 20px;
    opacity: 0.9;
}

footer p {
    margin: 5px 0;
}

.error-container {
    max-width: 600px;
    margin: 100px auto;
    background: white;
    padding: 40px;
    border-radius: 15px;
    text-align: center;
}

.error-message {
    color: #ef4444;
    font-size: 1.2em;
    margin: 20px 0;
    padding: 20px;
    background: #fee2e2;
    border-radius: 8px;
}

.error-help {
    text-align: left;
    margin: 30px 0;
}

.error-help ul {
    list-style-position: inside;
    color: #666;
}

.error-help li {
    margin: 10px 0;
}

.error-help code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
}

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

    #portfolio-stats {
        grid-template-columns: 1fr;
    }

    header h1 {
        font-size: 2em;
    }

    .btn-secondary {
        margin: 5px;
        display: block;
    }

    .logout-link {
        position: static;
        display: block;
        margin-top: 15px;
    }
}

/* Market Analysis Styles */
.market-analysis {
    padding: 10px;
}

.analysis-section {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.analysis-section h3 {
    margin: 0 0 15px 0;
    color: #667eea;
    font-size: 1.3em;
}

.sentiment-badge {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 1.2em;
    margin-bottom: 15px;
}

.sentiment-badge.bullish {
    background: #10b981;
    color: white;
}

.sentiment-badge.bearish {
    background: #ef4444;
    color: white;
}

.sentiment-badge.neutral {
    background: #f59e0b;
    color: white;
}

.allocation-grid {
    display: grid;
    gap: 15px;
}

.allocation-item {
    background: white;
    padding: 15px;
    border-radius: 8px;
}

.allocation-bar {
    height: 30px;
    background: #e5e7eb;
    border-radius: 15px;
    overflow: hidden;
    margin-bottom: 10px;
}

.allocation-fill {
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    transition: width 0.5s;
}

.allocation-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.asset-name {
    font-weight: bold;
    color: #333;
}

.asset-percent {
    color: #667eea;
    font-weight: bold;
    font-size: 1.1em;
}

.sector-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
}

.sector-item {
    background: white;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.sector-item strong {
    display: block;
    margin-bottom: 8px;
    color: #667eea;
}

.sector-item p {
    margin: 0;
    color: #666;
    font-size: 0.95em;
}

.risk-factors {
    display: grid;
    gap: 12px;
}

.risk-factor-item {
    background: white;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #ef4444;
}

.risk-factor-item strong {
    display: block;
    color: #ef4444;
    margin-bottom: 5px;
}

.risk-factor-item span {
    color: #666;
}

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

.indicator-item {
    background: white;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.indicator-name {
    font-weight: bold;
    color: #667eea;
    font-size: 0.85em;
    margin-bottom: 8px;
}

.indicator-value {
    color: #333;
    font-size: 0.95em;
}

/* New Market Analysis Styles */
.analysis-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    margin-bottom: 20px;
}

.sentiment-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.confidence {
    font-size: 0.9em;
    color: #6b7280;
    font-weight: 500;
}

.health-badge {
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9em;
    text-transform: uppercase;
}

.health-badge.good,
.health-badge.healthy {
    background: #d1fae5;
    color: #065f46;
}

.health-badge.moderate,
.health-badge.fair {
    background: #fef3c7;
    color: #92400e;
}

.health-badge.poor,
.health-badge.at-risk {
    background: #fee2e2;
    color: #991b1b;
}

.summary-text {
    line-height: 1.7;
    color: #374151;
    font-size: 1em;
}

.outlook-section {
    border-left: 4px solid #667eea;
    background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 100%);
}

.outlook-section p {
    line-height: 1.6;
    color: #1f2937;
}

/* Recommended Actions */
.actions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.action-item {
    background: white;
    padding: 16px;
    border-radius: 10px;
    border-left: 4px solid #667eea;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.action-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.action-ticker {
    font-weight: 700;
    font-size: 1.1em;
    color: #1f2937;
}

.action-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 600;
    color: white;
}

.action-priority {
    font-size: 0.9em;
}

.action-reason {
    color: #6b7280;
    margin: 0;
    font-size: 0.95em;
    line-height: 1.5;
}

/* Diversification */
.diversification-bar {
    height: 12px;
    background: #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
    margin: 15px 0;
}

.diversification-fill {
    height: 100%;
    border-radius: 6px;
    transition: width 0.5s ease;
}

.suggestions-list {
    margin-top: 15px;
    padding-left: 20px;
}

.suggestions-list li {
    margin: 8px 0;
    color: #4b5563;
}

/* Sector Exposure */
.sector-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.sector-item {
    background: white;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

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

.sector-name {
    font-weight: 600;
    color: #1f2937;
}

.sector-pct {
    font-weight: 700;
    color: #667eea;
    font-size: 1.1em;
}

.sector-bar {
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.sector-fill {
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.sector-rec {
    color: #6b7280;
    font-size: 0.9em;
    margin: 0;
}

/* Market Trends */
.trends-list {
    padding-left: 20px;
}

.trends-list li {
    margin: 10px 0;
    color: #374151;
    line-height: 1.5;
}

/* Risk and Opportunity Grid */
.risk-opp-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.risks-section {
    border-left: 4px solid #ef4444;
    background: #fef2f2;
}

.risks-section h3 {
    color: #dc2626;
}

.risks-section ul {
    padding-left: 20px;
}

.risks-section li {
    margin: 8px 0;
    color: #7f1d1d;
}

.opps-section {
    border-left: 4px solid #10b981;
    background: #ecfdf5;
}

.opps-section h3 {
    color: #059669;
}

.opps-section ul {
    padding-left: 20px;
}

.opps-section li {
    margin: 8px 0;
    color: #064e3b;
}

/* Chatbot Styles */
.chatbot-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

.chatbot-toggle {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 16px 24px;
    border-radius: 50px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chatbot-toggle::before {
    content: "💬";
    font-size: 1.2em;
}

.chatbot-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.chatbot-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    height: 550px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chatbot-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 18px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chatbot-header h3 {
    margin: 0;
    font-size: 1.1em;
    color: white;
    font-weight: 600;
}

.chatbot-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 1.3em;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.chatbot-close:hover {
    background: rgba(255,255,255,0.3);
}

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f9fafb;
}

.chatbot-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
    animation: slideIn 0.3s ease-out;
    line-height: 1.5;
}

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

.bot-message {
    align-self: flex-start;
    background: white;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
    color: #374151;
}

.user-message {
    align-self: flex-end;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Message content styles for parsed markdown */
.message-content {
    font-size: 0.95em;
}

.message-content strong {
    font-weight: 600;
}

.message-content em {
    font-style: italic;
}

.message-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 4px 0;
}

.message-content br + br {
    display: none;
}

.chatbot-message p {
    margin: 0;
    line-height: 1.5;
}

.chatbot-input-container {
    display: flex;
    padding: 16px;
    border-top: 1px solid #e5e7eb;
    gap: 10px;
    background: white;
}

.chatbot-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 24px;
    font-size: 0.95em;
    transition: border-color 0.3s;
    background: #f9fafb;
}

.chatbot-input:focus {
    outline: none;
    border-color: #667eea;
    background: white;
}

.chatbot-send {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 24px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 0.95em;
}

.chatbot-send:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.chatbot-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Mobile Responsive Styles */
@media (max-width: 1024px) {
    .dashboard {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    header {
        padding: 20px 0;
        margin-bottom: 20px;
    }

    header h1 {
        font-size: 1.8em;
    }

    .subtitle {
        font-size: 1em;
    }

    .logout-link {
        position: static;
        display: inline-block;
        margin-top: 15px;
        padding: 6px 14px;
        font-size: 0.85em;
    }

    .card {
        padding: 15px;
        border-radius: 12px;
    }

    .card h2 {
        font-size: 1.4em;
        margin-bottom: 15px;
    }

    .portfolio-stats {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-item {
        padding: 12px;
    }

    .stat-value {
        font-size: 1.3em;
    }

    .portfolio-controls {
        flex-direction: column;
    }

    .position-item {
        padding: 10px;
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

    .position-item > div:last-child {
        text-align: left !important;
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .risk-score {
        width: 80px;
        height: 80px;
    }

    .score-value {
        font-size: 1.8em;
    }

    .action-buttons {
        flex-direction: column;
    }

    .btn {
        width: 100%;
        padding: 12px;
    }

    /* Chatbot mobile */
    .chatbot-container {
        bottom: 10px;
        right: 10px;
    }

    .chatbot-toggle {
        padding: 12px 18px;
        font-size: 0.9em;
    }

    .chatbot-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

    .chatbot-header {
        padding: 16px;
    }

    .chatbot-messages {
        padding: 12px;
    }

    .chatbot-message {
        max-width: 90%;
    }

    .chatbot-input-container {
        padding: 12px;
    }

    .chatbot-input {
        padding: 10px 14px;
    }

    .chatbot-send {
        padding: 10px 16px;
    }

    /* Market analysis modal */
    .modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 5vh auto;
        padding: 15px;
    }

    .allocation-grid,
    .sector-grid,
    .indicators-grid {
        grid-template-columns: 1fr;
    }

    /* New market analysis responsive */
    .analysis-header {
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
    }

    .risk-opp-grid {
        grid-template-columns: 1fr;
    }

    .action-header {
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.5em;
    }

    .portfolio-stats {
        grid-template-columns: 1fr;
    }

    .stat-value {
        font-size: 1.2em;
    }

    .position-name {
        font-size: 0.95em;
    }

    .position-ticker {
        font-size: 0.8em;
    }

    .position-value {
        font-size: 0.95em;
    }

    .position-pnl {
        font-size: 0.8em;
    }
}
