/* ──────────────────────────────────────────────────────────────────
   Design Tokens
   ────────────────────────────────────────────────────────────────── */
:root {
    --bg:         #f2f3f5;
    --panel:      #ffffff;
    --panel-2:    #f7f9fb;
    --text:       #1f2a37;
    --muted:      #6b7280;
    --brand:      #0b7285;
    --brand-dark: #065865;
    --brand-light:#e7f5ff;
    --up:         #d9480f;
    --down:       #2f9e44;
    --shadow:     0 8px 24px rgba(15, 23, 42, 0.08);
    --radius-sm:  8px;
    --radius-md:  12px;
    --radius-lg:  14px;
    --transition: 0.15s ease;
}

/* 优化11：深色模式 */
@media (prefers-color-scheme: dark) {
    :root {
        --bg:         #111827;
        --panel:      #1f2937;
        --panel-2:    #263040;
        --text:       #e5e7eb;
        --muted:      #9ca3af;
        --brand:      #22b8cf;
        --brand-dark: #0b7285;
        --brand-light:#0e3d52;
        --up:         #f87171;
        --down:       #4ade80;
        --shadow:     0 8px 24px rgba(0, 0, 0, 0.4);
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Inter", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ──────────────────────────────────────────────────────────────────
   Layout
   ────────────────────────────────────────────────────────────────── */
.app {
    display: grid;
    grid-template-columns: 288px 1fr;
    height: 100vh;
}

.sidebar {
    background: var(--panel);
    border-right: 1px solid rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content {
    padding: 24px 28px;
    overflow-y: auto;
    height: 100vh;
}

/* ──────────────────────────────────────────────────────────────────
   Sync Bar
   ────────────────────────────────────────────────────────────────── */
.sync-bar {
    padding: 10px 16px;
    background: #fff9db;
    border-bottom: 1px solid #ffe066;
    font-size: 12px;
}
@media (prefers-color-scheme: dark) {
    .sync-bar { background: #2d2208; border-color: #7a5c00; }
}

.hidden { display: none !important; }

.sync-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.progress {
    margin-top: 6px;
    height: 5px;
    background: rgba(0,0,0,0.08);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #22b8cf, #339af0);
    transition: width 0.3s ease;
}

/* ──────────────────────────────────────────────────────────────────
   Search & Controls
   ────────────────────────────────────────────────────────────────── */
.search {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    display: flex;
    gap: 8px;
    align-items: center;
}

.search input {
    flex: 1;
    min-width: 0;
    padding: 9px 12px;
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: var(--radius-md);
    font-size: 13px;
    outline: none;
    background: var(--panel-2);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.search input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(34, 184, 207, 0.2);
    background: var(--panel);
}

.sort-hint {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}

.sort-select {
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: var(--radius-md);
    padding: 7px 8px;
    font-size: 12px;
    background: var(--panel-2);
    color: var(--text);
    cursor: pointer;
    transition: border-color var(--transition);
}
.sort-select:focus { outline: none; border-color: var(--brand); }

/* ──────────────────────────────────────────────────────────────────
   Data Freshness Bar
   ────────────────────────────────────────────────────────────────── */
.data-freshness-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 16px 8px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    background: var(--panel);
}

.freshness-text {
    font-size: 11px;
    color: var(--muted);
}

.freshness-text.stale {
    color: #d9480f;
}

.refresh-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    color: var(--text);
    font-size: 11px;
    cursor: pointer;
    font-family: inherit;
    transition: background var(--transition), border-color var(--transition);
}

.refresh-btn:hover:not(:disabled) {
    background: var(--brand-light);
    border-color: var(--brand);
    color: var(--brand);
}

.refresh-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.refresh-btn.spinning .refresh-icon {
    animation: spin 1s linear infinite;
}

.refresh-icon {
    width: 14px;
    height: 14px;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ──────────────────────────────────────────────────────────────────
   Mode Toggle
   ────────────────────────────────────────────────────────────────── */
.mode-toggle {
    display: flex;
    gap: 5px;
    padding: 10px 16px 6px;
}

.mode-btn {
    flex: 1;
    padding: 6px 6px;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: var(--radius-md);
    background: var(--panel-2);
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
    font-family: inherit;
}

.mode-btn:hover { background: var(--brand-light); border-color: var(--brand); }

.mode-btn.active {
    border-color: var(--brand);
    background: var(--brand-light);
    color: var(--brand);
    font-weight: 600;
}

/* ──────────────────────────────────────────────────────────────────
   Choice Month Bar
   ────────────────────────────────────────────────────────────────── */
.choice-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px 10px;
}

.choice-label { font-size: 12px; color: var(--muted); }

/* ──────────────────────────────────────────────────────────────────
   优化3：分页控件（侧边栏底部）
   ────────────────────────────────────────────────────────────────── */
.list-pager {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 16px 6px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.pager-btn {
    width: 26px;
    height: 26px;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: 6px;
    background: var(--panel-2);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
    font-family: inherit;
}
.pager-btn:hover:not(:disabled) { background: var(--brand-light); border-color: var(--brand); color: var(--brand); }
.pager-btn:disabled { opacity: 0.35; cursor: default; }

.pager-info {
    font-size: 12px;
    color: var(--muted);
    min-width: 40px;
    text-align: center;
}

.pager-total {
    font-size: 11px;
    color: var(--muted);
    margin-left: auto;
}

/* ──────────────────────────────────────────────────────────────────
   Stock List
   ────────────────────────────────────────────────────────────────── */
.stock-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 0 20px;
    scroll-behavior: smooth;
}

.stock-item {
    padding: 9px 16px;
    border-left: 3px solid transparent;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
    user-select: none;
}

.stock-item:hover { background: var(--panel-2); }

.stock-item.active {
    background: var(--brand-light);
    border-left-color: var(--brand);
}

.stock-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 13.5px;
}

.stock-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.stock-sub {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 11px;
    margin-top: 3px;
}

.stock-yoy {
    font-weight: 700;
    font-size: 13px;
    text-align: right;
    white-space: nowrap;
    margin-left: 6px;
}

.tag-up   { color: var(--up); }
.tag-down { color: var(--down); }

.star { color: #fcc419; font-weight: bold; }

/* ──────────────────────────────────────────────────────────────────
   Content Header
   ────────────────────────────────────────────────────────────────── */
.content-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.stock-title {
    font-size: 21px;
    font-weight: 700;
    margin: 0 0 4px;
    letter-spacing: -0.3px;
}

.stock-meta { font-size: 12px; color: var(--muted); }

.badge {
    font-size: 12px;
    padding: 5px 10px;
    background: var(--brand-light);
    border-radius: 999px;
    color: var(--brand);
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ──────────────────────────────────────────────────────────────────
   Cards & Pages
   ────────────────────────────────────────────────────────────────── */
.card {
    background: var(--panel);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}

.page {
    min-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
}

.choice-reason {
    background: #fff7e6;
    border: 1px solid #ffe8cc;
    color: #9c5a0a;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 12px;
    margin: 0 0 12px 0;
    line-height: 1.6;
}
@media (prefers-color-scheme: dark) {
    .choice-reason { background: #2a1800; border-color: #6b3a00; color: #f59e0b; }
}

.page-reports { padding-top: 12px; }

/* ──────────────────────────────────────────────────────────────────
   Table
   ────────────────────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    max-height: 320px;
    overflow-y: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th, td {
    padding: 8px 10px;
    text-align: center;
    border-bottom: 1px solid rgba(0,0,0,0.06);
}

th { background: var(--panel-2); font-weight: 600; position: sticky; top: 0; z-index: 1; }

.eps-num {
    font-family: "JetBrains Mono", "Consolas", monospace;
    font-weight: 600;
    font-size: 12px;
}

.yoy-tag { font-size: 11px; margin-left: 4px; }

.muted { color: var(--muted); }

/* ──────────────────────────────────────────────────────────────────
   Charts
   ────────────────────────────────────────────────────────────────── */
.charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.chart-box {
    background: var(--panel-2);
    border-radius: var(--radius-md);
    padding: 12px;
    border: 1px solid rgba(0,0,0,0.05);
}

.chart-title {
    font-size: 12px;
    color: var(--brand-dark);
    font-weight: 600;
    margin-bottom: 8px;
}

canvas { width: 100% !important; height: 160px !important; }

/* ──────────────────────────────────────────────────────────────────
   Reports
   ────────────────────────────────────────────────────────────────── */
.reports-title { font-weight: 600; margin-bottom: 10px; }

.report-box {
    background: var(--panel-2);
    border: 1px dashed rgba(0,0,0,0.12);
    border-radius: var(--radius-md);
    padding: 12px;
    color: var(--muted);
    font-size: 13px;
    min-height: 80px;
}

/* 研报内部状态 */
.report-empty {
    text-align: center;
    padding: 24px 12px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.7;
}

.report-unconfigured {
    display: block;
    color: #92400e;
    background: #fef3c7;
    border: 1px solid #fde68a;
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    text-align: left;
    line-height: 1.8;
}
.report-unconfigured code {
    background: rgba(0,0,0,0.07);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: "JetBrains Mono", monospace;
    font-size: 11px;
}
@media (prefers-color-scheme: dark) {
    .report-unconfigured { background: #2d1e00; border-color: #78480c; color: #fcd34d; }
    .report-unconfigured code { background: rgba(255,255,255,0.1); }
}

.report-loading {
    color: var(--brand);
    animation: pulse 1.4s ease-in-out infinite;
}

.report-error {
    color: #b91c1c;
}
@media (prefers-color-scheme: dark) {
    .report-error { color: #fca5a5; }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.5; }
}

.report-filters {
    display: grid;
    grid-template-columns: 1fr 140px 140px auto;
    gap: 8px;
    margin-bottom: 8px;
}

.report-input {
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    font-size: 12px;
    background: var(--panel-2);
    color: var(--text);
}

.report-summary-row {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.report-count { font-size: 12px; color: var(--muted); }

.report-item {
    padding: 10px 0;
    border-bottom: 1px solid rgba(0,0,0,0.06);
}
.report-item:last-child { border-bottom: none; }

.report-title { font-size: 13px; font-weight: 600; color: var(--text); }
.report-meta  { font-size: 11px; color: var(--muted); margin-top: 2px; }
.report-summary { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.4; }

.report-link {
    display: inline-block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--brand);
    text-decoration: none;
}
.report-link:hover { text-decoration: underline; }

.reports-pagination {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-btn {
    padding: 6px 10px;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: background var(--transition);
}
.page-btn:hover:not(:disabled) { background: var(--brand-light); border-color: var(--brand); color: var(--brand); }
.page-btn:disabled { opacity: 0.4; cursor: default; }

.page-info { font-size: 12px; color: var(--muted); }

/* ──────────────────────────────────────────────────────────────────
   优化10：Toast 通知
   ────────────────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    pointer-events: auto;
    animation: toastIn 0.25s ease forwards;
    max-width: 320px;
}

.toast.toast-error   { background: #fee2e2; color: #991b1b; border-left: 3px solid #ef4444; }
.toast.toast-success { background: #dcfce7; color: #166534; border-left: 3px solid #22c55e; }
.toast.toast-info    { background: var(--brand-light); color: var(--brand); border-left: 3px solid var(--brand); }
.toast.toast-out     { animation: toastOut 0.25s ease forwards; }

@keyframes toastIn  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(12px); } }

@media (prefers-color-scheme: dark) {
    .toast.toast-error   { background: #3b0a0a; color: #fca5a5; }
    .toast.toast-success { background: #052e16; color: #86efac; }
}

/* ──────────────────────────────────────────────────────────────────
   Responsive
   ────────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { height: 45vh; }
    .report-filters { grid-template-columns: 1fr 1fr; }
}

.screen-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 0 16px 10px;
}
