/* ── CSS 變數：淺色 ── */
:root, [data-theme="light"] {
    --bg:           #f0f2f5;   /* 外層背景，偏灰 */
    --bg-card:      #ffffff;
    --bg-hover:     #f1f3f5;
    --bg-input:     #ffffff;
    --border:       #e9ecef;
    --border-focus: #495057;
    --text:         #212529;
    --text-2:       #495057;
    --text-3:       #868e96;
    --text-inv:     #ffffff;
    --nav-bg:       #ffffff;
    --nav-border:   #e9ecef;
    --up:           #e03131;
    --down:         #2f9e44;
    --badge-bg:     #1971c2;
    --badge-text:   #ffffff;
    --ann-bg:       #fff9db;
    --shadow-sm:    0 1px 3px rgba(0,0,0,0.08);
    --shadow-md:    0 4px 12px rgba(0,0,0,0.10);
    --radius-sm:    6px;
    --radius-md:    10px;
    --radius-lg:    14px;
}

/* ── CSS 變數：深色 ── */
[data-theme="dark"] {
    /* 背景：微帶青色的深灰，比 #121212 有質感，像編輯器底色 */
    --bg:           #0f0f0f;   /* 外層更深 */
    /* 卡片：稍微拉開亮度，讓區塊感明顯一點 */
    --bg-card:      #1e1e1e;   /* 內容區相對亮一點 */
    /* 懸停：讓反饋更直覺 */
    --bg-hover:     #2d3136;
    --bg-input:     #1a1c1e; /* 輸入框稍微凹陷感 */
    
    /* 邊框：稍微帶點顏色，不要只是死灰 */
    --border:       #34393e;
    --border-focus: #58a6ff; /* 選中時用一點點「程式碼藍」，會很漂亮 */
    
    /* 文字：這才是關鍵！主文字要夠白，次要文字要跟背景色調一致 */
    --text:         #f0f2f5;
    --text-2:       #9ca3af;  /* 讓次要文字帶一點冷色調 */
    --text-3:       #6b7280;
    --text-inv:     #ffffff;
    
    --nav-bg:       #111214; /* 導覽列最深，壓住重心 */
    --nav-border:   #2d3136;

    /* 漲跌：稍微亮一點，在深青色背景下會很清晰 */
    --up:           #ff6b6b;
    --down:         #51cf66;

    /* 標記與勳章 */
    --badge-bg:     #388bfd;
    --badge-text:   #ffffff;
    --ann-bg:       #3d3100;
    
    --shadow-sm:    0 1px 3px rgba(0,0,0,0.5);
    --shadow-md:    0 8px 16px rgba(0,0,0,0.5);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Noto Sans TC', sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    transition: background 0.2s, color 0.2s;
    line-height: 1.6;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ── */
.navbar {
    position: sticky; top: 0; z-index: 200;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--nav-border);
    box-shadow: var(--shadow-sm);
}
.nav-inner {
    max-width: 1280px; margin: 0 auto;
    padding: 0 24px;
    height: 52px;
    display: flex; align-items: center; gap: 20px;
}
.nav-logo {
    font-size: 17px; font-weight: 700;
    color: var(--text); white-space: nowrap;
    text-decoration: none;
}
.nav-logo:hover { text-decoration: none; opacity: 0.8; }
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-links a {
    padding: 6px 12px; border-radius: var(--radius-sm);
    font-size: 14px; color: var(--text-2);
    transition: background 0.15s;
}
.nav-links a:hover { background: var(--bg-hover); text-decoration: none; }
.nav-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.nav-user { font-weight: 500; font-size: 14px; color: var(--text); }
.nav-badge {
    background: var(--badge-bg); color: var(--badge-text);
    font-size: 11px; padding: 2px 8px;
    border-radius: 20px; font-weight: 500;
}
.nav-logout { font-size: 13px; color: var(--text-3); }
.nav-logout:hover { color: var(--text); text-decoration: none; }
.btn-nav {
    padding: 6px 14px; border-radius: var(--radius-sm);
    font-size: 13px; color: var(--text-2);
    border: 1px solid var(--border);
    transition: background 0.15s;
}
.btn-nav:hover { background: var(--bg-hover); text-decoration: none; }
.btn-nav-primary {
    background: #495057;
    color: #ffffff;
    border-color: transparent;
}
.btn-nav-primary:hover { opacity: 0.85; background: #495057; }

/* ── Theme Toggle ── */
.theme-toggle {
    width: 34px; height: 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent; cursor: pointer;
    font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
}
.theme-toggle:hover { background: var(--bg-hover); }

/* ── Main Content ── */
.main-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 28px 24px;
}

/* ── 通用 Table ── */
table { width: 100%; border-collapse: collapse; }
th {
    padding: 10px 12px;
    text-align: right;
    font-size: 12px; font-weight: 600;
    color: var(--text-3);
    border-bottom: 2px solid var(--border);
    background: var(--bg);
    white-space: nowrap;
}
th:first-child { text-align: left; }
td {
    padding: 9px 12px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-2);
}
td:first-child { text-align: left; color: var(--text); }
tr:hover td { background: var(--bg-hover); }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }

/* ── Card ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px 24px;
    box-shadow: var(--shadow-sm);
}

/* ── 漲跌顏色 ── */
.up   { color: var(--up);   font-weight: 500; }
.down { color: var(--down); font-weight: 500; }

/* ── Buttons ── */
button, .btn { cursor: pointer; font-family: inherit; }
.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-2);
    cursor: pointer;
    transition: background 0.15s;
}
.btn-sm:hover { background: var(--bg-hover); }
.btn-danger { border-color: #ffc9c9; color: #e03131; }
.btn-danger:hover { background: #fff5f5; }

/* ── Form ── */
input[type=text], input[type=email], input[type=password],
input[type=date], input[type=number], select, textarea {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s;
    outline: none;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--border-focus);
}
button[type=submit]:not(.theme-toggle), button.btn-primary {
    padding: 8px 20px;
    background: #495057;
    color: #ffffff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.15s;
}
button[type=submit]:not(.theme-toggle):hover { opacity: 0.85; }

/* 讓深色模式的表格有隔行變色 */
[data-theme="dark"] tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.03); 
}

/* 讓深色模式的表格移上去有反應 */
[data-theme="dark"] tr:hover {
    background-color: rgba(255, 255, 255, 0.07); 
}

[data-theme="dark"] td:first-child {
    color: var(--text-2);
    font-weight: 500;
}

/* ── 首頁 ── */
.home-search-wrap { text-align: center; padding: 48px 0 36px; }
.home-title { font-size: 30px; font-weight: 700; margin-bottom: 20px; }
.home-search-box { max-width: 580px; margin: 0 auto; position: relative; }
.home-search-box input[type=text] {
    width: 100%; padding: 14px 18px;
    font-size: 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.home-search-box input[type=text]:focus {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-md);
}
#search-results {
    position: absolute; width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    z-index: 100;
    box-shadow: var(--shadow-md);
}
#search-results div {
    padding: 10px 18px; cursor: pointer;
    border-bottom: 1px solid var(--border);
    text-align: left; color: var(--text);
    transition: background 0.1s;
}
#search-results div:hover { background: var(--bg-hover); }
#search-results div:last-child { border-bottom: none; }
#search-results small { color: var(--text-3); margin-left: 6px; }
.home-section { margin: 28px 0; }
.home-section-header {
    display: flex; align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.home-section-header h2 { margin: 0; font-size: 17px; }
.home-section-more { font-size: 13px; color: var(--text-3); }
.home-section-more:hover { color: var(--text); text-decoration: none; }

/* 自選股卡片 */
.wl-preview-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.wl-preview-card {
    display: flex; flex-direction: column; gap: 4px;
    padding: 14px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    text-decoration: none; color: inherit;
    min-width: 120px;
    transition: box-shadow 0.15s, transform 0.15s;
    box-shadow: var(--shadow-sm);
}
.wl-preview-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    text-decoration: none;
}
.wl-preview-id { font-weight: 700; font-size: 15px; }
.wl-preview-name { font-size: 12px; color: var(--text-3); }
.wl-preview-price { font-size: 17px; font-weight: 700; margin-top: 6px; }
.wl-preview-pct { font-size: 13px; font-weight: 500; }

/* 最近瀏覽 */
.recent-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.recent-card {
    display: flex; gap: 8px; align-items: center;
    padding: 8px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: background 0.15s;
}
.recent-card:hover { background: var(--bg-hover); text-decoration: none; }
.recent-id { font-weight: 700; }
.recent-name { color: var(--text-3); }

/* ── 股票頁 ── */
.stock-header { margin-bottom: 20px; }
.stock-header h1 { font-size: 24px; margin: 0 0 4px; }
.stock-header small { color: var(--text-3); font-size: 14px; font-weight: 400; }

/* 持倉資訊列 */
.holding-inline {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: var(--radius-md);
    margin: 10px 0 18px;
    font-size: 14px;
    box-shadow: var(--shadow-sm);
}
.hi-label { color: var(--text-3); }
.hi-val { font-weight: 600; }
.hi-sep { color: var(--border); }
.hi-link { margin-left: auto; font-size: 13px; color: var(--text-3); }
.hi-link:hover { color: var(--text); text-decoration: none; }

/* 日期查詢 */
.date-form {
    display: flex; gap: 12px; align-items: flex-end;
    margin: 0 0 20px;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
}
.date-form label {
    display: flex; flex-direction: column;
    gap: 4px; font-size: 12px;
    color: var(--text-3);
}
.date-form small { color: var(--text-3); font-size: 12px; align-self: center; }

/* Tabs */
.tabs {
    display: flex; gap: 2px; flex-wrap: wrap;
    margin: 0 0 20px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
}
.tab-btn {
    padding: 9px 16px;
    border: none; background: none;
    cursor: pointer;
    font-size: 13px; font-weight: 500;
    color: var(--text-3);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s;
    font-family: inherit;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--text); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* 財報表格 */
.fin-table { min-width: 600px; }
.fin-table th { white-space: nowrap; min-width: 90px; }
.fin-table td { white-space: nowrap; }
.fin-table td.fin-name {
    white-space: normal; word-break: break-all;
    line-height: 1.5; text-align: left;
    max-width: 180px; color: var(--text);
}

/* ── Auth ── */
.auth-box {
    max-width: 420px; margin: 60px auto;
    padding: 36px 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}
.auth-box h2 { margin-top: 0; font-size: 22px; }
.auth-box label {
    display: flex; flex-direction: column;
    gap: 6px; margin-bottom: 16px;
    font-size: 13px; color: var(--text-2);
}
.auth-box input {
    padding: 10px 12px;
    font-size: 15px;
    width: 100%;
}
.auth-box button[type=submit] { width: 100%; padding: 11px; font-size: 15px; }
.auth-error {
    background: #fff5f5; color: #c92a2a;
    border: 1px solid #ffc9c9;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    font-size: 13px;
}
.auth-link { text-align: center; font-size: 13px; margin-top: 18px; color: var(--text-3); }

/* ── 自選股頁 ── */
.wl-group { margin-bottom: 36px; }
.wl-group-header {
    display: flex; align-items: center;
    gap: 12px; margin-bottom: 12px;
    flex-wrap: wrap;
}
.wl-count { color: var(--text-3); font-size: 13px; }
.wl-table th, .wl-table td { text-align: left; }
.wl-empty { color: var(--text-3); font-size: 14px; padding: 12px 0; }

/* ── 持倉頁 ── */
.holding-summary {
    display: flex; gap: 28px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 18px 24px;
    border-radius: var(--radius-md);
    margin-bottom: 28px;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
}
.summary-item { display: flex; flex-direction: column; gap: 4px; }
.summary-label { font-size: 12px; color: var(--text-3); }
.summary-value { font-size: 20px; font-weight: 700; }
.holding-table th, .holding-table td { white-space: nowrap; }
.holding-group-header { background: var(--bg-hover); }
.holding-group-header th {
    padding: 10px 12px; text-align: right;
    font-size: 13px; font-weight: 700;
    color: var(--text);
}
.holding-group-header th:first-child { text-align: left; }
.holding-sub-header td {
    font-size: 12px; color: var(--text-3);
    padding: 4px 12px;
    background: var(--bg);
}
.holding-lot-row td { font-size: 13px; }

/* ── 標記系統 ── */
.ann-form {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 18px 20px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}
.ann-form-row { display: flex; gap: 16px; margin-bottom: 12px; flex-wrap: wrap; }
.ann-form-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-3); }
.ann-form textarea {
    width: 100%; font-size: 14px;
    resize: vertical; min-height: 72px;
}
.ann-list { display: flex; flex-direction: column; gap: 12px; }
.ann-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
}
.ann-header {
    display: flex; gap: 10px; align-items: center;
    flex-wrap: wrap; margin-bottom: 8px;
}
.ann-date { font-weight: 600; font-size: 14px; }
.ann-tag {
    background: #e7f5ff; color: #1971c2;
    font-size: 12px; padding: 2px 8px;
    border-radius: 20px; font-weight: 500;
}
.ann-created { font-size: 12px; color: var(--text-3); margin-left: auto; }
.ann-note { font-size: 14px; line-height: 1.7; white-space: pre-wrap; color: var(--text-2); }
.ann-actions { margin-top: 10px; display: flex; gap: 8px; }
.ann-edit-form { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.ann-empty { color: var(--text-3); font-size: 14px; }

/* ── 整合時間軸 ── */
.timeline-table th, .timeline-table td { white-space: nowrap; font-size: 13px; }
.timeline-table td.tl-ann-cell { white-space: normal; min-width: 160px; max-width: 260px; }
.timeline-has-ann { background: var(--ann-bg) !important; }
.tl-date { font-weight: 600; }
.tl-ann-item { margin-bottom: 4px; font-size: 12px; line-height: 1.5; }
.tl-ann-note { color: var(--text-2); }
.tl-add-btn { opacity: 0.25; font-size: 14px; padding: 1px 6px; }
.tl-add-btn:hover { opacity: 1; }
tr:hover .tl-add-btn { opacity: 0.7; }

/* ── 後台 ── */
.admin-stats {
    display: flex; gap: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 18px 24px;
    border-radius: var(--radius-md);
    margin-bottom: 28px;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
}
.admin-table th, .admin-table td { text-align: left; }
.admin-inactive { opacity: 0.5; }
.admin-active-badge {
    background: #d3f9d8; color: #2f9e44;
    font-size: 12px; padding: 2px 8px; border-radius: 20px;
}
.admin-inactive-badge {
    background: #ffe3e3; color: #c92a2a;
    font-size: 12px; padding: 2px 8px; border-radius: 20px;
}

.content-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 32px;
    box-shadow: var(--shadow-sm);
    min-height: calc(100vh - 120px);
}

/* 反白顏色 */
::selection {
    background-color: #bee3f8;
    /* color: #1a365d; */
}
::-moz-selection {
    background-color: #bee3f8;
    /* color: #1a365d; */
}

[data-theme="dark"] ::selection {
    background-color: #ff922b40;
    /* color: #e2e8f0; */
}
[data-theme="dark"] ::-moz-selection {
    background-color: #ff922b40;
    /* color: #e2e8f0; */
}

/* 漲跌保留顏色 */
[data-theme="dark"] .up::selection,
[data-theme="dark"] .up *::selection {
    color: var(--up) !important;
}

[data-theme="dark"] .down::selection,
[data-theme="dark"] .down *::selection {
    color: var(--down) !important;
}

[data-theme="dark"] .up::-moz-selection,
[data-theme="dark"] .up *::-moz-selection {
    color: var(--up) !important;
}

[data-theme="dark"] .down::-moz-selection,
[data-theme="dark"] .down *::-moz-selection {
    color: var(--down) !important;
}

/* ── 訂閱頁 ── */
.pricing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}
.pricing-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 24px;
    position: relative;
    box-shadow: var(--shadow-sm);
}
.pricing-card-highlight {
    border-color: #1971c2;
    box-shadow: 0 0 0 2px #1971c233, var(--shadow-md);
}
.pricing-card-coming { opacity: 0.75; }
.pricing-badge-top {
    position: absolute; top: -12px; left: 50%;
    transform: translateX(-50%);
    background: #1971c2; color: white;
    font-size: 12px; font-weight: 600;
    padding: 3px 14px; border-radius: 20px;
}
.pricing-badge-dev { background: #868e96; }
.pricing-tier { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.pricing-price { margin-bottom: 24px; }
.pricing-amount { font-size: 36px; font-weight: 700; }
.pricing-period { font-size: 14px; color: var(--text-3); margin-left: 4px; }
.pricing-features {
    list-style: none; padding: 0; margin: 0 0 24px;
    display: flex; flex-direction: column; gap: 8px;
}
.pricing-features li { font-size: 14px; }
.feat-no   { color: var(--text-3); }
.feat-dev  { color: var(--text-3); font-style: italic; }
.pricing-btn {
    display: block; width: 100%;
    padding: 10px; text-align: center;
    border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 500;
    border: 1px solid var(--border);
    background: var(--bg-hover);
    color: var(--text); cursor: pointer;
    text-decoration: none;
    transition: opacity 0.15s;
}
.pricing-btn:hover { opacity: 0.8; text-decoration: none; }
.pricing-btn-primary {
    background: #1971c2; color: white;
    border-color: transparent;
}
.pricing-btn-disabled {
    opacity: 0.4; cursor: not-allowed;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--text-3);
    font-family: inherit;
    width: 100%; padding: 10px;
    border-radius: var(--radius-sm);
    font-size: 14px;
}
.pricing-current-badge {
    text-align: center; padding: 10px;
    font-size: 14px; color: var(--text-3);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
}
.pricing-donate {
    text-align: center;
    padding: 32px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-width: 400px;
    margin: 0 auto;
}
.pricing-donate h3 { margin-top: 0; }
.pricing-donate .pricing-btn { display: inline-block; width: auto; padding: 10px 32px; }

/* upgrade banner */
.upgrade-banner {
    background: #e7f5ff;
    color: #1971c2;
    border: 1px solid #a5d8ff;
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}
[data-theme="dark"] .upgrade-banner {
    background: #1a2a3a;
    border-color: #1971c2;
    color: #74c0fc;
}
.upgrade-banner a { font-weight: 600; margin-left: auto; }

/* locked tab */
.tab-locked { opacity: 0.5; cursor: pointer; }
.tab-locked:hover { opacity: 0.8; color: var(--text); }