/* BTC 上課管理：共用樣式（蛋黃主視覺） */
:root {
    color-scheme: light;
    --yolk: #FBC82E;
    --yolk-deep: #E9A800;
    --yolk-soft: #FFF4CC;
    --cream: #FFFBEF;
    --ink: #201909;
    --ink-soft: #6B5A3A;
    --muted: #9A8A68;
    --line: #F0E3BC;
    --surface: #FFFFFF;
    --ok: #16A34A;
    --ok-soft: #DCFCE7;
    --due: #DC2626;
    --due-soft: #FEE2E2;
    --warn-text: #7A5600;
    /* 圖表色（已通過色盲與對比驗證） */
    --series-income: #C98500;
    --series-expense: #6250D6;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
    background: var(--cream); color: var(--ink); min-height: 100vh;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- 頂部列 ---------- */
.top {
    position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--yolk); box-shadow: 0 2px 0 var(--yolk-deep);
}
.top .icon-btn {
    display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 0; cursor: pointer;
    background: rgba(255,255,255,.55); text-decoration: none; flex: none;
}
.top .logo { width: 40px; height: 40px; border-radius: 50%; background: #fff; padding: 2px; flex: none; }
.top h1 { font-size: 19px; margin: 0; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.pill { background: var(--ink); color: var(--yolk); border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 14px; white-space: nowrap; }
.pill b { font-size: 18px; margin: 0 2px; }

/* ---------- 選單抽屜 ---------- */
.drawer-bg { position: fixed; inset: 0; background: rgba(32,25,9,.4); z-index: 60; display: none; }
.drawer {
    position: fixed; top: 0; bottom: 0; left: 0; width: min(300px, 84vw); background: #fff; z-index: 61;
    transform: translateX(-102%); transition: transform .2s ease; display: flex; flex-direction: column;
    padding-top: env(safe-area-inset-top);
}
body.menu-open .drawer { transform: none; }
body.menu-open .drawer-bg { display: block; }
.drawer .me { display: flex; gap: 12px; align-items: center; padding: 20px 18px; background: var(--yolk-soft); }
.drawer .me img { width: 48px; height: 48px; border-radius: 50%; background: #fff; }
.drawer .me b { display: block; font-size: 17px; }
.drawer .me span { font-size: 13px; color: var(--ink-soft); }
.drawer nav { padding: 8px; overflow-y: auto; flex: 1; }
.drawer nav .group { font-size: 12px; color: var(--muted); padding: 14px 12px 6px; font-weight: 700; letter-spacing: 1px; }
.drawer nav a {
    display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; text-decoration: none; font-weight: 600;
}
.drawer nav a:hover { background: var(--cream); }
.drawer nav a.active { background: var(--yolk); }
.drawer nav a svg { flex: none; }

/* ---------- 版面 ---------- */
main { max-width: 760px; margin: 0 auto; padding: 16px; }
.card { background: var(--surface); border: 2px solid var(--line); border-radius: 20px; padding: 16px; }
.card + .card, .section + .section { margin-top: 16px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 22px 4px 10px; }
.section-title h2 { font-size: 17px; margin: 0; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }

/* ---------- 按鈕 ---------- */
.btn {
    appearance: none; border: 0; cursor: pointer; font-weight: 800; border-radius: 14px; padding: 12px 18px; font-size: 16px;
    text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .08s ease;
    white-space: nowrap;
}
.btn:active { transform: translateY(2px); }
.btn-yolk { background: var(--yolk); color: var(--ink); box-shadow: 0 3px 0 var(--yolk-deep); }
.btn-ink { background: var(--ink); color: var(--yolk); }
.btn-white { background: #fff; color: var(--ink); border: 2px solid var(--line); }
.btn-due { background: var(--due); color: #fff; box-shadow: 0 3px 0 #991B1B; }
.btn-ghost { background: transparent; color: var(--ink-soft); padding: 8px 10px; }
.btn-lg { padding: 16px 20px; font-size: 18px; border-radius: 16px; }
.btn-block { width: 100%; }

/* ---------- 標籤 ---------- */
.chip { display: inline-block; border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.chip-yolk { background: var(--yolk-soft); color: var(--warn-text); }
.chip-due { background: var(--due); color: #fff; }
.chip-ok { background: var(--ok-soft); color: #166534; }
.chip-gray { background: #F3F0E8; color: var(--ink-soft); }

/* ---------- 表單 ---------- */
.field { display: block; margin-bottom: 14px; min-width: 0; }
.field > span { display: block; font-size: 14px; font-weight: 700; margin-bottom: 6px; color: var(--ink-soft); }
.input {
    width: 100%; min-width: 0; padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; background: #fff; font-size: 16px; outline: none;
}
.input:focus { border-color: var(--yolk-deep); box-shadow: 0 0 0 3px var(--yolk-soft); }
.search { position: relative; min-width: 0; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search .input { padding-left: 42px; font-size: 17px; }
.seg { display: flex; background: #F3EBD2; border-radius: 12px; padding: 4px; gap: 4px; overflow-x: auto; }
.seg button, .seg label {
    flex: 1 0 auto; border: 0; background: transparent; border-radius: 9px; padding: 9px 6px; font-weight: 700; font-size: 14px;
    cursor: pointer; white-space: nowrap; text-align: center; color: var(--ink-soft);
}
.seg button.on, .seg input:checked + label { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg .n { display: inline-block; min-width: 18px; margin-left: 3px; padding: 0 5px; border-radius: 999px; background: var(--line); font-size: 12px; }
.seg button.on .n { background: var(--yolk); }

/* ---------- 進度條 ---------- */
.dots { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; }
.dots span { height: 6px; border-radius: 3px; background: var(--line); }
.dots span.on { background: var(--yolk); }
.dots span.now { background: var(--yolk-deep); }
.dots.due span.now { background: var(--due); }

/* ---------- 列表 ---------- */
.list { list-style: none; margin: 0; padding: 0; background: #fff; border: 2px solid var(--line); border-radius: 20px; overflow: hidden; }
.list > li { padding: 14px 16px; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list .empty { text-align: center; color: var(--ink-soft); padding: 28px 16px; }

/* ---------- 提示 ---------- */
.banner { border-radius: 16px; padding: 14px 16px; font-weight: 700; display: flex; gap: 10px; align-items: center; }
.banner-ok { background: var(--ok-soft); color: #166534; }
.banner-err { background: var(--due-soft); color: #991B1B; }
.banner-due { background: var(--due); color: #fff; }
.banner-warn { background: var(--yolk-soft); color: var(--warn-text); }
.toast {
    position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 80;
    background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 700; box-shadow: 0 10px 30px rgba(0,0,0,.25);
    max-width: calc(100vw - 32px);
}

/* ---------- 對話框 ---------- */
.modal { position: fixed; inset: 0; z-index: 70; background: rgba(32,25,9,.45); display: none; align-items: flex-end; justify-content: center; padding: 16px; }
.modal.show { display: flex; }
.modal .sheet {
    width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto; background: #fff; border-radius: 24px; padding: 20px;
    animation: up .2s ease;
}
.modal .sheet h3 { margin: 0 0 14px; font-size: 20px; display: flex; justify-content: space-between; align-items: center; }
@media (min-width: 640px) { .modal { align-items: center; } }
@keyframes up { from { transform: translateY(24px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---------- 統計 ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: #fff; border: 2px solid var(--line); border-radius: 18px; padding: 14px 16px; }
.kpi .label { font-size: 13px; color: var(--ink-soft); font-weight: 700; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 900; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.hero { background: var(--ink); border-color: var(--ink); color: #fff; }
.kpi.hero .label, .kpi.hero .sub { color: var(--yolk-soft); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- 圖表 ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-soft); margin-bottom: 8px; }
.chart .legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-tip {
    position: fixed; z-index: 90; pointer-events: none; background: var(--ink); color: #fff; border-radius: 12px;
    padding: 10px 12px; font-size: 13px; line-height: 1.6; box-shadow: 0 8px 24px rgba(0,0,0,.25); min-width: 140px;
}
.chart-tip b { color: var(--yolk); }
.chart-tip .row { display: flex; justify-content: space-between; gap: 14px; }
.hbar { display: grid; grid-template-columns: minmax(80px, 30%) 1fr 92px; gap: 10px; align-items: center; padding: 6px 0; }
.hbar .track { height: 12px; background: var(--cream); border-radius: 6px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 0 6px 6px 0; }
.hbar > b { text-align: right; }
.hbar .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 相機（掃碼新增） ---------- */
.camera { position: relative; border-radius: 24px; overflow: hidden; background: var(--ink); aspect-ratio: 1 / 1; width: 100%; max-width: 520px; margin: 0 auto; box-shadow: 0 6px 0 var(--yolk-deep); }
#reader { width: 100%; height: 100%; }
#reader video { object-fit: cover; width: 100% !important; height: 100% !important; }
#reader img[alt="Info icon"], #reader__dashboard_section_csr span, #reader__header_message { display: none !important; }
.camera .idle { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; color: var(--yolk-soft); text-align: center; padding: 24px; }
.camera .frame { position: absolute; inset: 14%; border-radius: 20px; pointer-events: none; box-shadow: 0 0 0 9999px rgba(32,25,9,.35); border: 4px solid var(--yolk); }

/* ---------- 月曆 ---------- */
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.calendar .dow { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.calendar button { aspect-ratio: 1; border: 2px solid var(--line); background: #fff; border-radius: 12px; font-weight: 700; cursor: pointer; font-size: 15px; }
.calendar button.on { background: var(--yolk); border-color: var(--yolk-deep); }
.calendar button.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.calendar button:disabled { opacity: .5; cursor: wait; }

@media (max-width: 400px) {
    .seg button { font-size: 13px; padding: 8px 4px; }
    .btn-lg { padding: 14px 14px; font-size: 17px; }
}
input[type="date"].input { -webkit-appearance: none; appearance: none; min-height: 48px; }

/* ---------- 金額文字色（收入／支出，已確認對比度 ≥ 4.5:1） ---------- */
.amt-in { color: #8A5A00; }
.amt-out { color: #4B3BB8; }
.voided { opacity: .6; }
.voided .strike { text-decoration: line-through; }
.lock { color: var(--muted); display: inline-grid; place-items: center; width: 40px; height: 40px; }
.history { margin-top: 8px; }
.history summary { cursor: pointer; font-size: 13px; color: var(--ink-soft); font-weight: 700; }
.history ol { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--ink-soft); line-height: 1.6; }
