/* style.css */
:root {
    /* 這裡的 brand 變數會被 HTML 行內動態覆蓋，此處僅為預設 fallback */
    --brand: #111827; 
    --brand-soft: rgba(17, 24, 39, 0.08);
    --primary-dark: #374151;
    --bg: #F6F8FB;
    --surface: #FFFFFF;
    --surface-2: #F1F5F9;
    --text-primary: #111827;
    --text-secondary: #374151;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --divider: #E2E8F0;
    --success: #15803D;
    --danger: #B91C1C;
    --warning: #B45309;
    --info: #1D4ED8;
    --primary: var(--brand);
    --accent: var(--brand-soft);
    --text: var(--text-primary);
    --text-light: var(--text-muted);
    --card: var(--surface);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; outline: none; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", sans-serif; line-height: 1.6; background: var(--bg); margin: 0; padding: 0; color: var(--text); padding-bottom: 80px; }
.header { background: var(--brand); padding: 10px 15px; color: #FFFFFF; position: sticky; top: 0; z-index: 50; box-shadow: 0 2px 10px rgba(0,0,0,0.15); display: flex; justify-content: space-between; align-items: center; height: 56px; }
.brand { font-size: 18px; font-weight: 800; letter-spacing: 0.5px; cursor: pointer; user-select: none; display: flex; align-items: center; gap: 8px; overflow: hidden; }
.brand-text-group { display: flex; flex-direction: row; align-items: baseline; gap: 8px; white-space: nowrap; }
.db-info, #dbStatus { font-size: 12px; color: rgba(255, 255, 255, 0.9) !important; font-weight: 500; margin-top: 0; }
@media (max-width: 360px) { .db-info, #dbStatus { display: none; } }
.header-tools { display: flex; gap: 10px; }
.btn-icon { background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px; border-radius: 4px; transition: 0.2s; color: #FFFFFF !important; }
.btn-icon:hover { background: rgba(255, 255, 255, 0.2) !important; }
#adminBtn { opacity: 0.3 !important; transition: none !important; }
#adminBtn:hover, #adminBtn:active { opacity: 0.3 !important; background: none !important; }
.container { max-width: 1000px; margin: 0 auto; padding: 15px; }
.section { background: var(--card); margin-bottom: 24px; padding: 24px; border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,0.04); border: 1px solid var(--border); }
.sec-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; color: var(--text-primary); display: flex; align-items: center; gap: 8px; }
.sec-title::before { content: ''; width: 4px; height: 16px; background: var(--brand); border-radius: 2px; display: block; }
.filter-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 24px; }
.filter-btn { padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; text-align: center; font-size: 14px; font-weight: 600; color: var(--text-muted); cursor: pointer; transition: 0.2s; }
.filter-btn:hover { border-color: var(--brand); color: var(--brand); }
.filter-btn.active { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); font-weight: bold; }

/* --- 已升級：區域標籤膠囊化 --- */
.region-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.region-tab { padding: 8px 16px; font-size: 14px; background: var(--surface); color: var(--text-muted); border: 1px solid var(--border); border-radius: 20px; cursor: pointer; transition: 0.2s; white-space: nowrap; }
.region-tab:hover { border-color: var(--brand); color: var(--brand); }
.region-tab.active { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); font-weight: 600; }

.dist-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
@media (max-width: 480px) { .dist-grid { grid-template-columns: repeat(3, 1fr); } }
.dist-item { font-size: 13px; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; text-align: center; cursor: pointer; transition: 0.1s; user-select: none; color: var(--text-muted); }
.dist-item.checked { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); font-weight: 600; }
.input-group { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; }
.form-input { flex: 1; padding: 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: var(--surface); color: var(--text-primary); transition: 0.2s; min-width: 0; }
.form-input:focus { border-color: var(--brand); }
.price-range-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; margin-bottom: 16px; }
.price-range-sep { color: var(--text-muted); white-space: nowrap; text-align: center; font-size: 13px; }
.autocomplete-wrapper { position: relative; width: 100%; }
.suggestions-list { position: absolute; top: 100%; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-top: none; border-radius: 0 0 8px 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); max-height: 300px; overflow-y: auto; z-index: 1000; display: none; }
.suggestion-item { padding: 12px 16px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--divider); transition: background 0.2s; }
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: var(--surface-2); }
.s-text { font-size: 14px; color: var(--text-primary); font-weight: 500; }
.s-tag { font-size: 11px; padding: 2px 6px; border-radius: 4px; background: var(--surface-2); color: var(--text-secondary); }
.s-tag.type-name { background: var(--brand-soft); color: var(--brand); }
.btn-analyze { width: 100%; padding: 14px; background: var(--brand); color: #ffffff; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; transition: 0.2s; }
.btn-analyze:hover { filter: brightness(0.92); }

/* --- 已升級：雙按鈕群組排版與清空按鈕樣式 (1:1 對稱高級感) --- */
.btn-analyze-group { display: flex; gap: 10px; width: 100%; }
.btn-analyze-group .btn-analyze { flex: 1; width: auto; margin: 0; }
.btn-clear { flex: 1; padding: 14px; background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--border); border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; transition: 0.2s; }
.btn-clear:hover { background: var(--border); color: var(--text-primary); }

.dash-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.dash-head { display: flex; align-items: center; justify-content: center; margin-bottom: 12px; font-weight: 600; color: var(--text-primary); font-size: 15px; border-bottom: 1px solid var(--divider); padding-bottom: 8px; }
.dash-head span { margin-left: 6px; font-size: 12px; color: var(--text-muted); font-weight: normal; }
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--divider); font-size: 13px; }
.stat-row:last-child { border-bottom: none; }
.stat-lbl { color: var(--text-muted); }
.stat-val { font-weight: 600; color: var(--text-primary); font-family: monospace; font-size: 14px; }
.stat-row.highlight { background: var(--surface-2); border-radius: 4px; padding: 8px; margin: 0 -8px; border-bottom: none; }
.stat-row.highlight .stat-val { color: var(--brand); font-weight: 700; }
.val-max { color: var(--danger); }
.val-min { color: var(--success); }
.dash-top-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.tooltip-wrap { position: relative; display: inline-flex; align-items: center; cursor: help; border-bottom: 1px dashed var(--text-muted); padding-bottom: 2px; }
.tooltip-content { visibility: hidden; width: 280px; background-color: rgba(17, 24, 39, 0.95); color: #fff; text-align: left; border-radius: 8px; padding: 12px; position: absolute; z-index: 100; bottom: 130%; left: 50%; transform: translateX(-50%) translateY(10px); font-size: 13px; line-height: 1.6; font-weight: normal; opacity: 0; transition: opacity 0.2s, transform 0.2s; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); backdrop-filter: blur(4px); }
.tooltip-content::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -6px; border-width: 6px; border-style: solid; border-color: rgba(17, 24, 39, 0.95) transparent transparent transparent; }
.tooltip-wrap:hover .tooltip-content, .tooltip-wrap:active .tooltip-content { visibility: visible; opacity: 1; transform: translateX(-50%) translateY(0); }
.leaderboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.lb-card { padding: 12px; border-radius: 8px; background: var(--surface); }
.lb-row { display: flex; justify-content: space-between; font-size: 12px; padding: 6px 0; border-bottom: 1px dashed var(--divider); align-items: center; }
.lb-row:last-child { border-bottom: none; }
.lb-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 65%; font-weight: 500; }
.project-profile { background: linear-gradient(135deg, var(--brand-soft), var(--surface)); border: 1px solid var(--brand); padding: 16px; border-radius: 8px; margin-bottom: 16px; box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
.chart-section { margin-top: 24px; }
.chart-container { height: 400px; margin-bottom: 32px; border: 1px solid var(--border); border-radius: 8px; padding: 16px; background: var(--surface); }
.hot-topics { display: flex; flex-wrap: wrap; gap: 8px; margin: 24px 0; justify-content: center; }
.hot-pill { padding: 6px 12px; background: var(--surface); border: 1px solid var(--brand); color: var(--brand); border-radius: 20px; font-size: 12px; cursor: pointer; font-weight: 500; transition: 0.2s; }
.hot-pill:hover { background: var(--brand); color: #ffffff; }
.view-toggle { display: flex; justify-content: flex-end; margin-bottom: 16px; gap: 8px; }
.toggle-btn { padding: 6px 12px; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.toggle-btn.active { background: var(--surface-2); color: var(--text-primary); border-color: var(--border); font-weight: 600; }
.data-table { width: 100%; min-width: 800px; border-collapse: collapse; font-size: 13px; background: var(--surface); border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.data-table th, .data-table td { min-width: 60px; padding: 12px 8px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--divider); }
.data-table th { position: sticky; top: 0; background: var(--surface-2); z-index: 11; font-weight: 600; color: var(--text-secondary); cursor: pointer; }
.data-table th:first-child, .data-table td:first-child { position: sticky; left: 0; z-index: 10; background: inherit; border-right: 1px solid var(--divider); }
.data-table th:first-child { background: var(--surface-2); }
.data-table td:first-child { background: var(--surface); }
.data-table tr:hover td { background: var(--bg); }
.modal .data-table { min-width: auto; width: 100%; }
.modal .data-table th { width: 30%; white-space: normal; background: var(--surface-2); color: var(--text-secondary); }
.modal .data-table td { white-space: normal; word-break: break-all; }
.pagination-bar { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(8px); padding: 8px 16px; border-radius: 50px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); display: none; gap: 16px; align-items: center; z-index: 90; border: 1px solid var(--border); width: 90%; max-width: 400px; justify-content: space-between; }
.page-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text-primary); font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: 0.2s; }
.page-btn:active { transform: scale(0.95); background: var(--surface-2); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.page-info { font-size: 14px; font-weight: 600; font-family: monospace; color: var(--text-primary); }
.modal { display: none; position: fixed; inset: 0; background: rgba(17,24,39,0.7); z-index: 100; justify-content: center; align-items: center; backdrop-filter: blur(4px); }
.modal-box { background: var(--surface); width: 90%; max-width: 500px; border-radius: 8px; padding: 24px; box-shadow: 0 10px 25px rgba(0,0,0,0.1); animation: popIn 0.2s ease-out; display: flex; flex-direction: column; max-height: 85vh; position: relative; }
.modal-body { overflow-y: auto; margin: 16px 0; }
@keyframes popIn { from { transform: scale(0.98); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.card-list { display: grid; gap: 16px; }
.data-card { background: var(--surface); padding: 16px; border-radius: 8px; border: 1px solid var(--border); box-shadow: 0 1px 2px rgba(0,0,0,0.04); cursor: pointer; transition: 0.2s; }
.data-card:hover { border-color: var(--brand); box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); }
.loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.9); z-index: 200; display: none; flex-direction: column; justify-content: center; align-items: center; backdrop-filter: blur(4px); }
.spinner { width: 40px; height: 40px; border: 3px solid var(--surface-2); border-top: 3px solid var(--brand); border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 16px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.site-footer { margin-top: 40px; padding: 30px 15px 40px 15px; background: var(--surface); border-top: 1px solid var(--border); text-align: center; }
.footer-nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-bottom: 20px; max-width: 800px; margin-left: auto; margin-right: auto; }
.footer-nav a { color: var(--text-secondary); text-decoration: none; font-size: 13px; padding: 6px 14px 6px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; transition: all 0.2s ease-out; font-weight: 500; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.footer-nav a:hover { transform: translateY(-2px); box-shadow: 0 4px 6px rgba(0,0,0,0.08); background: var(--surface-2); color: var(--text-primary); }
.link-park { border-left: 4px solid #0E7490 !important; }
.link-ty   { border-left: 4px solid #1E3A8A !important; }
.link-hc   { border-left: 4px solid #065F46 !important; }
.link-tc   { border-left: 4px solid #A16207 !important; }
.link-tn   { border-left: 4px solid #C2410C !important; }
.link-kh   { border-left: 4px solid #991B1B !important; }
.footer-copyright { font-size: 12px; color: var(--text-muted); line-height: 1.8; }
.footer-copyright a { color: var(--text-muted); text-decoration: underline; text-underline-offset: 2px; transition: color 0.2s; }
.footer-copyright a:hover { color: var(--brand); }
@media (max-width: 600px) {
    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 8px 4px; }
    .section { padding: 16px; }
    .footer-nav { gap: 8px; }
    .footer-nav a { font-size: 12px; padding: 6px 10px 6px 8px; }
    .dash-top-row { grid-template-columns: 1fr 1fr; gap: 10px; }
    .leaderboard-grid { grid-template-columns: 1fr; gap: 10px; }
    .dash-card { padding: 12px; }
    .stat-lbl { font-size: 11px; }
    .stat-val { font-size: 13px; }
    .dash-head { font-size: 13px; margin-bottom: 8px; padding-bottom: 6px; }
    .dash-head span { font-size: 11px; }
}
