/* ============================================
   Fund Tracker - Design System
   ============================================ */
:root {
    --primary: #4361ee;
    --primary-light: #eef1ff;
    --primary-dark: #3651d4;
    --success: #10b981;
    --success-light: #ecfdf5;
    --success-bg: rgba(16, 185, 129, 0.08);
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --danger-bg: rgba(239, 68, 68, 0.08);
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --dark: #1e293b;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.07);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.1);
    --radius: 0.75rem;
    --radius-lg: 1rem;
}

/* ============================================
   Base
   ============================================ */
body {
    background-color: var(--gray-50);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    color: var(--dark);
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   Login Page
   ============================================ */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: relative;
}
.login-container::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.login-card {
    width: 420px;
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    background: white;
    position: relative;
    z-index: 1;
}
.login-card h2 {
    color: var(--dark);
    margin-bottom: 0.5rem;
    font-weight: 700;
}
.login-card .login-subtitle {
    color: var(--gray-500);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}
.login-card .form-control {
    border-radius: 0.5rem;
    padding: 0.625rem 0.875rem;
    border-color: var(--gray-200);
}
.login-card .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
}
.login-card .form-control.is-invalid {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}
.login-card .form-control.is-invalid:focus {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25);
}
.login-card #loginError {
    border-left: 3px solid #ef4444;
    background-color: #fef2f2;
    color: #991b1b;
    font-size: 0.875rem;
    animation: shake 0.3s ease-in-out;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}
.login-card #togglePassword {
    cursor: pointer;
    transition: color 0.2s;
}
.login-card #togglePassword:hover {
    color: var(--primary) !important;
}
.login-card .btn-primary {
    padding: 0.625rem;
    font-weight: 600;
    border-radius: 0.5rem;
    background: var(--primary);
    border-color: var(--primary);
}
.login-card .btn-primary:hover {
    background: var(--primary-dark);
}

/* ============================================
   Navbar
   ============================================ */
.navbar {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%) !important;
    box-shadow: var(--shadow-md);
    padding: 0.5rem 1rem;
}
.navbar-brand {
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.01em;
}

/* ============================================
   Dashboard Layout
   ============================================ */
.dashboard-left-column {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    height: 100%;
}

/* ============================================
   Stat Cards - Base
   ============================================ */
.stat-card {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
    background: white;
    height: 100%;
    display: flex;
    flex-direction: column;
}
.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
.stat-card .card-body {
    padding: 1.25rem;
}
.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-bottom: 0.5rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.stat-card .stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--dark);
    line-height: 1.3;
}
.stat-card .stat-sub {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 0.25rem;
}

/* Primary Stat Cards (Dashboard top row - key metrics) */
.stat-card-primary {
    border: none;
    border-left: 4px solid var(--primary);
    background: linear-gradient(135deg, #ffffff 0%, var(--primary-light) 100%);
    min-height: 140px;
}
.stat-card-primary .card-body {
    padding: 1.5rem;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 0.2rem;
}
.stat-card-primary .stat-label {
    font-size: 0.85rem;
    color: var(--gray-600);
    margin-bottom: 0.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    text-transform: none;
    letter-spacing: 0;
}
.stat-card-primary .stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--dark);
    line-height: 1.2;
    margin-bottom: 0.12rem;
    flex-grow: 0;
    display: block;
}
.stat-card-primary .stat-sub {
    font-size: 0.78rem;
    color: var(--gray-500);
    line-height: 1.3;
    min-height: 1.3em;
    margin-top: auto;
    padding-top: 0.38rem;
}

/* Fund contribution styling (基金贡献样式) */
.fund-contrib-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35em 0.6em;
    font-size: 0.7em;
    font-weight: 500;
    margin-top: 0;
    margin-bottom: 0.25em;
    color: var(--gray-500);
    line-height: 1.4;
}
.fund-contrib-item {
    display: inline-flex;
    align-items: center;
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 999px;
    padding: 0.14em 0.55em;
}
.fund-contrib-dot {
    width: 0.48em;
    height: 0.48em;
    border-radius: 999px;
    display: inline-block;
    margin-right: 0.24em;
    transform: translateY(-0.02em);
}
.fund-contrib-name {
    font-weight: 600;
    margin-right: 0.24em;
    letter-spacing: 0.01em;
}
.fund-contrib-val {
    color: var(--gray-700);
    font-weight: 500;
}
.fund-contrib-sep {
    display: none;
}

/* Positive / Negative coloring (红涨绿跌) */
.stat-card-primary .stat-value.positive,
.stat-card-secondary .stat-value.positive,
.stat-card .stat-value.positive {
    color: #ef4444;
}
.stat-card-primary .stat-value.negative,
.stat-card-secondary .stat-value.negative,
.stat-card .stat-value.negative {
    color: #10b981;
}

/* Secondary Stat Cards (总投入 / 总市值) */
.stat-card-secondary {
    border: 1px solid var(--gray-200);
    border-left: 3px solid var(--gray-300);
    flex: 1;
    min-height: 0;
}
.stat-card-secondary .card-body {
    padding: 1.25rem 1.5rem;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.stat-card-secondary .stat-label {
    font-size: 0.82rem;
    color: var(--gray-500);
    margin-bottom: 0.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    text-transform: none;
    letter-spacing: 0;
}
.stat-card-secondary .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--dark);
    line-height: 1.2;
}
.stat-card-secondary .stat-sub {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 0.25rem;
}

/* ============================================
   Fund Cards
   ============================================ */
.fund-card {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all 0.25s ease;
    border-left: 4px solid var(--primary);
    background: white;
    overflow: hidden;
}
.fund-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-left-color: var(--primary-dark);
}
.fund-card .fund-name {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--dark);
}
.fund-card .fund-nav {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}
.fund-card .fund-metric {
    padding: 0.25rem 0;
}
.fund-card .fund-metric .text-muted {
    font-size: 0.75rem;
    color: var(--gray-400) !important;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.fund-card .fund-metric .fw-bold {
    font-variant-numeric: tabular-nums;
}
.fund-card .fund-weekly-bar {
    background: var(--gray-50);
    border-top: 1px solid var(--gray-100);
    margin: 0 -1rem -1rem;
    padding: 0.6rem 1rem;
}
.fund-card .fund-weekly-bar.positive-bg {
    background: rgba(239, 68, 68, 0.06);
    border-top-color: rgba(239, 68, 68, 0.1);
}
.fund-card .fund-weekly-bar.negative-bg {
    background: rgba(16, 185, 129, 0.06);
    border-top-color: rgba(16, 185, 129, 0.1);
}

/* ============================================
   Chart Container
   ============================================ */
.chart-container {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
}

/* ============================================
   Tables
   ============================================ */
.table-container {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    overflow-x: auto;
}
.table-container h6 {
    color: var(--dark);
    font-weight: 700;
}
.table {
    font-size: 0.875rem;
}
.table thead th {
    background-color: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.6rem 0.75rem;
}
.table td {
    vertical-align: middle;
    white-space: nowrap;
    padding: 0.55rem 0.75rem;
    font-variant-numeric: tabular-nums;
    color: var(--gray-700);
}
.table tbody tr {
    transition: background 0.15s;
}
.table-hover tbody tr:hover {
    background-color: var(--primary-light);
}

/* Dashboard returns tables */
.dashboard-returns-panel {
    height: 320px;
    display: flex;
    flex-direction: column;
}
.dashboard-returns-panel h6 {
    flex-shrink: 0;
}
.dashboard-period-wrap {
    flex: 1;
    overflow: hidden;
}
.dashboard-weekly-scroll,
.detail-weekly-scroll {
    flex: 1;
    overflow-y: scroll;
    scrollbar-gutter: stable;
    position: relative;
    border: 1px solid var(--gray-100);
    border-radius: 0.5rem;
    background: linear-gradient(to bottom, rgba(67,97,238,0.04) 0%, rgba(67,97,238,0) 24px, rgba(67,97,238,0) calc(100% - 24px), rgba(67,97,238,0.04) 100%);
}

.detail-weekly-scroll {
    height: 420px; /* roughly shows recent 3 months of weekly rows by default */
}

/* Make weekly table scroll affordance obvious */
.dashboard-weekly-scroll::-webkit-scrollbar,
.detail-weekly-scroll::-webkit-scrollbar {
    width: 10px;
}
.dashboard-weekly-scroll::-webkit-scrollbar-track,
.detail-weekly-scroll::-webkit-scrollbar-track {
    background: #e2e8f0;
    border-radius: 999px;
}
.dashboard-weekly-scroll::-webkit-scrollbar-thumb,
.detail-weekly-scroll::-webkit-scrollbar-thumb {
    background: #64748b;
    border-radius: 999px;
    border: 2px solid #e2e8f0;
}
.dashboard-weekly-scroll::-webkit-scrollbar-thumb:hover,
.detail-weekly-scroll::-webkit-scrollbar-thumb:hover {
    background: #4361ee;
}

.dashboard-section-divider {
    border: 0;
    border-top: 2px solid var(--gray-300);
    margin: 0.75rem 0 1.25rem;
    opacity: 1;
}

/* ============================================
   Badges
   ============================================ */
.badge-holding {
    background-color: #ef4444 !important;
}
.badge-redeemed {
    background-color: var(--gray-400) !important;
}

/* ============================================
   Modal
   ============================================ */
.modal-header {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    color: white;
    border-radius: 0.3rem 0.3rem 0 0;
    padding: 1rem 1.25rem;
}
.modal-header .modal-title {
    font-weight: 700;
    font-size: 1rem;
}
.modal-header .btn-close {
    filter: brightness(0) invert(1);
}
.modal-body {
    padding: 1.25rem;
}
.modal-body .form-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--gray-600);
}
.modal-body .form-control,
.modal-body .form-select {
    border-radius: 0.5rem;
    border-color: var(--gray-200);
    font-size: 0.9rem;
}
.modal-body .form-control:focus,
.modal-body .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}
.modal-footer {
    border-top: 1px solid var(--gray-100);
    padding: 0.75rem 1.25rem;
}

/* ============================================
   Tabs
   ============================================ */
.nav-tabs {
    border-bottom: 2px solid var(--gray-200);
}
.nav-tabs .nav-link {
    font-weight: 600;
    color: var(--gray-500);
    border: none;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    transition: color 0.2s;
}
.nav-tabs .nav-link:hover {
    color: var(--primary);
    border: none;
}
.nav-tabs .nav-link.active {
    color: var(--primary);
    border: none;
    border-bottom: 3px solid var(--primary);
    background: transparent;
}

/* ============================================
   Detail Page - Fund Header
   ============================================ */
.detail-header {
    background: linear-gradient(135deg, #ffffff 0%, var(--primary-light) 100%);
    border: 1px solid var(--gray-200);
    border-left: 5px solid var(--primary);
    border-radius: var(--radius);
}
.detail-header .detail-nav-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}
.detail-header .detail-nav-date {
    font-size: 0.78rem;
    color: var(--gray-400);
}

/* Detail stat cards */
.detail-stat-card {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: white;
    text-align: center;
    transition: all 0.2s;
}
.detail-stat-card:hover {
    box-shadow: var(--shadow-md);
}
.detail-stat-card .card-body {
    padding: 1rem;
}
.detail-stat-card .stat-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gray-400);
    margin-bottom: 0.4rem;
    font-weight: 600;
}
.detail-stat-card .stat-value {
    font-size: 1.15rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.detail-stat-card .stat-sub {
    font-size: 0.72rem;
    margin-top: 0.2rem;
}

/* ============================================
   Section Headers
   ============================================ */
.section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.section-header h6 {
    margin: 0;
    font-weight: 700;
    color: var(--dark);
    font-size: 0.95rem;
}
.section-header .section-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}
.section-header .section-icon.blue {
    background: var(--primary-light);
    color: var(--primary);
}
.section-header .section-icon.green {
    background: var(--success-light);
    color: var(--success);
}

/* ============================================
   Loading
   ============================================ */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* ============================================
   User Selector
   ============================================ */
.user-selector {
    max-width: 200px;
    border-radius: 0.4rem;
    font-size: 0.82rem;
}

/* ============================================
    Manage Page - Quick Actions
    ============================================ */
.quick-action-card {
    border: 2px dashed var(--gray-200);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.25s;
    background: white;
    height: 100%;
    display: flex;
    flex-direction: column;
}
.quick-action-card:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.quick-action-card .card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.quick-action-card .action-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    margin-bottom: 0.75rem;
    flex-shrink: 0;
}
.quick-action-card .fw-bold {
    flex-shrink: 0;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 992px) {
    .dashboard-left-column {
        flex-direction: row;
        gap: 0.75rem;
    }
    .stat-card-secondary { flex: 1; }
}

@media (max-width: 768px) {
    .stat-card-primary { min-height: 120px; }
    .stat-card-primary .stat-value { font-size: 1.4rem; }
    .stat-card-secondary .stat-value { font-size: 1.2rem; }
    .stat-card-primary .card-body,
    .stat-card-secondary .card-body { padding: 1rem; }
    .login-card { width: 92%; margin: 1rem; padding: 2rem; }
    .fund-card .fund-nav { font-size: 1.1rem; }
    .container-fluid { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
    .dashboard-returns-panel { height: auto; }
    .dashboard-period-wrap { overflow: visible; }
    .dashboard-weekly-scroll { max-height: 320px; }
}

/* ============================================
   Utilities
   ============================================ */
/* 中国股市惯例：红涨绿跌 */
.text-profit { color: #ef4444 !important; }
.text-loss { color: #10b981 !important; }
.cursor-pointer { cursor: pointer; }
.font-tabular { font-variant-numeric: tabular-nums; }
.hover-hint { cursor: help; text-decoration: underline dotted var(--gray-300); text-underline-offset: 2px; }
