/* ===== GURA 主題裝飾（自製鯊魚／海洋向量，非官方角色圖） ===== */
/* 背景氣泡 */
[data-theme="gura"] body {
    background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='150'%20height='150'%20viewBox='0%200%20150%20150'%3E%3Cg%20fill='none'%20stroke='%23aadcec'%20stroke-width='2'%3E%3Ccircle%20cx='28'%20cy='38'%20r='7'/%3E%3Ccircle%20cx='104'%20cy='86'%20r='12'/%3E%3Ccircle%20cx='66'%20cy='124'%20r='5'/%3E%3Ccircle%20cx='128'%20cy='28'%20r='4'/%3E%3C/g%3E%3C/svg%3E");
    background-attachment: fixed;
}
/* Hero：你的 Gura 橫幅圖 + 左側深藍漸層蓋住讓白字清楚 */
[data-theme="gura"] .hero {
    min-height: 240px;
    display: flex; flex-direction: column; justify-content: center;
    background-image:
        linear-gradient(90deg, rgba(13,70,90,.94) 0%, rgba(13,70,90,.82) 34%, rgba(13,70,90,.30) 60%, rgba(13,70,90,0) 82%),
        url("../img/gura/wide.jpg");
    background-repeat: no-repeat, no-repeat;
    background-position: center, right 35%;
    background-size: cover, cover;
}
/* 文字加陰影，疊在圖上仍清楚 */
[data-theme="gura"] .hero h1, [data-theme="gura"] .hero p { text-shadow: 0 1px 4px rgba(0,60,80,.45); }
[data-theme="gura"] .hero h1::after { content: " 🦈"; }

/* 登入頁：整頁 Gura 背景 */
[data-theme="gura"] body.auth-bg {
    background-image:
        linear-gradient(rgba(20,80,110,.35), rgba(20,80,110,.55)),
        url("../img/gura/g1.jpg");
    background-size: cover; background-position: center; background-attachment: fixed;
}
/* 登入卡片：半透明 + 毛玻璃，讓背景透出來又保持文字清楚 */
[data-theme="gura"] body.auth-bg .auth-card {
    background: rgba(255,255,255,.35);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    border-color: rgba(255,255,255,.6);
}

/* ===== OKAKORO 主題裝飾（自製肉球圖樣，非官方角色圖） ===== */
[data-theme="okakoro"] body {
    background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='170'%20height='170'%20viewBox='0%200%20170%20170'%3E%3Cg%20fill='%23e4daf4'%3E%3Cellipse%20cx='60'%20cy='82'%20rx='16'%20ry='12'/%3E%3Ccircle%20cx='42'%20cy='54'%20r='6'/%3E%3Ccircle%20cx='58'%20cy='46'%20r='6'/%3E%3Ccircle%20cx='76'%20cy='50'%20r='6'/%3E%3Ccircle%20cx='90'%20cy='64'%20r='5'/%3E%3C/g%3E%3C/svg%3E");
    background-attachment: fixed;
}
/* Hero：おかゆ×ころね 合照 + 左側深紫漸層蓋住讓白字清楚 */
[data-theme="okakoro"] .hero {
    min-height: 240px;
    display: flex; flex-direction: column; justify-content: center;
    background-image:
        linear-gradient(90deg, rgba(58,38,86,.94) 0%, rgba(58,38,86,.82) 34%, rgba(58,38,86,.30) 60%, rgba(58,38,86,0) 82%),
        url("../img/okakoro/hero.jpg");
    background-repeat: no-repeat, no-repeat;
    background-position: center, right center;
    background-size: cover, cover;
}
[data-theme="okakoro"] .hero h1, [data-theme="okakoro"] .hero p { text-shadow: 0 1px 4px rgba(30,10,50,.5); }
[data-theme="okakoro"] .hero h1::after { content: " 🐾"; }

/* 登入頁：整頁 OKAKORO 背景 */
[data-theme="okakoro"] body.auth-bg {
    background-image:
        linear-gradient(rgba(50,30,80,.35), rgba(50,30,80,.55)),
        url("../img/okakoro/login.jpg");
    background-size: cover; background-position: center 30%; background-attachment: fixed;
}
[data-theme="okakoro"] body.auth-bg .auth-card {
    background: rgba(255,255,255,.35);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    border-color: rgba(255,255,255,.6);
}

/* ===== 天峰藍主題（預設） ===== */
:root {
    --blue:       #5b9bd5;   /* 主色（天峰藍） */
    --blue-deep:  #4180b9;   /* hover / 深一階 */
    --blue-dark:  #356a9c;   /* 標題藍 */
    --blue-soft:  #eaf3fb;   /* 淺藍底（表頭、tag） */
    --bg:         #eef5fb;   /* 頁面背景 */
    --ink:        #21303d;   /* 主要文字 */
    --muted:      #7b8a97;   /* 次要文字 */
    --card:       #ffffff;
    --line:       #e1eaf2;   /* 邊線 */
    --line-in:    #cfe0ef;   /* 輸入框邊線 */
    --hero-a:     #6aa9de;   /* Hero 漸層起 */
    --hero-b:     #8fc0e8;   /* Hero 漸層迄 */
}

/* ===== GURA 主題（Gawr Gura 鯊魚青藍） ===== */
[data-theme="gura"] {
    --blue:       #2ba6cc;
    --blue-deep:  #1f8bb0;
    --blue-dark:  #14657f;
    --blue-soft:  #e2f6fb;
    --bg:         #e9f7fb;
    --ink:        #16323d;
    --muted:      #6f8891;
    --card:       #ffffff;
    --line:       #d1ecf3;
    --line-in:    #bde2ec;
    --hero-a:     #37c1dd;   /* 明亮鯊魚青 */
    --hero-b:     #86e6ef;
}

/* ===== OKAKORO 主題（おかゆ紫丁香 + ころね暖色） ===== */
[data-theme="okakoro"] {
    --blue:       #7d61c6;
    --blue-deep:  #684cae;
    --blue-dark:  #503c86;
    --blue-soft:  #efeafb;
    --bg:         #f3effb;
    --ink:        #2a2440;
    --muted:      #837b96;
    --card:       #ffffff;
    --line:       #e6def4;
    --line-in:    #d6c9ee;
    --hero-a:     #9a7fd6;   /* 丁香紫 */
    --hero-b:     #c99bd0;   /* 帶點暖粉 */
}

* { box-sizing: border-box; }
body {
    font-family: "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
    margin: 0; background: var(--bg); color: var(--ink);
}

/* 導覽列 */
.topbar {
    background: linear-gradient(135deg, var(--blue), var(--blue-deep));
    color: #fff; padding: 14px 24px;
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: 0 2px 8px rgba(53,106,156,.18);
}
.topbar a { color: #fff; text-decoration: none; margin-left: 18px; opacity: .92; }
.topbar a:hover { opacity: 1; text-decoration: underline; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: .5px; white-space: nowrap; flex-shrink: 0; }

.container { max-width: 1080px; margin: 32px auto; padding: 0 16px; }
.card {
    background: var(--card); border: 1px solid var(--line); border-radius: 14px;
    padding: 26px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(53,106,156,.06);
}
.auth-card { max-width: 420px; margin: 64px auto; }
/* 登入頁：卡片貼齊底部，頁面維持一個視窗高，背景不會被撐大 */
body.auth-bg { min-height: 100vh; display: flex; flex-direction: column; justify-content: flex-end; }
body.auth-bg .auth-card { margin: 0 auto 48px; }
h1 { font-size: 22px; margin: 0 0 20px; }
h2 { font-size: 17px; margin: 0 0 14px; color: var(--blue-dark); }
label { display: block; font-size: 14px; margin: 14px 0 6px; font-weight: 600; }
input, select {
    width: 100%; padding: 10px 12px; border: 1px solid var(--line-in);
    border-radius: 8px; font-size: 15px; background: #fff;
}
input:focus, select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(91,155,213,.18); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.btn {
    display: inline-block; margin-top: 20px; padding: 11px 22px;
    background: var(--blue); color: #fff; border: none; border-radius: 8px;
    font-size: 15px; cursor: pointer; text-decoration: none; transition: background .15s;
}
.btn:hover { background: var(--blue-deep); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--blue-deep); border: 1px solid var(--blue); }
.btn-ghost:hover { background: var(--blue-soft); }
.msg { padding: 11px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; }
.msg-ok { background: #e1f5ee; color: #0f6e56; }
.msg-err { background: #faece7; color: #993c1d; }
.field-err { color: #d4537e; font-size: 13px; margin-top: 4px; }
.row { display: flex; gap: 16px; }
.row > div { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }
table.kv { width: 100%; border-collapse: collapse; }
table.kv td { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
table.kv td:first-child { color: var(--muted); width: 120px; }
.links { margin-top: 16px; text-align: center; font-size: 14px; }
.links a { color: var(--blue-deep); }

/* 頂列大頭貼 */
.nav-avatar-link { display: inline-flex; margin-left: 16px; }
.nav-avatar {
    width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
    border: 2px solid rgba(255,255,255,.7); vertical-align: middle; background: #fff;
    display: block;   /* 避免 inline 圖片底部空隙把列撐高 */
}
/* 個人資料頁大頭貼 */
.avatar-lg {
    width: 96px; height: 96px; border-radius: 50%; object-fit: cover;
    border: 3px solid var(--line); background: #fff;
}
.avatar-empty {
    display: flex; align-items: center; justify-content: center;
    color: #b6c2cd; font-size: 14px; background: var(--blue-soft);
}

/* 導覽連結 */
.navlinks { display: flex; align-items: center; flex-wrap: wrap; }
.navlinks > a, .navtop { margin-left: 16px; font-size: 14px; color: #fff; }
.navlinks > a.on, .navtop.on { font-weight: 700; text-decoration: underline; }
a.brand { color: #fff; text-decoration: none; }

/* 漢堡按鈕（僅手機顯示） */
.nav-toggle {
    display: none; background: none; border: none; color: #fff;
    font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 6px;
}

/* 下拉群組 */
.navgroup { position: relative; display: inline-block; }
.navtop { cursor: pointer; opacity: .92; user-select: none; }
.navtop:hover { opacity: 1; }
.navmenu {
    display: none; position: absolute; top: 100%; left: 16px; margin-top: 8px;
    background: #fff; border: 1px solid var(--line); border-radius: 10px;
    box-shadow: 0 8px 24px rgba(53,106,156,.18); padding: 6px 0; min-width: 168px; z-index: 60;
}
/* 點擊開啟（不使用 hover，避免滑開就消失）；最右邊群組靠右對齊避免超出畫面 */
.navgroup.open .navmenu { display: block; }
.navgroup-right .navmenu { left: auto; right: 0; }
.navmenu a {
    display: block; margin: 0; padding: 9px 18px; font-size: 14px;
    color: var(--ink); opacity: 1; white-space: nowrap;
}
.navmenu a:hover { background: var(--blue-soft); text-decoration: none; }
.navmenu a.on { font-weight: 700; color: var(--blue-deep); text-decoration: none; }
.navmenu-label {
    display: block; padding: 8px 18px 4px; margin-top: 4px;
    font-size: 12px; color: var(--muted); border-top: 1px solid var(--line);
}

/* 手機：☰ 漢堡選單，點開才展開；平常只顯示品牌 + 按鈕，列高不變大 */
@media (max-width: 700px) {
    .topbar { flex-wrap: wrap; padding: 12px 16px; }
    .nav-toggle { display: inline-block; }
    .navlinks {
        display: none; width: 100%; flex-direction: column; align-items: flex-start;
        row-gap: 2px; margin-top: 10px;
    }
    .topbar.nav-open .navlinks { display: flex; }
    .navlinks > a, .navtop { margin: 0; padding: 8px 0; }
    /* 群組與子選單：就地往下展開、佔整行，永遠在畫面內 */
    .navgroup { display: block; width: 100%; }
    .navmenu {
        position: static; margin: 2px 0 6px; width: 100%; min-width: 0;
        box-shadow: none; border: 1px solid var(--line);
    }
    .navgroup-right .navmenu { left: auto; right: auto; }
    .nav-avatar-link { margin: 8px 0 0; }
}

/* 清單表格 */
table.list { width: 100%; border-collapse: collapse; margin-top: 4px; }
table.list th, table.list td {
    padding: 9px 10px; border-bottom: 1px solid var(--line); font-size: 14px; text-align: left;
}
table.list th { color: var(--blue-dark); font-weight: 600; background: var(--blue-soft); }
table.list tbody tr:hover td { background: #f6fafe; }
table.list tr.inactive td { color: #aebcc8; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; }
.badge-on { background: #e1f5ee; color: #0f6e56; }
.badge-off { background: #eef1f4; color: #888780; }
.actions { white-space: nowrap; }
.actions a, .actions button {
    font-size: 13px; padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line-in);
    background: #fff; color: var(--blue-deep); cursor: pointer; text-decoration: none; margin-right: 6px;
}
.actions a:hover, .actions button:hover { background: var(--blue-soft); }
/* 只有包在 .table-scroll 裡的寬表格才橫向捲動；小表格不受影響 */
.table-scroll { overflow-x: auto; }
.table-scroll table.list { min-width: 720px; }
/* 明細清單欄位不換行，太寬時靠 .table-scroll 橫向捲動 */
.table-scroll table.list th, .table-scroll table.list td { white-space: nowrap; }
.actions button.danger { color: #993c1d; border-color: #f0c4b3; }
.actions button.danger:hover { background: #faece7; }
/* 操作改用 icon（ui.js 依文字自動套用）：方形小按鈕、省空間 */
.actions .ico {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; padding: 0; margin-right: 4px;
}
.actions .ico svg {
    width: 17px; height: 17px; display: block;
    fill: none; stroke: currentColor; stroke-width: 2;
    stroke-linecap: round; stroke-linejoin: round;
}
.actions .ico:hover { border-color: currentColor; }
/* 往右捲時凍結最左欄（交易明細的「操作」在第一欄，維護頁則凍結識別欄）*/
.table-scroll table.list th:first-child,
.table-scroll table.list td:first-child {
    position: sticky; left: 0; z-index: 2;
    background: var(--card); box-shadow: 2px 0 4px rgba(53,106,156,.08);
}
.table-scroll table.list thead th:first-child { z-index: 3; background: var(--blue-soft); }
.inline-form { display: inline; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

/* ===== 首頁 ===== */
.hero {
    background: linear-gradient(135deg, var(--hero-a), var(--hero-b));
    color: #fff; border: none; box-shadow: 0 4px 14px rgba(53,106,156,.22);
}
.hero h1 { margin: 0 0 6px; font-size: 24px; color: #fff; }
.hero p { margin: 0; color: rgba(255,255,255,.9); font-size: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.stat {
    background: var(--card); border: 1px solid var(--line); border-radius: 14px;
    padding: 18px 20px; box-shadow: 0 1px 3px rgba(53,106,156,.06);
    border-top: 3px solid var(--blue);
}
.stat .label { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.stat .value { font-size: 22px; font-weight: 700; color: var(--ink); line-height: 1.5; }
.stat .value .ccy { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 4px; }
.stat .empty { font-size: 18px; color: #b6c2cd; font-weight: 400; }
@media (max-width: 600px) { .stat-grid { grid-template-columns: 1fr; } }

/* 各帳戶分類卡（現金/銀行/信用卡） */
.acct-card .acct-row {
    display: flex; justify-content: space-between; gap: 10px;
    padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 14px;
}
.acct-card .acct-row .nm { color: var(--ink); }
.acct-card .acct-row .amt { font-weight: 600; white-space: nowrap; }
.acct-card .ccy { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 3px; }
.acct-card .empty { color: #b6c2cd; padding: 7px 0; }
.acct-card .subtotal {
    display: flex; justify-content: space-between; gap: 10px;
    padding-top: 10px; margin-top: 4px; font-weight: 700; color: var(--blue-dark);
}

/* 快速操作按鈕群 */
.quicklinks { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.quicklinks .btn, .quicklinks .btn-ghost { margin-top: 0; }

/* ===== 通用工具類（取代樣板內 inline style） ===== */
/* 加 table.list td/th 選擇器才蓋得過 table.list td 的靠左 */
.num, table.list td.num, table.list th.num { text-align: right; }
.center, table.list td.center, table.list th.center { text-align: center; }
.nowrap { white-space: nowrap; }
.pnl-pos { color: #0f6e56; }
.pnl-neg { color: #993c1d; }

/* ===== 篩選列（原本各頁 inline style，統一收斂到這裡） ===== */
.filterbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.filterbar input, .filterbar select { width: auto; }
.filterbar input[type="date"] { max-width: 160px; }
.filterbar select { max-width: 240px; }
.filterbar input[type="text"] { max-width: 260px; }

/* ===== 表格排序（ui.js 自動套用在 table.list th） ===== */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { text-decoration: underline; }
th.sortable[data-dir="asc"]::after { content: " ▲"; font-size: 10px; }
th.sortable[data-dir="desc"]::after { content: " ▼"; font-size: 10px; }

/* ===== 成功訊息自動淡出（ui.js 控制） ===== */
.msg-ok { transition: opacity .6s; }
.msg-ok.fade-out { opacity: 0; }

/* ===== 刪除確認 modal（取代原生 confirm，ui.js 產生） ===== */
.modal-mask {
    position: fixed; inset: 0; background: rgba(15, 30, 45, .45);
    display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
    background: var(--card); color: var(--ink); border: 1px solid var(--line);
    border-radius: 14px; padding: 22px 24px; max-width: 360px; width: calc(100% - 48px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, .28);
}
.modal p { margin: 0; font-size: 15px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.modal-actions .btn { margin-top: 0; }
.btn-danger { background: #c0533a; }
.btn-danger:hover { background: #a8442d; }

/* ===== 首頁小圖表（純 SVG/CSS，ui.js 繪製） ===== */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .chart-grid { grid-template-columns: 1fr; } }
.chart-box { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; font-size: 13px; }
.chart-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: baseline; }
.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 150px; width: 100%; padding: 0 6px; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar-chart .bar { width: 70%; max-width: 46px; background: linear-gradient(180deg, var(--hero-a), var(--blue)); border-radius: 6px 6px 0 0; min-height: 2px; }
.bar-chart .bar-val { font-size: 11px; color: var(--muted); white-space: nowrap; }
.bar-chart .bar-label { font-size: 12px; color: var(--ink); }
.bar-chart .bar-sub { font-size: 10px; color: var(--muted); white-space: nowrap; }
.bar-chart { overflow-x: auto; }
.bar-chart .bar-col { min-width: 40px; }
/* 圖表左側縱軸標籤（如「成本(USD)」）*/
.chart-with-axis { display: flex; align-items: stretch; gap: 8px; margin-bottom: 16px; }
.chart-with-axis > div { flex: 1; min-width: 0; }
.chart-yaxis { writing-mode: vertical-rl; transform: rotate(180deg); align-self: center; font-size: 12px; color: var(--muted); white-space: nowrap; }
/* 圖表分頁按鈕（如報表 SPEC 批次依幣別切換） */
.chart-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chart-tabs button {
    font-size: 13px; padding: 5px 14px; border-radius: 999px; cursor: pointer;
    border: 1px solid var(--line-in); background: var(--card); color: var(--blue-deep);
}
.chart-tabs button.on { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ===== 深色主題 ===== */
[data-theme="dark"] {
    --blue:       #4f8fc4;
    --blue-deep:  #3c76a8;
    --blue-dark:  #9cc4e4;   /* 深色下標題改亮藍 */
    --blue-soft:  #22303e;   /* 表頭/tag 底 */
    --bg:         #141a21;
    --ink:        #dce6ef;
    --muted:      #8ba0b3;
    --card:       #1c242e;
    --line:       #2a3644;
    --line-in:    #3a4a5c;
    --hero-a:     #2c4a66;
    --hero-b:     #3b688e;
}
[data-theme="dark"] input, [data-theme="dark"] select { background: #232d38; color: var(--ink); }
[data-theme="dark"] .navmenu { background: #1f2833; }
[data-theme="dark"] .navmenu a:hover { background: #2a3644; }
[data-theme="dark"] table.list tbody tr:hover td { background: #222c37; }
[data-theme="dark"] table.list tr.inactive td { color: #55677a; }
[data-theme="dark"] .actions a, [data-theme="dark"] .actions button { background: #232d38; color: #9cc4e4; }
[data-theme="dark"] .actions a:hover, [data-theme="dark"] .actions button:hover { background: #2a3644; }
[data-theme="dark"] .actions button.danger { color: #f0a488; border-color: #5a3226; }
[data-theme="dark"] .actions button.danger:hover { background: #3b201a; }
[data-theme="dark"] .msg-ok { background: #153528; color: #7fd4b4; }
[data-theme="dark"] .msg-err { background: #3b201a; color: #f0a488; }
[data-theme="dark"] .badge-on { background: #153528; color: #7fd4b4; }
[data-theme="dark"] .badge-off { background: #2a3038; color: #98a2ac; }
[data-theme="dark"] .field-err { color: #f08cae; }
[data-theme="dark"] .pnl-pos { color: #5fcf9f; }
[data-theme="dark"] .pnl-neg { color: #f0a488; }
[data-theme="dark"] .stat .empty, [data-theme="dark"] .acct-card .empty { color: #4d6275; }
[data-theme="dark"] .avatar-empty { color: #5b7186; }
[data-theme="dark"] .nav-avatar { background: #232d38; }
