/* ===================================================================
 * 台股量化回測站 — app.css
 * 風格:灰階極簡,mobile-first 響應式,家族 tag 點綴色
 * =================================================================== */

/* ---- Reset / 基礎 ---- */
*,
*::before,
*::after { box-sizing: border-box; }

html { font-size: 15px; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
                 "Noto Sans TC", "Microsoft JhengHei", sans-serif;
    color: #1f2937;
    background: #f5f5f5;
    line-height: 1.5;
}

h1, h2, h3 { margin: 0 0 0.5em; color: #111827; line-height: 1.3; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75em; }
.muted { color: #6b7280; }
.small { font-size: 0.85em; }
.hint { color: #6b7280; font-size: 0.9rem; margin: 0.25em 0; }

a { color: #3b82f6; text-decoration: none; }
a:hover { text-decoration: underline; }

input, select, button, textarea {
    font: inherit;
    color: inherit;
}

/* ---- 按鈕 ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0.5em 1.2em;
    border: 1px solid transparent;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.95rem;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover { background: #f3f4f6; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
}
.btn-primary:hover { background: #2563eb; border-color: #2563eb; text-decoration: none; color: #fff; }
.btn-text {
    border: none;
    background: transparent;
    padding: 0.3em 0.6em;
    color: #6b7280;
    min-height: auto;
}
.btn-text:hover { color: #1f2937; background: #f3f4f6; }
.btn-run { min-width: 160px; font-weight: 600; }

.btn-group { display: inline-flex; gap: 0; }
.btn-group button {
    min-height: 44px;
    padding: 0.5em 1.2em;
    border: 1px solid #d1d5db;
    background: #fff;
    cursor: pointer;
}
.btn-group button:first-child { border-radius: 6px 0 0 6px; }
.btn-group button:last-child  { border-radius: 0 6px 6px 0; border-left: none; }
.btn-group button.active {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
}

/* ---- Header ---- */
.site-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    flex-wrap: wrap;
}
.site-brand {
    font-weight: 700;
    font-size: 1.05rem;
    color: #111827;
}
.site-brand:hover { text-decoration: none; }
.site-nav {
    display: flex;
    gap: 0.25rem;
    flex: 1;
    flex-wrap: wrap;
}
.site-nav a {
    padding: 0.4em 0.75em;
    border-radius: 6px;
    color: #4b5563;
}
.site-nav a:hover { background: #f3f4f6; text-decoration: none; }
.site-nav a.active { background: #eef2ff; color: #1e3a8a; }
.site-user { display: flex; align-items: center; gap: 0.5rem; }
.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3em 0.6em;
    background: #f3f4f6;
    border-radius: 6px;
    font-size: 0.9rem;
}
.plan-badge {
    padding: 0.1em 0.5em;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.plan-badge.plan-free { background: #e5e7eb; color: #4b5563; }
.plan-badge.plan-pro  { background: #dbeafe; color: #1e40af; }

/* ---- Main ---- */
.site-main {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.25rem 1rem;
}
.page-header { margin-bottom: 1.5rem; }
.section-title { margin: 1.5rem 0 0.5rem; }

/* ---- 表單 ---- */
.form-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}
.form-row > label:first-child {
    min-width: 6.5em;
    font-weight: 500;
    color: #374151;
}
input[type="text"],
input[type="number"],
input[type="date"],
select {
    padding: 0.5em 0.75em;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    min-height: 44px;
}
input[type="range"] { flex: 1; max-width: 200px; }
.date-range { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.date-sep { color: #9ca3af; }
.radio {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-right: 0.5rem;
    min-height: 44px;
    cursor: pointer;
}
.loading-skel { color: #9ca3af; font-style: italic; }
.error-msg {
    color: #dc2626;
    cursor: pointer;
    text-decoration: underline dashed;
}

/* ---- 指標卡片 ---- */
.indicator-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}
.indicator-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.indicator-card.selected { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.indicator-card.disabled { opacity: 0.5; }
.indicator-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    cursor: pointer;
}
.indicator-name { font-size: 1.05rem; }
.indicator-desc { margin: 0.5rem 0 0; }
.indicator-params {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed #e5e7eb;
}
.param-row {
    display: grid;
    grid-template-columns: 5em 6em 1fr;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

/* ---- Family tag 色系(家族點綴色) ---- */
.family-tag {
    display: inline-block;
    padding: 0.1em 0.5em;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}
.family-orange { background: #ffedd5; color: #c2410c; } /* 反轉 */
.family-green  { background: #d1fae5; color: #047857; } /* 趨勢 */
.family-blue   { background: #dbeafe; color: #1e40af; } /* 量能 */
.family-purple { background: #ede9fe; color: #5b21b6; } /* 籌碼 */

/* ---- 組合邏輯 ---- */
.logic-section {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

/* ---- 執行列 ---- */
.action-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1.5rem 0;
    flex-wrap: wrap;
}

/* ---- 服務卡片(TG 推播引流等) ---- */
.service-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1.25rem;
    margin-top: 2rem;
}
.service-card ul { margin: 0.5em 0 0.75em; padding-left: 1.5em; color: #4b5563; }

/* ---- Ad slot 佔位(M4 上架前填 AdSense) ---- */
.ad-slot {
    max-width: 960px;
    margin: 0 auto;
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    font-size: 0.8rem;
    background: #f9fafb;
    border: 1px dashed #e5e7eb;
}
.ad-slot::before { content: "Ad slot (reserved)"; }
.affiliate-slot { max-width: 960px; margin: 0 auto; }

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17,24,39,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.modal-body {
    background: #fff;
    border-radius: 10px;
    padding: 1.5rem;
    max-width: min(600px, 80vw);
    width: 100%;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
    color: #9ca3af;
    width: 36px;
    height: 36px;
    border-radius: 50%;
}
.modal-close:hover { background: #f3f4f6; color: #1f2937; }
.modal-icon { font-size: 3rem; text-align: center; margin-bottom: 0.5rem; }
.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1rem;
    flex-wrap: wrap;
}
.modal-actions-stack { flex-direction: column; align-items: stretch; }
.modal-actions-stack .btn { width: 100%; }

/* ---- Footer ---- */
.site-footer {
    max-width: 960px;
    margin: 2rem auto 0;
    padding: 1.25rem 1rem;
    border-top: 1px solid #e5e7eb;
    color: #6b7280;
    font-size: 0.8rem;
    line-height: 1.5;
}
.site-footer p { margin: 0.2em 0; }

/* =========================================================
 * 響應式:桌面(>= 768px)
 * ========================================================= */
@media (min-width: 768px) {
    html { font-size: 16px; }
    .indicator-grid { grid-template-columns: 1fr 1fr; }
    .site-header { padding: 0.75rem 2rem; }
    .site-main { padding: 1.5rem 2rem; }
    .site-footer { padding: 1.5rem 2rem; }
    .modal-body { max-width: min(600px, 80vw); }
}

@media (min-width: 1024px) {
    html { font-size: 16px; }
}

@media (max-width: 480px) {
    html { font-size: 14px; }
    .site-header { padding: 0.5rem 0.75rem; gap: 0.5rem; }
    .site-nav a { padding: 0.3em 0.5em; font-size: 0.9rem; }
    .modal-body { padding: 1rem; }
    .form-row > label:first-child { min-width: 100%; }
    .param-row { grid-template-columns: 4em 5em 1fr; font-size: 0.9rem; }
}

/* Task 19 — 交易明細表格 ↔ 權益圖 marker 連動時 row highlight */
.highlight-flash {
    animation: flash-bg 1.5s ease-out;
}
@keyframes flash-bg {
    0% { background-color: #fef3c7; }
    100% { background-color: transparent; }
}

[x-cloak] { display: none !important; }
