:root {
  --bg: #f2f5f4;
  --card: #ffffff;
  --ink: #15201f;
  --muted: #647170;
  --line: #e1e8e6;
  --teal: #0f5e57;
  --teal-2: #13776e;
  --teal-dark: #0a3a36;
  --teal-soft: #e4f2ef;
  --lime: #a6ce39;
  --lime-soft: #f1f8e1;
  --red: #c0392b;
  --red-soft: #fdecea;
  --amber: #b7791f;
  --amber-soft: #fdf3e1;
  --green: #2e7d32;
  --green-soft: #e8f5e9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 40, 38, .05), 0 4px 16px rgba(16, 40, 38, .04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Sukhumvit Set",
    "Noto Sans Thai", sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); font-size: 14.5px; line-height: 1.55; }
a { color: var(--teal-2); }
h1, h2, h3, h4 { margin: 0 0 10px; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
small, .muted { color: var(--muted); }
small { font-size: .85em; }
code { background: #eef2f1; padding: 1px 5px; border-radius: 5px; font-size: .9em; }

/* ---------- 版面：側欄 + 內容 ---------- */
.layout { display: flex; min-height: 100vh; }
.side { width: 236px; flex: none; background: linear-gradient(180deg, var(--teal-dark), var(--teal) 70%, var(--teal-2));
  color: #fff; padding: 18px 12px 24px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .logo { display: flex; gap: 10px; align-items: center; padding: 4px 8px 14px; border-bottom: 1px solid rgba(255,255,255,.14);
  margin-bottom: 10px; text-decoration: none; color: #fff; }
.side .logo .mark { width: 36px; height: 36px; border-radius: 10px; background: rgba(255,255,255,.14); display: grid;
  place-items: center; font-size: 19px; }
.side .logo b { display: block; font-size: 15.5px; line-height: 1.2; }
.side .logo small { color: #cfe6e1; font-size: 11px; }
.side .group { margin: 12px 8px 4px; font-size: 11px; letter-spacing: .08em; color: #a9d4cc; }
.side a.nav { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 9px; color: #eaf6f3;
  text-decoration: none; font-size: 14px; }
.side a.nav:hover { background: rgba(255,255,255,.09); }
.side a.nav.on { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--lime); }
.side .ico { width: 20px; text-align: center; }
.side .foot { margin-top: 16px; padding: 10px 10px 0; border-top: 1px solid rgba(255,255,255,.14); font-size: 12px; color: #cfe6e1; }
.side .foot a { color: #fff; }
.content { flex: 1; min-width: 0; }
.topbar { display: none; }
.page { max-width: 1280px; margin: 0 auto; padding: 22px 26px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.badge-top { font-size: 12px; background: var(--teal-soft); color: var(--teal); padding: 4px 10px; border-radius: 999px; font-weight: 600; }

@media (max-width: 900px) {
  .layout { display: block; }
  .side { position: fixed; z-index: 50; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  body.nav-open .side { transform: none; }
  .topbar { display: flex; position: sticky; top: 0; z-index: 40; align-items: center; gap: 10px; padding: 10px 16px;
    background: var(--teal-dark); color: #fff; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; padding: 0 4px; cursor: pointer; }
  .page { padding: 16px 16px 60px; }
}

/* ---------- 卡片與網格 ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 16px; }
.card h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.card h2 small { font-weight: 400; }
.grid { display: grid; gap: 16px; }
.grid > .card + .card { margin-top: 0; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-main { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 700px) { .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); } }
.stack > * + * { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.right { margin-left: auto; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }

/* ---------- Hero（總覽頁上方） ---------- */
.hero { border-radius: 18px; padding: 24px 26px; color: #fff; margin-bottom: 18px;
  background: radial-gradient(circle at 92% 20%, rgba(166, 206, 57, .45), transparent 34%),
              linear-gradient(120deg, var(--teal-dark), var(--teal) 55%, var(--teal-2)); }
.hero h1 { font-size: 25px; margin-bottom: 6px; }
.hero p { color: #d9eeea; max-width: 760px; }
.hero .quick { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.hero .quick a { background: rgba(255,255,255,.14); color: #fff; padding: 7px 13px; border-radius: 9px; text-decoration: none;
  font-weight: 600; font-size: 13.5px; border: 1px solid rgba(255,255,255,.18); }
.hero .quick a:hover { background: rgba(255,255,255,.24); }

/* ---------- 數字卡 ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; text-decoration: none;
  color: var(--ink); display: block; box-shadow: var(--shadow); }
.kpi:hover { border-color: var(--teal-2); }
.kpi .n { font-size: 24px; font-weight: 700; line-height: 1.2; }
.kpi .l { font-size: 12.5px; color: var(--muted); }
.kpi.warn .n { color: var(--red); }
.kpi.amber .n { color: var(--amber); }
.kpi.good .n { color: var(--teal); }

/* ---------- 表單 ---------- */
label { display: block; margin-bottom: 12px; font-weight: 600; font-size: 13.5px; }
label .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
input, select, textarea { font: inherit; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid #cdd7d4;
  border-radius: 9px; background: #fff; color: var(--ink); font-weight: 400; }
textarea { resize: vertical; line-height: 1.5; max-width: 100%; }
textarea::placeholder { white-space: pre-wrap; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(19, 119, 110, .35); border-color: var(--teal-2); }
input[type=checkbox], input[type=radio] { width: auto; margin: 0 6px 0 0; accent-color: var(--teal); }
label.check { display: inline-flex; align-items: center; font-weight: 500; margin: 0 14px 8px 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid, .form-grid.three { grid-template-columns: 1fr; } }
.inline-form { display: inline; }

/* ---------- 按鈕 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 9px;
  border: 1px solid #cdd7d4; background: #fff; color: var(--ink); font: inherit; font-weight: 600; font-size: 13.5px;
  cursor: pointer; text-decoration: none; white-space: nowrap; line-height: 1.3; }
.btn:hover { border-color: var(--teal-2); color: var(--teal); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-2); color: #fff; }
.btn.lime { background: var(--lime); border-color: var(--lime); color: #17260a; }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn.small { padding: 4px 9px; font-size: 12.5px; border-radius: 7px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.wa { background: #25d366; border-color: #25d366; color: #fff; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 8px 8px; border-bottom: 1px solid var(--line);
  white-space: nowrap; background: #f8fbfa; }
.tbl td { padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: #fafcfb; }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl .nowrap { white-space: nowrap; }
.tbl td.actions { white-space: nowrap; text-align: right; }

/* ---------- 標籤 ---------- */
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #edf1f0;
  color: #44514f; white-space: nowrap; }
.pill.A, .pill.ok, .pill.green { background: var(--green-soft); color: var(--green); }
.pill.B, .pill.check, .pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.C, .pill.drop, .pill.red { background: var(--red-soft); color: var(--red); }
.pill.teal { background: var(--teal-soft); color: var(--teal); }
.pill.lime { background: var(--lime-soft); color: #5d7a14; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.dot.red { background: var(--red); } .dot.green { background: var(--green); } .dot.amber { background: var(--amber); }

/* ---------- 清單 ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 9px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; }
.list .sub { color: var(--muted); font-size: 12.5px; }
.empty { color: var(--muted); padding: 14px 0; text-align: center; font-size: 13.5px; }

/* ---------- 分數環 ---------- */
.score { display: flex; gap: 18px; align-items: center; }
.ring { --p: 50; --c: var(--teal); width: 104px; height: 104px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), #e7eeec 0); }
.ring span { width: 78px; height: 78px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-size: 26px; font-weight: 700; }
.ring.A { --c: #2e9d55; } .ring.B { --c: #d9a21b; } .ring.C { --c: #d0493a; }
.bars .bar { margin: 7px 0; }
.bars .bar .top { display: flex; justify-content: space-between; font-size: 12.5px; }
.bars .track { height: 7px; background: #e8eeec; border-radius: 99px; overflow: hidden; margin-top: 2px; }
.bars .fill { height: 100%; background: var(--teal-2); border-radius: 99px; }

/* ---------- 橫條圖 ---------- */
.hbar { display: grid; grid-template-columns: 130px 1fr 90px; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
.hbar .track { height: 10px; background: #e8eeec; border-radius: 99px; overflow: hidden; }
.hbar .fill { height: 100%; background: linear-gradient(90deg, var(--teal), var(--teal-2)); border-radius: 99px; }
.hbar .v { text-align: right; color: var(--muted); white-space: nowrap; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 提示訊息 ---------- */
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; }
.flash.ok { background: var(--green-soft); color: #1f5d23; border: 1px solid #c8e6c9; }
.flash.error { background: var(--red-soft); color: #8e2a20; border: 1px solid #f5c6c0; }
.note { background: var(--teal-soft); border-radius: 10px; padding: 10px 13px; font-size: 13.5px; color: #214c47; }
.note.amber { background: var(--amber-soft); color: #7a5412; }
.note.red { background: var(--red-soft); color: #8e2a20; }

/* ---------- AI 輸出 ---------- */
.prose { font-size: 14.5px; }
.prose h2 { font-size: 16.5px; margin-top: 18px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.prose h3 { font-size: 15px; margin-top: 14px; }
.prose ul, .prose ol { padding-left: 22px; margin: 6px 0 12px; }
.prose li { margin: 3px 0; }
.prose table { margin: 8px 0 14px; }
.sources { font-size: 12.5px; }
.sources a { color: var(--muted); word-break: break-all; }
.cost { font-size: 12px; color: var(--muted); }
.textbox { white-space: pre-wrap; background: #f8fbfa; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 14px; }

/* ---------- AI 工作進度視窗 ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 30, 28, .45); z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 16px; padding: 22px; width: min(460px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(620px, 100%); }
.modal h3 { margin-bottom: 8px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--teal-soft); border-top-color: var(--teal); border-radius: 50%;
  animation: spin 1s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px;
  border-radius: 10px; z-index: 120; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.error { background: var(--red); }

/* ---------- Odoo 搜尋框 ---------- */
.picker { position: relative; }
.picker .results { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.12); max-height: 300px; overflow-y: auto; margin-top: 4px; }
.picker .results div { padding: 8px 11px; cursor: pointer; font-size: 13.5px; border-bottom: 1px solid #f0f3f2; }
.picker .results div:hover { background: var(--teal-soft); }
.picker .chip { display: inline-flex; align-items: center; gap: 8px; background: var(--teal-soft); color: var(--teal); padding: 5px 10px;
  border-radius: 9px; font-weight: 600; margin-top: 4px; }
.picker .chip button { border: 0; background: none; color: var(--teal); cursor: pointer; font-size: 15px; padding: 0; }

/* ---------- 名片 ---------- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
@media (max-width: 500px) { .cards-grid { grid-template-columns: 1fr; } }
.bizcard img { width: 100%; max-height: 220px; object-fit: contain; background: #f4f7f6; border-radius: 10px; border: 1px solid var(--line); }
.bizcard .imgs { display: flex; gap: 8px; }
.bizcard .imgs a { flex: 1; }

/* ---------- 定位圖 ---------- */
.posmap { width: 100%; max-width: 640px; }
.posmap text { font-size: 11px; fill: #33403e; }
.posmap .me circle { fill: var(--lime); stroke: var(--teal-dark); stroke-width: 2; }
.posmap .me text { font-weight: 700; fill: var(--teal-dark); }

/* ---------- 分頁籤 ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--teal); border-bottom-color: var(--teal); }

details.box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; }
details.box + details.box { margin-top: 10px; }
details.box summary { cursor: pointer; font-weight: 600; }
.sticky-bar { position: sticky; bottom: 0; background: rgba(255,255,255,.96); border-top: 1px solid var(--line); padding: 10px 0; margin-top: 10px;
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center; z-index: 5; }

/* ---------- 每日紀錄：手機 ---------- */
@media (max-width: 900px) {
  .daily-grid > .stack:last-child { order: -1; }
  .daily-grid .tbl td.actions { min-width: 0 !important; }
  .daily-grid .tbl .btn.small { padding: 7px 12px; font-size: 13px; }
  .daily-grid .tbl input[type=date], .daily-grid .tbl select { width: 100%; margin-top: 4px; }
  .daily-grid .inline-form { display: block; margin-top: 6px; }
}

/* AI 研究分頁、其他工具燈號 */
.ai-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.ai-tabs a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: 14px; }
.ai-tabs a:hover { background: var(--card); color: inherit; }
.ai-tabs a.on { background: var(--teal); color: #fff; }
.tool-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #999; margin-left: 6px; vertical-align: middle; }
.tool-dot.up { background: #4ade80; }
.goal { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.goal:last-child { border-bottom: 0; }
.goal .t { flex: 1; min-width: 0; }
.goal.done .t b { text-decoration: line-through; color: var(--muted); }
.goal .track { height: 6px; background: var(--line); border-radius: 3px; margin-top: 4px; }
.goal .track div { height: 100%; background: var(--teal); border-radius: 3px; }
.goal form { margin: 0; }
.quad { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .quad { grid-template-columns: 1fr; } }
.quad .q-Q1 { border-top: 4px solid var(--red); } .quad .q-Q2 { border-top: 4px solid var(--teal); }
.quad .q-Q3 { border-top: 4px solid var(--amber); } .quad .q-Q4 { border-top: 4px solid #bbb; }
.mail { padding: 10px 0; border-bottom: 1px solid var(--line); }
.mail:last-child { border-bottom: 0; }
.mail .top { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.mail .top .muted { margin-left: auto; }
.mail .subj { margin: 2px 0; font-weight: 600; overflow-wrap: anywhere; }
.mail .act { font-size: 13.5px; margin: 4px 0; }
/* 區域年度計劃 */
.plan-tbl td { min-width: 110px; }
.plan-tbl tr.total td { background: #f4f7f6; }
.pnum { white-space: nowrap; }
.ptrack { position: relative; height: 6px; background: var(--line); border-radius: 3px; margin: 4px 0 2px; }
.ptrack .fill { height: 100%; border-radius: 3px; background: var(--teal); }
.ptrack .fill.amber { background: var(--amber); } .ptrack .fill.warn { background: var(--red); }
.ptrack .pace { position: absolute; top: -3px; width: 2px; height: 12px; background: #333; opacity: .55; }
small.good { color: var(--teal); } small.amber { color: var(--amber); } small.warn { color: var(--red); }
.mbars { position: relative; display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-bottom: 18px; }
.mbars .mb { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.mbars .bar { width: 100%; background: var(--teal-2); border-radius: 4px 4px 0 0; min-height: 1px; }
.mbars .mb span { position: absolute; bottom: -18px; font-size: 11px; color: var(--muted); }
.mbars .avg { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--amber); }

/* ---------- 手機版：底部常用按鈕、加大點擊範圍 ---------- */
.tabbar { display: none; }
@media (max-width: 900px) {
  .topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .topbar b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; background: #fff; border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 16px rgba(0,0,0,.06); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 0 6px; font-size: 11px;
    color: var(--muted); text-decoration: none; }
  .tabbar a span { font-size: 20px; line-height: 1.1; }
  .tabbar a.on { color: var(--teal); font-weight: 700; }
  .page { padding-bottom: calc(90px + env(safe-area-inset-bottom)); }
  .page-head h1 { font-size: 21px; }
  .page-head p { font-size: 13px; }
  .page-head > .row { width: 100%; }
  input, select, textarea { font-size: 16px !important; }   /* iPhone 點輸入框不會自動放大 */
  .btn { min-height: 36px; }
  .btn.small { min-height: 32px; padding: 6px 11px; }
  .card { padding: 14px; }
  .ai-tabs { flex-wrap: nowrap; overflow-x: auto; }
  .ai-tabs a { white-space: nowrap; }
  .side { padding-bottom: 80px; overflow-y: auto; max-height: 100vh; }
  .mail .row .btn.small { flex: 1; }
  .goal { flex-wrap: wrap; }
  .goal .t { flex-basis: 60%; }
  .plan-tbl td { min-width: 96px; }
}
