/* 殯葬客戶管理系統 · RWD 樣式 */
:root {
    --primary: #37474f;
    --primary-dark: #263238;
    --accent: #00897b;
    --danger: #c62828;
    --bg: #f4f6f8;
    --card: #ffffff;
    --border: #d9dee3;
    --text: #263238;
    --muted: #78909c;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }

/* ---------- 頂部導覽 ---------- */
.topbar { background: var(--primary); color: #fff; box-shadow: var(--shadow); position: sticky; top: 0; z-index: 50; }
.topbar-inner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.brand { color: #fff; font-weight: 700; font-size: 1.05rem; margin-right: auto; }
.user-chip { background: rgba(255,255,255,.15); padding: 4px 12px; border-radius: 999px; font-size: .85rem; }
.hamburger { display: none; background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; padding: 4px 8px; }
.nav { display: flex; gap: 4px; padding: 0 12px 8px; flex-wrap: wrap; }
.nav a { color: #eceff1; padding: 8px 14px; border-radius: 8px; font-size: .95rem; }
.nav a:hover { background: rgba(255,255,255,.12); }
.nav a.logout { color: #ffcdd2; margin-left: auto; }

/* ---------- 容器 ---------- */
.container { max-width: 1080px; margin: 0 auto; padding: 24px 16px 60px; }
.page-title { font-size: 1.5rem; margin: 0 0 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.muted { color: var(--muted); }
.readonly-tag { font-size: .75rem; background: #eceff1; color: var(--muted); padding: 2px 10px; border-radius: 999px; vertical-align: middle; }

/* ---------- Flash ---------- */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 14px; font-size: .95rem; }
.flash-success { background: #e0f2f1; color: #00695c; border: 1px solid #b2dfdb; }
.flash-error { background: #ffebee; color: #c62828; border: 1px solid #ffcdd2; }

/* ---------- 按鈕 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    background: #eceff1; color: var(--text); border: 1px solid var(--border);
    padding: 10px 16px; border-radius: 8px; cursor: pointer; font-size: .95rem;
    min-height: 42px; transition: background .15s, opacity .15s; }
.btn:hover { background: #dfe4e8; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #00796b; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: .9; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: .85rem; }

/* ---------- 功能選單卡片 ---------- */
.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-top: 20px; }
.menu-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 22px; box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s; color: var(--text); }
.menu-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.1); }
.menu-card h2 { margin: 8px 0 6px; font-size: 1.15rem; }
.menu-card p { margin: 0; color: var(--muted); font-size: .9rem; }
.menu-icon { font-size: 2rem; }
.menu-card.highlight { border-color: var(--accent); }

/* ---------- 搜尋列 ---------- */
.search-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.search-bar input[type=text] { flex: 1 1 200px; padding: 6px 12px; border: 1px solid var(--border);
    border-radius: 8px; min-height: 36px; height: 36px; font-size: .92rem; }
.search-bar .btn { min-height: 36px; height: 36px; padding: 4px 14px; }

/* ---------- 卡片 / 面板 ---------- */
.card, .panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px; }
.card-title { margin: 0 0 14px; font-size: 1.1rem; }
.panel h2 { margin: 0 0 14px; font-size: 1.15rem; border-bottom: 2px solid #eceff1; padding-bottom: 8px; }

/* ---------- 表單 ---------- */
.record-form fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 20px; background: var(--card); }
.record-form legend { font-weight: 700; color: var(--primary); padding: 0 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; }
.field span { color: var(--muted); font-size: .85rem; }
.field.required span::after { content: " *"; color: var(--danger); }
.field input, .field select, .search-bar select, select {
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
    min-height: 42px; font-size: .95rem; width: 100%; background: #fff; }
.field.grow { flex: 1 1 220px; }
.field.small { max-width: 120px; }
.inline-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-actions { display: flex; gap: 12px; margin-top: 10px; }
.hint { color: var(--muted); font-size: .85rem; margin-top: 10px; }

/* ---------- 表格（桌機） ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius); overflow: hidden; }
.data-table th, .data-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: .92rem; }
.data-table th { background: #eceff1; color: var(--primary); font-weight: 600; white-space: nowrap; }
.data-table tr:last-child td { border-bottom: none; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { background: #e0f2f1; color: #00695c; padding: 3px 10px; border-radius: 999px; font-size: .8rem; }
.sign-tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .8rem; white-space: nowrap; }
.sign-done { background: #e0f2f1; color: #00695c; border: 1px solid #80cbc4; }
.sign-prog { background: #fff8e1; color: #f57f17; border: 1px solid #ffe082; }
.sign-draft { background: #eceff1; color: #607d8b; border: 1px solid #cfd8dc; }
.sign-none { background: transparent; color: #b0bec5; border: 1px dashed #cfd8dc; }
.empty { color: var(--muted); background: var(--card); border: 1px dashed var(--border); border-radius: var(--radius); padding: 30px; text-align: center; }

/* ---------- 總覽詳情 ---------- */
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px 20px; }
.info-row { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px dashed #eceff1; }
.info-label { color: var(--muted); min-width: 90px; font-size: .88rem; }
.info-value { font-weight: 500; }

/* ---------- 手寫簽名 ---------- */
.sig-wrap { border: 2px dashed var(--border); border-radius: var(--radius); background: #fafcff; padding: 6px; margin: 6px 0 12px; }
.sig-canvas { display: block; width: 100%; height: 220px; touch-action: none; cursor: crosshair; border-radius: 6px; background: #fff; }
.clause-list { margin: 4px 0; padding-left: 20px; }
.clause-list li { padding: 2px 0; }
.consent { display: flex; gap: 10px; align-items: flex-start; background: #fff8e1; border: 1px solid #ffe082; border-radius: 8px; padding: 12px 14px; margin: 10px 0; font-size: .92rem; }
.consent input { margin-top: 3px; width: 18px; height: 18px; flex-shrink: 0; }
.hash { font-family: ui-monospace, "Courier New", monospace; font-size: .8rem; color: var(--muted); }
.hash-block { display: block; font-family: ui-monospace, "Courier New", monospace; font-size: .82rem; word-break: break-all; background: #263238; color: #b2dfdb; padding: 12px 14px; border-radius: 8px; }
.verify-banner { padding: 18px; border-radius: var(--radius); font-size: 1.1rem; text-align: center; }
.verify-ok { background: #e0f2f1; color: #00695c; border: 1px solid #b2dfdb; }
.verify-bad { background: #ffebee; color: #c62828; border: 1px solid #ffcdd2; }
.verify-warn { background: #fff8e1; color: #f57f17; border: 1px solid #ffe082; }

/* ---------- 簽約流程 ---------- */
.steps { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.steps .step { flex: 1 1 auto; text-align: center; padding: 10px 8px; background: var(--card);
    border: 1px solid var(--border); border-radius: 8px; font-size: .88rem; color: var(--muted); white-space: nowrap; }
.steps .step.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }

.plan-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.plan-option { cursor: pointer; }
.plan-option input { position: absolute; opacity: 0; }
.plan-card { border: 2px solid var(--border); border-radius: var(--radius); padding: 18px; text-align: center; transition: border-color .15s, box-shadow .15s; }
.plan-option input:checked + .plan-card { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,137,123,.15); }
.plan-card h3 { margin: 0 0 8px; font-size: 1.1rem; }
.plan-price { font-size: 1.25rem; font-weight: 700; color: var(--accent); }
.plan-sub { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.plan-total { font-size: 1.1rem; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.plan-section { margin: 10px 0 14px; padding-bottom: 10px; border-bottom: 1px dashed #eceff1; }
.plan-section h3 { font-size: 1rem; margin: 0 0 6px; color: var(--primary); }
.mini-table { width: 100%; border-collapse: collapse; margin: 4px 0; }
.mini-table th, .mini-table td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; font-size: .9rem; }
.mini-table th { background: #eceff1; }

.tag-manual { background: #fff3e0; color: #e65100; padding: 1px 6px; border-radius: 5px; font-size: .72rem; white-space: nowrap; }

/* Excel 式緊湊加購表 */
.addon-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 720px) { .addon-cols { grid-template-columns: 1fr; } }
.xls-table { width: 100%; border-collapse: collapse; font-size: .82rem; table-layout: fixed; }
.xls-table th, .xls-table td { border: 1px solid var(--border); padding: 2px 5px; text-align: left; }
.xls-table thead th { background: #37474f; color: #fff; font-size: .76rem; padding: 4px 5px; font-weight: 600; }
.xls-table td.nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xls-table td.nm .unit { color: var(--muted); font-size: .72rem; margin-left: 3px; }
.xls-table .c-sel { width: 26px; text-align: center; }
.xls-table .c-qty { width: 52px; }
.xls-table .c-up { width: 60px; text-align: right; }
.xls-table .c-amt { width: 66px; }
.xls-table input[type=number] { width: 100%; min-height: 26px; padding: 1px 4px; font-size: .8rem; border: 1px solid var(--border); border-radius: 4px; }
.xls-table input[type=checkbox] { width: 17px; height: 17px; }
.xls-table tr.on { background: #e0f2f1; }
.xls-table tr.on td.nm { font-weight: 600; }
.xls-table .auto { color: var(--muted); font-size: .72rem; }
.xls-table td.c-up { white-space: nowrap; }

.dual-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .dual-sign { grid-template-columns: 1fr; } }

/* Excel 式費用明細統計表（緊湊，手機可一次瀏覽） */
.stmt-table { width: 100%; border-collapse: collapse; font-size: .84rem; table-layout: fixed; }
.stmt-table col.c1 { width: 48%; }
.stmt-table col.c2 { width: 28%; }
.stmt-table col.c3 { width: 24%; }
.stmt-table td { border: 1px solid #b0bec5; padding: 3px 7px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; }
.stmt-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stmt-table tr.cat td { background: #c8e6c9; color: #1b5e20; text-align: center; font-weight: 700; letter-spacing: 1px; padding: 4px; }
.stmt-table tr.hd td { background: #eceff1; color: #607d8b; font-weight: 600; font-size: .74rem; padding: 2px 7px; }
.stmt-table tr.sub td { background: #bbdefb; color: #0d47a1; font-weight: 700; }
.stmt-table td.muted { text-align: center; color: var(--muted); }
.stmt-table tr.grand td { background: #37474f; color: #fff; font-size: .98rem; font-weight: 700; }
.stmt-table tr.grand td.num { color: #ffd54f; }
@media (max-width: 480px) {
    .stmt-table { font-size: .76rem; }
    .stmt-table td { padding: 2px 5px; }
    .stmt-table tr.hd td { font-size: .68rem; }
    .stmt-table tr.grand td { font-size: .9rem; }
}

/* ---------- 登入頁 ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; background: linear-gradient(135deg, #37474f, #263238); }
.login-box { background: #fff; padding: 36px 28px; border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.25); width: 100%; max-width: 380px; }
.login-box h1 { font-size: 1.35rem; margin: 0 0 4px; text-align: center; }
.login-box .subtitle { text-align: center; color: var(--muted); margin: 0 0 20px; }
.login-box label { display: block; margin-bottom: 14px; font-size: .9rem; color: var(--muted); }
.login-box input { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 8px; margin-top: 6px; min-height: 46px; font-size: 1rem; }

/* =========================================================
   RWD 響應式
   ========================================================= */
@media (max-width: 768px) {
    .hamburger { display: block; }
    .nav { display: none; flex-direction: column; padding: 0 12px 12px; }
    .nav.open { display: flex; }
    .nav a.logout { margin-left: 0; }
    .user-chip { display: none; }

    /* 表格 → 卡片式 */
    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table tr { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
        margin-bottom: 12px; padding: 8px 4px; box-shadow: var(--shadow); }
    .data-table td { border: none; border-bottom: 1px dashed #eceff1; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
    .data-table td:last-child { border-bottom: none; }
    .data-table td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; font-weight: 600; text-align: left; }
    .data-table td[data-label=""]::before { content: ""; }
    .actions { justify-content: flex-end; }

    .inline-form { flex-direction: column; align-items: stretch; }
    .search-bar { gap: 6px; align-items: center; }
    .search-bar input[type=text] { min-height: 34px; height: 34px; padding: 4px 10px; font-size: .88rem; }
    .search-bar .btn { min-height: 34px; height: 34px; padding: 2px 12px; font-size: .85rem; }
    .field.small { max-width: none; }
    .info-row { flex-direction: column; gap: 2px; }
}

@media (max-width: 420px) {
    .page-title { font-size: 1.25rem; }
    .container { padding: 16px 12px 50px; }
}
