/* ===== THEME VARIABLES ===== */
:root {
    --bg-primary: #f8fafc;
    --bg-gradient-start: #f8fafc;
    --bg-gradient-end: #eef2ff;
    --bg-radial-1: rgba(16, 185, 129, 0.08);
    --bg-radial-2: rgba(59, 130, 246, 0.08);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --card-bg: rgba(255, 255, 255, 0.92);
    --glass-bg: rgba(255, 255, 255, 0.82);
    --border-color: rgba(226, 232, 240, 0.9);
    --shadow-color: rgba(15, 23, 42, 0.06);
    --sidebar-bg: rgba(255, 255, 255, 0.90);
    --sidebar-hover: #ecfdf5;
    --sidebar-hover-text: #047857;
    --input-bg: #f8fafc;
    --table-header-bg: #f8fafc;
    --table-row-hover: #f8fafc;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-gradient-start: #0f172a;
    --bg-gradient-end: #1e293b;
    --bg-radial-1: rgba(16, 185, 129, 0.15);
    --bg-radial-2: rgba(59, 130, 246, 0.15);
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --card-bg: rgba(30, 41, 59, 0.92);
    --glass-bg: rgba(30, 41, 59, 0.82);
    --border-color: rgba(51, 65, 85, 0.9);
    --shadow-color: rgba(0, 0, 0, 0.3);
    --sidebar-bg: rgba(30, 41, 59, 0.95);
    --sidebar-hover: #1e3a2f;
    --sidebar-hover-text: #10b981;
    --input-bg: #1e293b;
    --table-header-bg: #1e293b;
    --table-row-hover: #1e293b;
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: background 0.3s ease, color 0.3s ease;
}

body {
    background:
        radial-gradient(circle at top left, var(--bg-radial-1), transparent 30%),
        radial-gradient(circle at top right, var(--bg-radial-2), transparent 25%),
        linear-gradient(180deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
}

.glass { background: var(--glass-bg); backdrop-filter: blur(16px); }
.app-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px var(--shadow-color);
    transition: all 0.3s ease;
}
.sidebar-link { transition: all .2s ease; color: var(--text-secondary); }
.sidebar-link:hover { background: var(--sidebar-hover); color: var(--sidebar-hover-text); transform: translateX(2px); }
.hidden-ui { display: none !important; }

[data-theme="dark"] .bg-white { background-color: var(--card-bg) !important; }
[data-theme="dark"] .bg-slate-50 { background-color: var(--input-bg) !important; }
[data-theme="dark"] .bg-slate-100 { background-color: var(--table-header-bg) !important; }
[data-theme="dark"] .text-slate-900, [data-theme="dark"] .text-slate-800, [data-theme="dark"] .text-slate-700 { color: var(--text-primary) !important; }
[data-theme="dark"] .text-slate-600 { color: var(--text-secondary) !important; }
[data-theme="dark"] .text-slate-500 { color: var(--text-muted) !important; }
[data-theme="dark"] .border-slate-200, [data-theme="dark"] .border-slate-100 { border-color: var(--border-color) !important; }

input, select, textarea {
    background: var(--input-bg) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
    transition: all 0.3s ease;
}
input::placeholder, select::placeholder { color: var(--text-muted) !important; }
table thead { background: var(--table-header-bg) !important; }
table tbody tr { border-color: var(--border-color); }
table tbody tr:hover { background: var(--table-row-hover) !important; }
table th, table td { color: var(--text-secondary); }

.theme-toggle {
    position: relative; width: 50px; height: 26px;
    background: var(--border-color); border-radius: 13px;
    cursor: pointer; transition: all 0.3s ease;
}
.theme-toggle-slider {
    position: absolute; width: 20px; height: 20px;
    background: white; border-radius: 50%; top: 3px; left: 3px;
    transition: transform 0.3s ease;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
[data-theme="dark"] .theme-toggle { background: #4f46e5; }
[data-theme="dark"] .theme-toggle-slider { transform: translateX(24px); }
.theme-toggle-icon { font-size: 12px; color: #f59e0b; }
[data-theme="dark"] .theme-toggle-icon { color: #e0e7ff; }

#toast-container {
    position: fixed; top: 1.5rem; right: 1.5rem; z-index: 3000;
    display: flex; flex-direction: column; gap: 0.75rem; pointer-events: none;
}
.toast {
    pointer-events: auto; min-width: 320px; max-width: 420px;
    padding: 1rem 1.25rem; border-radius: 1rem;
    background: var(--card-bg); backdrop-filter: blur(12px);
    border: 1px solid var(--border-color); box-shadow: 0 10px 40px var(--shadow-color);
    display: flex; align-items: flex-start; gap: 0.75rem;
    animation: toastSlideIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
    position: relative; overflow: hidden; color: var(--text-primary);
}
.toast.toast-exit { animation: toastSlideOut 0.3s cubic-bezier(0.22, 1, 0.36, 1) forwards; }
.toast-icon {
    width: 2rem; height: 2rem; border-radius: 0.75rem;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 0.95rem;
}
.toast-success .toast-icon { background: #d1fae5; color: #047857; }
.toast-error .toast-icon { background: #fee2e2; color: #b91c1c; }
.toast-warning .toast-icon { background: #fef3c7; color: #b45309; }
.toast-info .toast-icon { background: #e0f2fe; color: #0369a1; }
.toast-content { flex: 1; }
.toast-title { font-weight: 600; color: var(--text-primary); font-size: 0.95rem; margin-bottom: 0.15rem; }
.toast-message { color: var(--text-secondary); font-size: 0.875rem; line-height: 1.4; }
.toast-close {
    background: transparent; border: none; color: var(--text-muted);
    cursor: pointer; padding: 0.25rem; border-radius: 0.5rem;
    transition: all 0.2s; flex-shrink: 0;
}
.toast-close:hover { background: var(--input-bg); color: var(--text-secondary); }
.toast-progress {
    position: absolute; bottom: 0; left: 0; height: 3px;
    background: currentColor; opacity: 0.3;
    animation: toastProgress 3s linear forwards;
}
.toast-success .toast-progress { color: #10b981; }
.toast-error .toast-progress { color: #ef4444; }
.toast-warning .toast-progress { color: #f59e0b; }
.toast-info .toast-progress { color: #0ea5e9; }
.toast:hover .toast-progress { animation-play-state: paused; }

@keyframes toastSlideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastSlideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(120%); opacity: 0; } }
@keyframes toastProgress { from { width: 100%; } to { width: 0%; } }

.loading-dots::after { content: ''; animation: loadingDots 1.5s infinite; }
@keyframes loadingDots {
    0%, 20% { content: ''; } 25%, 45% { content: '.'; }
    50%, 70% { content: '..'; } 75%, 100% { content: '...'; }
}
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3rem 1rem; text-align: center; }
.empty-state-icon {
    width: 4rem; height: 4rem; border-radius: 50%;
    background: var(--input-bg); display: flex;
    align-items: center; justify-content: center; margin-bottom: 1rem;
}
.empty-state-icon i { font-size: 1.5rem; color: var(--text-muted); }
.input-error { border-color: #fca5a5 !important; background-color: #fef2f2 !important; }
.input-error:focus { --tw-ring-color: #ef4444 !important; border-color: #ef4444 !important; }
.input-success { border-color: #6ee7b7 !important; }
.input-success:focus { --tw-ring-color: #10b981 !important; border-color: #10b981 !important; }

.stock-account-row { cursor: pointer; transition: all 0.2s ease; }
.stock-account-row:hover { background-color: var(--table-row-hover); }
.stock-account-row .expand-icon { transition: transform 0.3s ease; }
.stock-account-row.expanded .expand-icon { transform: rotate(90deg); }
.stock-detail-row { max-height: 0; overflow: hidden; transition: max-height 0.4s ease, opacity 0.3s ease; opacity: 0; }
.stock-detail-row.show { max-height: 1000px; opacity: 1; }
.stock-detail-content {
    padding: 1rem 1.5rem;
    background: linear-gradient(to right, var(--bg-primary), var(--card-bg));
    border-top: 1px solid var(--border-color);
}
.stock-summary-badge { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0.75rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 600; }
.badge-profit { background: #d1fae5; color: #047857; }
.badge-neutral { background: #e0f2fe; color: #0369a1; }
.badge-loss { background: #fee2e2; color: #b91c1c; }

.stock-side-panel {
    position: fixed; top: 0; right: -100%; width: 60%; max-width: 800px; height: 100vh;
    background: var(--card-bg); color: var(--text-primary);
    box-shadow: -10px 0 30px var(--shadow-color);
    transition: right 0.3s ease; z-index: 1000; overflow-y: auto;
}
.stock-side-panel.show { right: 0; }
.stock-side-panel-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5); opacity: 0; visibility: hidden;
    transition: all 0.3s ease; z-index: 999;
}
.stock-side-panel-overlay.show { opacity: 1; visibility: visible; }
.stock-panel-header {
    position: sticky; top: 0; background: var(--card-bg);
    border-bottom: 2px solid var(--border-color); padding: 1.5rem; z-index: 10;
}
.stock-panel-content { padding: 1.5rem; }
.stock-panel-close {
    position: absolute; top: 1.5rem; right: 1.5rem;
    background: var(--input-bg); border: 1px solid var(--border-color);
    width: 2.5rem; height: 2.5rem; border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; color: var(--text-secondary);
}
.stock-panel-close:hover { background: var(--border-color); transform: rotate(90deg); }
.stock-detail-table th, .stock-detail-table td { text-align: right; padding: 0.75rem 1rem; }
.stock-detail-table th:first-child, .stock-detail-table td:first-child { text-align: left; }

.tooltip-card {
    position: fixed; top: 0; left: 0; background: var(--card-bg);
    border-radius: 1rem; box-shadow: 0 20px 40px var(--shadow-color);
    padding: 1rem 1.25rem; min-width: 280px; z-index: 1000;
    opacity: 0; visibility: hidden; transform: translateY(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none; border: 1px solid var(--border-color); color: var(--text-primary);
}
.tooltip-card.show { opacity: 1; visibility: visible; transform: translateY(0); }
.tooltip-title {
    font-size: 0.75rem; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.05em;
    margin-bottom: 0.75rem; padding-bottom: 0.5rem; border-bottom: 2px solid var(--border-color);
}
.tooltip-item { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; font-size: 0.875rem; border-bottom: 1px solid var(--border-color); }
.tooltip-item:last-child { border-bottom: none; }
.tooltip-label { color: var(--text-secondary); font-weight: 500; }
.tooltip-value { font-weight: 600; color: var(--text-primary); }
.tooltip-total {
    margin-top: 0.75rem; padding-top: 0.75rem; border-top: 2px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center;
    font-weight: 700; font-size: 0.95rem; color: var(--text-primary);
}

.pie-chart-container {
    background: var(--card-bg); border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px var(--shadow-color); border-radius: 1.5rem; padding: 1.5rem;
}
.pie-chart-wrapper { position: relative; height: 320px; width: 100%; }

.export-btn { transition: all 0.3s ease; }
.export-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }

/* ===== DIVIDEND CALENDAR ===== */
.dividend-calendar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    margin-top: 1rem;
}

@media (max-width: 1280px) {
    .dividend-calendar {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .dividend-calendar {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .dividend-calendar {
        grid-template-columns: 1fr;
    }
}

.calendar-month {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1rem;
    box-shadow: 0 4px 12px var(--shadow-color);
}

.calendar-month-header {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    text-align: center;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.calendar-day-name {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
    padding: 0.25rem 0;
    text-transform: uppercase;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    border-radius: 0.375rem;
    position: relative;
    min-height: 32px;
}

.calendar-day.empty {
    background: transparent;
}

.calendar-day.has-dividend {
    background: rgba(244, 63, 94, 0.08);
    font-weight: 600;
    color: var(--text-primary);
}

.calendar-day-number {
    font-size: 0.75rem;
    line-height: 1;
}

.dividend-dots {
    display: flex;
    gap: 2px;
    margin-top: 2px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 100%;
}

.dividend-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.dividend-dot:hover {
    transform: scale(1.5);
    z-index: 10;
}

.dividend-legend {
    margin-top: 2rem;
    padding: 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
}

.dividend-legend-title {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.dividend-legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.dividend-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.dividend-legend-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}