:root {
    --bg-dark: #0f172a;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --secondary: #475569;
    --secondary-hover: #334155;
    
    --profit-up: #ef4444;    /* Red for profit */
    --loss-down: #10b981;    /* Green for loss */
    --profit-up-bg: rgba(239, 68, 68, 0.15);
    --loss-down-bg: rgba(16, 185, 129, 0.15);

    --border-radius: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    -webkit-font-smoothing: antialiased;
}

/* Background Decorative Elements */
.bg-shape {
    position: fixed;
    border-radius: 50%;
    filter: blur(100px);
    z-index: -1;
    opacity: 0.5;
    animation: float 20s infinite alternate;
}
.shape-1 {
    width: 400px;
    height: 400px;
    background: #3b82f6;
    top: -100px;
    left: -100px;
}
.shape-2 {
    width: 600px;
    height: 600px;
    background: #8b5cf6;
    bottom: -200px;
    right: -200px;
    animation-delay: -5s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(50px, 50px) scale(1.1); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-in-up {
    animation: fadeInUp 0.6s ease-out forwards;
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Glassmorphism */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

/* Header */
.app-header {
    padding: 1.5rem 2rem;
}
.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.app-header h1 span {
    font-size: 0.9rem;
    padding: 4px 10px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    border-radius: 20px;
    font-weight: 600;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.logout-link {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.05);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
}
.logout-link:hover {
    color: white;
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
    transform: translateY(-1px);
}
.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--profit-up);
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Controls */
.controls-section {
    padding: 2rem;
}
.controls-section h2 {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    color: var(--text-main);
    font-weight: 600;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    align-items: end;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.input-group label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

input {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 0.8rem 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
}
input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.button-row {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
    align-items: center;
}
.btn-spacer {
    flex: 1;
    min-width: 1rem;
}
.btn {
    padding: 0.7rem 1.2rem;
    border-radius: 8px;
    border: none;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: white;
    white-space: nowrap;
}
.primary-btn {
    background: var(--primary);
}
.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}
.secondary-btn {
    background: var(--secondary);
}
.secondary-btn:hover {
    background: var(--secondary-hover);
    transform: translateY(-2px);
}
.danger-btn {
    background: var(--loss-down);
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}
.danger-btn:hover {
    background: #dc2626;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

/* Dashboard Table */
.dashboard-section {
    padding: 1.5rem;
    overflow: hidden;
}

/* Table Toolbar */
.table-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.75rem;
}
.col-toggle-wrapper {
    position: relative;
}
.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}
.col-toggle-dropdown {
    position: absolute;
    right: 0;
    top: 110%;
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 50;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    min-width: 160px;
}
.col-toggle-dropdown.hidden {
    display: none;
}
.col-toggle-dropdown label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 0;
    transition: color 0.2s;
}
.col-toggle-dropdown label:hover {
    color: var(--text-main);
}
.col-toggle-dropdown input[type="checkbox"] {
    width: auto;
    accent-color: var(--primary);
}
.table-container {
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    text-align: left;
}
th {
    padding: 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--glass-border);
    white-space: nowrap;
}
td {
    padding: 1rem;
    font-size: 0.95rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: var(--transition);
    white-space: nowrap;
}
tbody tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}
tbody tr:last-child td {
    border-bottom: none;
}

.text-success {
    color: var(--profit-up);
    font-weight: 600;
}
.text-danger {
    color: var(--loss-down);
    font-weight: 600;
}
.badge {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
}
.badge.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--loss-down); /* In A-shares, Green is usually Sell/Down */
}
.badge.danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--profit-up); /* In A-shares, Red is usually Buy/Up */
}
/* Explicit semantic colors */
.text-buy { color: var(--profit-up) !important; font-weight: bold; }
.text-sell { color: var(--loss-down) !important; font-weight: bold; }
.action-icon {
    cursor: pointer;
    opacity: 0.6;
    transition: 0.2s;
    font-size: 1.1rem;
    padding: 4px;
    border-radius: 4px;
    display: inline-block;
}
.action-icon:hover {
    opacity: 1;
    transform: scale(1.15);
    background: rgba(255,255,255,0.08);
}

/* Editable cells hint */
.editable {
    cursor: pointer;
    border-bottom: 1px dashed rgba(255,255,255,0.2) !important;
}
.editable:hover {
    background: rgba(255,255,255,0.1) !important;
}
.chart-trigger {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: var(--primary);
    text-decoration-style: dashed;
}
.chart-trigger:hover {
    color: var(--primary);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}
.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}
.modal-content {
    background: var(--bg-dark);
    width: 95%;
    max-width: 1200px;
    max-height: 85vh;
    padding: 2rem;
    position: relative;
    transform: translateY(20px) scale(0.95);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}
.modal-overlay.active .modal-content {
    transform: translateY(0) scale(1);
}

/* AI Report Area specific scrolling */
#ai-report-content {
    flex: 1;
    overflow-y: auto;
    padding-right: 1rem;
    margin: 1rem 0;
}

/* Custom Scrollbar for better UX */
#ai-report-content::-webkit-scrollbar {
    width: 6px;
}
#ai-report-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}
#ai-report-content::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}
#ai-report-content::-webkit-scrollbar-thumb:hover {
    background: var(--primary-hover);
}

.markdown-body {
    line-height: 1.6;
    color: var(--text-main);
    font-size: 1rem;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3 {
    color: var(--primary);
    margin-top: 1.5rem;
    margin-bottom: 0.8rem;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.3rem;
}
.markdown-body p { margin-bottom: 1rem; }
.markdown-body ul, .markdown-body ol { padding-left: 1.5rem; margin-bottom: 1rem; }
.markdown-body code {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
}
.close-btn {
    position: absolute;
    top: 15px; right: 20px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.2s;
}
.close-btn:hover { color: white; }

.chart-wrapper {
    height: 600px;
    margin-top: 1rem;
}

/* Prompt Modal */
.modal-prompt {
    background: var(--bg-dark);
    width: 90%;
    max-width: 400px;
    padding: 2rem;
    border-radius: var(--border-radius);
    text-align: center;
}
.prompt-body {
    margin: 1.5rem 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.prompt-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}
.default-btn {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
}
.default-btn:hover {
    background: rgba(255,255,255,0.05);
}

/* Toast */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}
.toast {
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    border-left: 4px solid var(--primary);
    padding: 12px 20px;
    border-radius: 8px;
    color: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    animation: slideIn 0.3s ease forwards, fadeOut 0.3s ease 2.7s forwards;
}
.toast.error { border-left-color: var(--loss-down); }
.toast.success { border-left-color: var(--profit-up); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

#prompt-modal {
    z-index: 10000 !important;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }

/* Responsive adjustments */
@media (max-width: 1024px) {
    .controls-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .app-container { padding: 1rem; }
    .controls-grid { grid-template-columns: 1fr; }
    .button-row { flex-direction: column; }
    .btn-spacer { display: none; }
}

/* AI Analysis Modal Styles */
.ai-modal-btn {
    background: linear-gradient(45deg, #3b82f6, #8b5cf6, #d946ef);
    background-size: 200% 200%;
    animation: gradientShift 5s ease infinite;
    color: white !important;
    opacity: 1 !important;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.ai-loading-container {
    padding: 3rem;
    text-align: center;
    color: var(--text-muted);
}

.ai-pulse {
    width: 60px;
    height: 60px;
    background-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto 1.5rem;
    animation: pulse 1.5s ease-in-out infinite;
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 15px rgba(59, 130, 246, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}

/* Markdown Rendering Styles */
.markdown-body {
    line-height: 1.6;
    color: var(--text-main);
}
.markdown-body h1, .markdown-body h2, .markdown-body h3 {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    color: var(--primary);
}
.markdown-body p { margin-bottom: 1rem; }
.markdown-body ul, .markdown-body ol { margin-bottom: 1rem; padding-left: 2rem; }
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    background: rgba(255,255,255,0.03);
    border-radius: 8px;
    overflow: hidden;
}
.markdown-body th, .markdown-body td {
    padding: 0.75rem;
    border: 1px solid var(--glass-border);
    text-align: left;
}
.markdown-body th { background: rgba(59, 130, 246, 0.1); color: var(--primary); }
.markdown-body blockquote {
    border-left: 4px solid var(--primary);
    padding-left: 1rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Memo Column Styling */
.memo-cell {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.85rem;
    transition: var(--transition);
}
.memo-cell:hover {
    color: var(--primary);
    text-decoration: underline;
}
.memo-cell.empty {
    color: rgba(255,255,255,0.1);
    font-style: italic;
}

/* Report List & Viewer Styles */
.report-list-item {
    transition: var(--transition);
    cursor: default;
}
.report-list-item:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    transform: translateX(4px);
}
.report-list-item .view-btn {
    opacity: 0.8;
}
.report-list-item:hover .view-btn {
    opacity: 1;
    background: var(--primary);
    border-color: var(--primary);
}

.markdown-body {
    line-height: 1.8;
    color: #e2e8f0;
}

.markdown-body h1, .markdown-body h2 {
    border-bottom: 2px solid var(--primary);
    padding-bottom: 0.5rem;
    margin-top: 2rem;
}

.markdown-body h3 {
    color: #93c5fd;
    margin-top: 1.5rem;
}

.markdown-body hr {
    border: none;
    border-top: 1px solid var(--glass-border);
    margin: 2rem 0;
}

.markdown-body blockquote {
    background: rgba(59, 130, 246, 0.05);
    border-left: 4px solid var(--primary);
    padding: 1rem;
    margin: 1rem 0;
    border-radius: 0 8px 8px 0;
}

.markdown-body strong {
    color: #fbbf24; /* Amber for emphasis */
}

/* Scrollbar refinement for markdown view */
#report-md-body::-webkit-scrollbar {
    width: 8px;
}
#report-md-body::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.2);
}
#report-md-body::-webkit-scrollbar-thumb {
    background: var(--secondary);
    border-radius: 4px;
}
#report-md-body::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}
