/* ============================================================
   主题变量 - 黑夜模式（默认）
   ============================================================ */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-card: #161b22;
    --bg-input: #0d1117;
    --bg-hover: #21262d;
    --bg-selected: #2a3a5a;
    --border-color: #30363d;
    --border-light: #21262d;
    --text-primary: #e6edf3;
    --text-secondary: #c9d1d9;
    --text-dim: #8b949e;
    --gold: #f0b429;
    --gold-dark: #d4a017;
    --red: #f85149;
    --green: #3fb950;
    --blue: #58a6ff;
    --shadow: rgba(0, 0, 0, 0.3);
    --modal-bg: rgba(0, 0, 0, 0.7);
}

/* 白天模式 */
body.light-mode {
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --bg-hover: #f0f3f6;
    --bg-selected: #ddf4ff;
    --border-color: #d0d7de;
    --border-light: #eaeef2;
    --text-primary: #1f2328;
    --text-secondary: #424a53;
    --text-dim: #6e7781;
    --gold: #bf8700;
    --gold-dark: #9a6700;
    --red: #cf222e;
    --green: #1a7f37;
    --blue: #0969da;
    --shadow: rgba(0, 0, 0, 0.08);
    --modal-bg: rgba(0, 0, 0, 0.4);
}

/* ============================================================
   全局样式
   ============================================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    padding-bottom: 76px;
    transition: background 0.3s, color 0.3s;
}

.container {
    max-width: 100%;
    padding: 0 12px;
}

/* ============================================================
   顶部标题
   ============================================================ */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 4px 12px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--gold);
}

.update-time {
    font-size: 11px;
    color: var(--text-dim);
}

/* 主题切换按钮 */
.theme-toggle {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
    transition: all 0.3s;
}

.theme-toggle:hover {
    background: var(--bg-hover);
    transform: scale(1.05);
}

.theme-toggle:active {
    transform: scale(0.95);
}

/* 登出按钮 */
.header-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-logout {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-secondary);
    transition: all 0.3s;
}

.btn-logout:hover {
    background: var(--bg-hover);
    color: var(--red);
    border-color: var(--red);
}

/* ============================================================
   登录页面
   ============================================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--bg-primary);
    transition: background 0.3s;
}

.login-box {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 36px 28px;
    width: 100%;
    max-width: 360px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 40px var(--shadow);
    text-align: center;
    transition: background 0.3s, border-color 0.3s;
}

.login-logo {
    font-size: 48px;
    margin-bottom: 12px;
}

.login-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--gold);
    margin-bottom: 6px;
}

.login-subtitle {
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 24px;
}

.login-form {
    text-align: left;
    margin-bottom: 16px;
}

.login-form .form-group {
    margin-bottom: 16px;
}

.login-form .form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.login-form .form-group input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 14px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: all 0.3s;
}

.login-form .form-group input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.15);
}

.btn-login {
    width: 100%;
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
    color: var(--bg-primary);
    border: none;
    border-radius: 10px;
    padding: 14px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 8px;
}

.btn-login:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-login:active {
    transform: scale(0.98);
}

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

.login-tip {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

/* ============================================================
   三大指标卡片 - 3行布局
   ============================================================ */
.summary-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 12px;
}

.card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    transition: background 0.3s, border-color 0.3s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-total {
    border: 2px solid var(--gold);
    background: linear-gradient(135deg, var(--bg-hover) 0%, var(--bg-card) 100%);
}

.card-label {
    font-size: 13px;
    color: var(--text-dim);
    font-weight: 500;
}

.card-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    text-align: right;
    transition: color 0.3s;
}

.card-total .card-value {
    color: var(--gold);
    font-size: 20px;
}

/* ============================================================
   股票/基金分类卡片
   ============================================================ */
.category-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.cat-card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 12px;
    border: 1px solid var(--border-color);
    transition: background 0.3s, border-color 0.3s;
}

.cat-title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 8px;
}

.cat-stock .cat-title {
    color: var(--red);
}

.cat-fund .cat-title {
    color: var(--blue);
}

.cat-detail {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.8;
    transition: color 0.3s;
}

/* ============================================================
   持仓明细
   ============================================================ */
.holdings-section {
    margin-bottom: 20px;
}

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

.section-header h2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    transition: color 0.3s;
}

.btn-refresh {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-refresh:hover {
    background: var(--bg-hover);
}

.btn-refresh:active {
    background: var(--bg-hover);
}

/* 刷新按钮加载中状态 */
.btn-refresh:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* 表格 - 横向滚动 */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    transition: border-color 0.3s;
}

.holdings-table {
    width: 100%;
    min-width: 720px;
    border-collapse: collapse;
    font-size: 12px;
}

.holdings-table th:nth-child(2),
.holdings-table td:nth-child(2) {
    width: 70px;
    white-space: nowrap;
}

.holdings-table thead {
    background: var(--bg-card);
    position: sticky;
    top: 0;
}

.holdings-table th {
    padding: 10px 8px;
    text-align: center;
    color: var(--gold);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    transition: color 0.3s, background 0.3s;
}

.holdings-table th:first-child {
    text-align: left;
    padding-left: 12px;
    width: 115px;
}

.holdings-table td:first-child {
    width: 115px;
}

.holdings-table td {
    padding: 10px 8px;
    text-align: center;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
    color: var(--text-secondary);
    transition: color 0.3s, border-color 0.3s;
}

.holdings-table td:first-child {
    text-align: left;
}

.holding-name-row {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    line-height: 1.3;
    text-align: right;
}

.holding-meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.3;
}

.holding-current {
    color: var(--text-dim);
    font-size: 10px;
}

.holding-code {
    color: var(--text-dim);
    font-size: 10px;
}

.holdings-table tbody tr {
    background: var(--bg-primary);
    transition: background 0.3s;
}

.holdings-table tbody tr:nth-child(even) {
    background: var(--bg-card);
}

.holdings-table .loading {
    text-align: center;
    color: var(--text-dim);
    padding: 30px;
}

/* 颜色 */
.text-red {
    color: var(--red) !important;
    font-weight: 600;
}

.text-green {
    color: var(--green) !important;
    font-weight: 600;
}

.text-gold {
    color: var(--gold) !important;
}

.text-blue {
    color: var(--blue) !important;
}

/* 删除按钮 */
.btn-del {
    background: transparent;
    color: var(--red);
    border: 1px solid var(--red);
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-del:hover {
    background: var(--red);
    color: #fff;
}

.btn-del:active {
    background: var(--red);
    color: #fff;
}

/* ============================================================
   底部操作栏
   ============================================================ */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 100;
    transition: background 0.3s, border-color 0.3s;
}

.btn-add {
    width: 100%;
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
    color: var(--bg-primary);
    border: none;
    border-radius: 10px;
    padding: 14px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-add:hover {
    opacity: 0.9;
}

.btn-add:active {
    opacity: 0.9;
    transform: scale(0.98);
}

/* ============================================================
   弹窗
   ============================================================ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--modal-bg);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: background 0.3s;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 14px;
    width: 100%;
    max-width: 380px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: 0 10px 40px var(--shadow);
    transition: background 0.3s, border-color 0.3s;
}

.modal-small {
    max-width: 300px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 16px;
    color: var(--gold);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    padding: 16px;
}

.modal-body p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: all 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--gold);
}

.modal-footer {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
}

.btn-cancel,
.btn-confirm,
.btn-delete {
    flex: 1;
    padding: 11px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.3s;
}

.btn-cancel {
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-confirm {
    background: var(--gold);
    color: var(--bg-primary);
}

.btn-delete {
    background: var(--red);
    color: #fff;
}

/* ============================================================
   Toast
   ============================================================ */
.toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 20px var(--shadow);
}

.toast.show {
    opacity: 1;
}

/* ============================================================
   桌面端适配
   ============================================================ */
@media (min-width: 768px) {
    .container {
        max-width: 900px;
        margin: 0 auto;
    }

    .card-value {
        font-size: 20px;
    }

    .card-total .card-value {
        font-size: 22px;
    }

    .holdings-table {
        min-width: 100%;
    }
}

/* 小尺寸金色按钮（用于区块标题栏，如"添加持仓/添加债务"） */
.btn-add.btn-small {
    width: auto;
    display: inline-block;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    vertical-align: middle;
}

/* 标题栏按钮组：间隔 + 图标 */
.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.btn-refresh .refresh-icon {
    vertical-align: -2px;
    margin-right: 4px;
}

/* 底部栏刷新按钮 */
.btn-refresh-bottom {
    width: 100%;
    padding: 12px;
    background: #e9af24;
    color: var(--bg-primary);
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.3s, opacity 0.3s;
}
.btn-refresh-bottom:hover {
    background: #d4a017;
}
.btn-refresh-bottom:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.btn-refresh-bottom .refresh-icon {
    vertical-align: -2px;
}

/* 刷新按钮 金币爆开动画 */
.coin-burst {
    position: fixed;
    z-index: 9999;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff6c9, #f4c430 45%, #b8860b 85%);
    box-shadow:
        inset -2px -3px 5px rgba(139, 101, 8, 0.55),
        inset 2px 2px 4px rgba(255, 255, 255, 0.65),
        0 0 8px rgba(244, 196, 48, 0.85);
    border: 1px solid rgba(255, 220, 90, 0.7);
    pointer-events: none;
    opacity: 0;
    animation: coinFly 0.9s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}
/* 金币内圈方孔，更像铜钱/金币 */
.coin-burst::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30%;
    height: 30%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: rgba(184, 134, 11, 0.35);
    box-shadow: inset 0 0 2px rgba(120, 84, 6, 0.6);
}

@keyframes coinFly {
    0% {
        transform: translate(-50%, -50%) translate(0, 0) rotate(0deg) scale(0.3);
        opacity: 1;
    }
    60% {
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) translate(var(--tx, 0px), var(--ty, -100px))
            rotate(var(--rot, 180deg)) scale(1.15);
        opacity: 0;
    }
}


/* ========== 刷新按钮小眼睛动画 ========== */
.eye-pair {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-right: 8px;
    vertical-align: middle;
}
.eye {
    position: relative;
    display: inline-block;
    width: 20px;
    height: 24px;
    background: #fffdf4;
    border-radius: 50%;
    box-shadow: inset 0 0 0 2px rgba(43, 26, 14, 0.35), 0 1px 2px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}
.pupil {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 11px;
    height: 13px;
    background: radial-gradient(circle at 35% 35%, #5a3b22, #2b1a0e 70%);
    border-radius: 50%;
    margin: -6.5px 0 0 -5.5px;
    animation: pupilLook 3.6s ease-in-out infinite;
}
.eye-2 .pupil {
    animation-delay: 0.18s;
}
@keyframes pupilLook {
    0%, 12%   { transform: translateX(-5px); }
    28%, 40%  { transform: translateX(5px); }
    56%, 68%  { transform: translateX(-5px); }
    84%, 100% { transform: translateX(5px); }
}


/* ========== 刷新按钮眨眼动画 ========== */
.eye.blink {
    animation: blinkEyes 0.4s ease-in-out;
}
@keyframes blinkEyes {
    0%   { transform: scaleY(1); }
    35%  { transform: scaleY(0.08); }
    60%  { transform: scaleY(0.08); }
    100% { transform: scaleY(1); }
}


/* ========== 眨眼时瞳孔上翻（翻白眼） ========== */
.eye.blink .pupil {
    animation: rollEyes 0.4s ease-in-out;
}
@keyframes rollEyes {
    0%   { transform: translateY(0); }
    25%  { transform: translateY(-9px); }
    60%  { transform: translateY(-9px); }
    100% { transform: translateY(0); }
}
