/* 單程殯葬學院 會員工具平台 — 手機/iPad 優先響應式樣式 */
:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #23211e;
  --muted: #6f6a62;
  --line: #e5e1d8;
  --brand: #4a5d52;
  --brand-dark: #36463d;
  --accent: #a8845c;
  --danger: #b0483f;
  --warn: #b07a2e;
  --ok: #4d7c5f;
  --info: #5b6e8c;
  --nav-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; font-size: 16px; line-height: 1.65; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== 頂欄 ===== */
.topbar { background: var(--brand-dark); color: #f2efe9; padding: 0 16px; display: flex; align-items: center; gap: 16px; height: 54px; position: sticky; top: 0; z-index: 20; }
.topbar .logo { font-weight: 700; font-size: 16px; letter-spacing: 1px; color: #fff; white-space: nowrap; }
.topbar nav { display: flex; gap: 14px; align-items: center; overflow-x: auto; }
.topbar nav a { color: #d8d4c8; font-size: 14px; white-space: nowrap; padding: 6px 2px; }
.topbar nav a.active, .topbar nav a:hover { color: #fff; text-decoration: none; }
.topbar .spacer { flex: 1; }
.topbar .user { font-size: 13px; color: #b9b4a6; white-space: nowrap; }
.topbar .logout { color: #d8d4c8; font-size: 13px; white-space: nowrap; }

/* ===== 底部導覽（手機） ===== */
.bottomnav { display: none; }
@media (max-width: 820px) {
  .topbar nav, .topbar .user { display: none; }
  .bottomnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #fff; border-top: 1px solid var(--line); height: calc(var(--nav-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom); box-shadow: 0 -2px 12px rgba(0,0,0,.06); }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); }
  .bottomnav a .ic { font-size: 21px; line-height: 1; }
  .bottomnav a.active { color: var(--brand-dark); font-weight: 700; }
  .bottomnav a:hover { text-decoration: none; }
  body.loggedin { padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px); }
}

.container { max-width: 1080px; margin: 0 auto; padding: 20px 16px 80px; }
@media (min-width: 821px) { .container { padding: 28px 24px 80px; } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
@media (min-width: 600px) { .panel { padding: 20px 24px; margin-bottom: 18px; } }

h1 { font-size: 21px; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 22px 0 10px; border-left: 4px solid var(--brand); padding-left: 10px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
.sub { color: var(--muted); font-size: 13px; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 4px -4px; padding: 0 4px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
th { background: #f0ede6; font-weight: 600; white-space: nowrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; background: var(--brand); color: #fff; border: none; border-radius: 9px; padding: 11px 20px; font-size: 15px; cursor: pointer; min-height: 44px; font-family: inherit; }
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn.secondary { background: #fff; color: var(--brand); border: 1px solid var(--brand); }
.btn.small { padding: 6px 14px; font-size: 13px; min-height: 36px; }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; }

input, select, textarea { font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; min-height: 44px; }
textarea { min-height: 120px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.checkline { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; margin-right: 16px; font-size: 15px; color: var(--ink); }
.checkline input { width: 20px; height: 20px; min-height: 0; margin: 0; }

.grid2, .grid3 { display: grid; grid-template-columns: 1fr; gap: 4px 18px; }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid3 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { .grid3 { grid-template-columns: 1fr 1fr 1fr; } }

.badge { display: inline-block; border-radius: 20px; padding: 1px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.avoid, .badge.error { background: #f6dedc; color: var(--danger); }
.badge.caution, .badge.warning { background: #f5e8d3; color: var(--warn); }
.badge.acceptable { background: #e8ece9; color: var(--muted); }
.badge.favorable { background: #dcebe1; color: var(--ok); }
.badge.info, .badge.admin { background: #e2e8f0; color: var(--info); }
.badge.ritual { background: #ece7dd; color: var(--accent); }
.badge.gray { background: #eee; color: #666; }

/* ===== 分頁籤（案件內） ===== */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 4px 2px 6px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex-shrink: 0; padding: 9px 18px; border-radius: 22px; font-size: 14px; color: var(--muted); background: #fff; border: 1px solid var(--line); min-height: 40px; display: inline-flex; align-items: center; }
.tabs a.active { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; font-weight: 700; }
.tabs a:hover { text-decoration: none; }

.timeline-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.timeline-date { min-width: 96px; font-weight: 600; font-size: 13.5px; color: var(--brand-dark); }
.timeline-body { flex: 1; min-width: 0; }
.timeline-name { font-weight: 600; }
.timeline-desc { font-size: 13px; color: var(--muted); margin-top: 2px; }
.variant { font-size: 12.5px; color: var(--accent); margin-top: 2px; }
@media (max-width: 480px) { .timeline-item { flex-direction: column; gap: 2px; } .timeline-date { min-width: 0; } }

.day-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: #fff; }
.day-card.avoid { border-left: 5px solid var(--danger); }
.day-card.caution { border-left: 5px solid var(--warn); }
.day-card.acceptable { border-left: 5px solid #bbb; }
.day-card.favorable { border-left: 5px solid var(--ok); }
.day-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.hit { font-size: 12.5px; margin: 2px 0; }
.hit.block { color: var(--danger); }
.hit.warn { color: var(--warn); }
.hit.info { color: var(--info); }
.hit.favor { color: var(--ok); }

.obituary { font-family: "Noto Serif TC", "PMingLiU", serif; white-space: pre-wrap; background: #fffdf7; border: 1px solid var(--line); padding: 18px; border-radius: 8px; font-size: 15px; overflow-x: auto; }
.disclaimer { background: #f4f1ea; border-left: 4px solid var(--accent); padding: 10px 14px; font-size: 12.5px; color: var(--muted); border-radius: 4px; margin: 14px 0; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: #faf9f6; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; text-align: center; }
.stat b { font-size: 26px; color: var(--brand-dark); display: block; line-height: 1.3; }
.stat span { font-size: 12.5px; color: var(--muted); }

.card-list { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 620px) { .card-list { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); } }
.case-card { border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; background: #fff; display: block; color: inherit; }
.case-card:hover { border-color: var(--brand); text-decoration: none; }

/* 設施卡片 */
.fac-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: #fff; margin-bottom: 12px; }
.fac-card .fac-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.fac-card .fac-head b { font-size: 16px; }
.fac-row { display: flex; gap: 8px; font-size: 13.5px; padding: 3px 0; }
.fac-row .k { min-width: 72px; color: var(--muted); flex-shrink: 0; }
.fac-row .v { min-width: 0; word-break: break-word; }

.md-content { line-height: 1.85; overflow-wrap: break-word; }
.md-content h1 { font-size: 20px; } .md-content h2 { font-size: 17px; } .md-content h3 { font-size: 15px; }
.md-content table { font-size: 13px; margin: 10px 0; }
.md-content code { background: #f0ede6; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.md-content blockquote { border-left: 3px solid var(--accent); margin: 10px 0; padding: 4px 14px; color: var(--muted); background: #faf8f3; }
.md-content img { max-width: 100%; }

.login-box { max-width: 400px; margin: 60px auto; padding: 0 16px; }
@media (min-width: 600px) { .login-box { margin: 90px auto; } }
.login-box .logo-big { text-align: center; font-size: 24px; font-weight: 700; color: var(--brand-dark); margin-bottom: 4px; }

.toolrow { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 14px 0; }
.err { color: var(--danger); font-size: 13px; }
.oknote { color: var(--ok); font-size: 13px; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
