/* AI 智能掌櫃 — 主管營運儀表板
   視覺基準：Joyce 既有「美國AMPM營運儀表板」設計語言——
   深藍灰漸層背景（不整頁死黑）、頂端精簡導覽列、內容集中固定最大寬度、
   緊湊有層級的卡片／狀態點／標籤／進度條，紫藍漸層作重點；
   綠＝完成或正常、黃＝待處理、紅＝阻塞或重大錯誤。
   本產品採單一深色定案外觀；無外部資源；系統字體。狀態永遠附中文標籤，不單靠顏色。 */

:root {
  --bg-0: #101522;
  --bg-1: #161d30;
  --surface: #1a2234;          /* 卡片 */
  --surface-2: #202a40;        /* 內層區塊 */
  --surface-3: #253049;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #e9edf5;
  --text-2: #9aa5bb;
  --text-3: #6a7590;
  --accent-a: #8a63f0;         /* 紫藍漸層（重點／進度） */
  --accent-b: #4f8cff;
  --good: #3ddc97;             /* 綠：完成／正常 */
  --good-dim: rgba(61, 220, 151, 0.13);
  --warn: #f2c94c;             /* 黃：待處理 */
  --warn-dim: rgba(242, 201, 76, 0.12);
  --bad: #f07178;              /* 紅：阻塞／重大錯誤 */
  --bad-dim: rgba(240, 113, 120, 0.12);
  --radius: 12px;
  --radius-s: 9px;
  --shadow: 0 8px 26px rgba(6, 10, 20, 0.4);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg-0);
  background-image:
    radial-gradient(900px 480px at 12% -6%, rgba(115, 92, 221, 0.16), transparent 60%),
    radial-gradient(820px 460px at 98% 4%, rgba(63, 111, 196, 0.12), transparent 55%),
    linear-gradient(168deg, var(--bg-1) 0%, var(--bg-0) 55%, #0d1220 100%);
  background-attachment: fixed;
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
  min-height: 100vh;
}
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent-b); outline-offset: 2px; border-radius: 6px; }
img { max-width: 100%; }

/* ── 頂端導覽列 ── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(13, 18, 31, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 15px;
}
.brand-name { font-size: 15.5px; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; }
.brand-page { font-size: 13px; color: var(--text-2); white-space: nowrap; }
.brand-sep { color: var(--text-3); }
.topbar-side { display: flex; align-items: center; gap: 10px; flex: none; }

.sys-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--good);
  background: var(--good-dim); border: 1px solid rgba(61, 220, 151, 0.28);
  border-radius: 999px; padding: 4px 12px; white-space: nowrap;
}
.sys-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); flex: none; }
.sys-pill.offline { color: var(--warn); background: var(--warn-dim); border-color: rgba(242, 201, 76, 0.3); }
.sys-pill.offline .dot { background: var(--warn); }

.update-btn {
  background: linear-gradient(90deg, var(--accent-a), var(--accent-b));
  color: #fff; border: none; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; padding: 6px 14px;
}

/* ── 主容器與頁首 ── */
.container { max-width: 1180px; margin: 0 auto; padding: 18px 20px 30px; }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 14px; margin: 4px 0 14px; }
.page-head h1 { font-size: 21px; font-weight: 800; margin: 0; letter-spacing: 0.01em; }
.page-meta { font-size: 12.5px; color: var(--text-2); }
.env-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.env-chips .chip {
  font-size: 11.5px; color: var(--text-2);
  border: 1px solid var(--line-strong); border-radius: 999px; padding: 2px 10px;
  background: rgba(255, 255, 255, 0.03); white-space: nowrap;
}

/* ── 區段標題（左側紫條） ── */
.sec-head {
  display: flex; align-items: center; gap: 8px; margin: 20px 0 10px;
}
.sec-head::before {
  content: ""; width: 3.5px; height: 15px; border-radius: 2px;
  background: linear-gradient(180deg, var(--accent-a), var(--accent-b));
}
.sec-head .t { font-size: 15px; font-weight: 700; }
.sec-head .side { margin-left: auto; font-size: 12px; color: var(--text-3); }

/* ── 訊息橫幅（G-03 誠實顯示） ── */
.banner {
  border-radius: var(--radius-s); padding: 10px 14px; margin: 0 0 14px;
  font-size: 13.5px; border: 1px solid var(--line-strong); background: var(--surface-2);
}
.banner.warn { border-color: rgba(242, 201, 76, 0.45); background: var(--warn-dim); color: var(--warn); }
.banner.error { border-color: rgba(240, 113, 120, 0.45); background: var(--bad-dim); color: var(--bad); }

/* ── 模組卡（多模組網格；本 PR 只有美國盤點異常） ── */
.module-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 900px) { .module-grid { grid-template-columns: 1fr 1fr; } }
.module-card {
  position: relative;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px 14px;
  box-shadow: var(--shadow); cursor: pointer; overflow: hidden;
}
.module-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2.5px;
  background: linear-gradient(90deg, var(--accent-a), var(--accent-b), transparent 82%);
}
.module-card:hover { border-color: var(--line-strong); }
.module-card h2 { font-size: 15.5px; font-weight: 700; margin: 0; }
.mc-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.mc-top .period {
  font-size: 11.5px; color: var(--accent-b); border: 1px solid rgba(79, 140, 255, 0.35);
  background: rgba(79, 140, 255, 0.1); border-radius: 6px; padding: 1px 8px; white-space: nowrap;
}

.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 11px;
  margin-left: auto; white-space: nowrap;
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.normal { color: var(--good); background: var(--good-dim); }
.status.attention { color: var(--warn); background: var(--warn-dim); }
.status.partial { color: var(--warn); background: var(--warn-dim); }
.status.blocked { color: var(--bad); background: var(--bad-dim); }

.headline {
  font-size: 16.5px; font-weight: 800; letter-spacing: 0.01em;
  margin: 2px 0 10px; line-height: 1.45; word-break: keep-all; overflow-wrap: anywhere;
}

/* 四數字：緊湊 stat 列 */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0 0 10px; }
.metric {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-s); padding: 8px 6px 7px; text-align: center;
}
.metric .v {
  font-size: 20px; font-weight: 800; line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.metric.m-short .v, .metric.m-extra .v { color: var(--warn); }
.metric .k { font-size: 11px; color: var(--text-2); margin-top: 2px; white-space: nowrap; }

/* 來源列處理進度（紫藍漸層條，同儀表板語言） */
.progress-row { margin: 2px 0 10px; }
.progress-row .lbl {
  display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-2); margin-bottom: 4px;
}
.progress-row .bar { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.progress-row .bar > span {
  display: block; height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent-a), var(--accent-b));
}

.meta-line { font-size: 12px; color: var(--text-2); margin-top: 3px; word-break: keep-all; overflow-wrap: anywhere; }
.meta-line.warnline { color: var(--warn); }
.stale-badge { color: var(--warn); font-weight: 700; }

.card-cta {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line);
  font-size: 13px; font-weight: 700; color: var(--accent-b);
}

.empty-state {
  border-radius: var(--radius-s); border: 1px solid rgba(61, 220, 151, 0.3);
  background: var(--good-dim); color: var(--good);
  font-size: 14.5px; font-weight: 700; padding: 14px; text-align: center; margin: 4px 0 10px;
}
.blocked-state {
  border-radius: var(--radius-s); border: 1px solid rgba(240, 113, 120, 0.4);
  background: var(--bad-dim); color: var(--bad);
  font-size: 13.5px; padding: 12px 14px; margin: 4px 0 10px; line-height: 1.6;
}
.partial-note {
  border-radius: var(--radius-s); border: 1px solid rgba(242, 201, 76, 0.35);
  background: var(--warn-dim); color: var(--warn);
  font-size: 12.5px; padding: 9px 12px; margin: 0 0 10px;
}

/* 首頁側欄（資料警告摘要＋處理統計） */
.home-aside { display: grid; gap: 14px; align-content: start; }
.aside-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 16px 12px; box-shadow: var(--shadow);
}
.ac-title { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.ac-list { margin: 0; padding-left: 17px; }
.ac-list li { font-size: 12.5px; color: var(--text-2); margin: 4px 0; }
.ac-list li .trace { color: var(--text-3); font-size: 11.5px; }
.ac-empty { font-size: 12.5px; color: var(--text-3); margin: 2px 0 6px; }
.ac-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 9px; }
.ac-stat {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-s); padding: 7px 6px; text-align: center;
}
.ac-stat .v { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ac-stat .v.good { color: var(--good); }
.ac-stat .v.warn { color: var(--warn); }
.ac-stat .k { font-size: 10.5px; color: var(--text-2); margin-top: 1px; white-space: nowrap; }

/* ── 載入骨架 ── */
.loading-state { display: grid; gap: 10px; }
.skeleton {
  border-radius: var(--radius); background: linear-gradient(100deg, var(--surface) 40%, var(--surface-2) 50%, var(--surface) 60%);
  background-size: 220% 100%; animation: shimmer 1.2s infinite linear;
}
.skeleton.s1 { height: 150px; }
.skeleton.s2 { height: 78px; }
.loading-label { font-size: 12.5px; color: var(--text-3); text-align: center; }
@keyframes shimmer { to { background-position: -120% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ── 詳情頁 ── */
.back-btn {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  font-size: 13px; padding: 7px 14px; margin: 0 0 12px;
}
.filter-bar {
  display: inline-flex; gap: 4px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px; margin: 0 0 12px 8px;
  vertical-align: middle;
}
.filter-bar button {
  border: none; background: transparent; color: var(--text-2);
  font-size: 12.5px; border-radius: 999px; padding: 5px 13px; white-space: nowrap;
}
.filter-bar button[aria-pressed="true"] {
  background: var(--surface-3); color: var(--text); font-weight: 700;
}

.case-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 2px 0 14px; }
@media (min-width: 980px) { .case-grid { grid-template-columns: 1fr 1fr; align-items: start; } }

/* 案件卡：details 摺疊（手機預設只展開第一案；平板／桌面全展開） */
.case-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.case-card > summary {
  list-style: none; cursor: pointer; padding: 12px 14px;
  display: flex; align-items: center; gap: 11px;
}
.case-card > summary::-webkit-details-marker { display: none; }
.case-card > summary .thumb {
  width: 46px; height: 56px; flex: none; border-radius: 7px;
  object-fit: contain; background: #e9ebef;
}
.case-sum-main { min-width: 0; flex: 1; }
.case-sum-title { font-size: 13.5px; font-weight: 700; display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.case-status-tag {
  font-size: 11px; font-weight: 700; border-radius: 6px; padding: 1.5px 8px; white-space: nowrap;
}
.case-status-tag.open_pending { background: var(--warn-dim); color: var(--warn); }
.case-status-tag.open_manual { background: rgba(79, 140, 255, 0.14); color: var(--accent-b); }
.case-status-tag.closed, .case-status-tag.closed_source_correction { background: var(--good-dim); color: var(--good); }
.case-sum-diff { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.case-caret { flex: none; color: var(--text-3); font-size: 12px; transition: transform 0.15s; }
.case-card[open] .case-caret { transform: rotate(90deg); }
.case-body { padding: 0 14px 13px; border-top: 1px solid var(--line); }

/* 商品對照：圖片優先 */
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 4px; }
.pair .col {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-s); padding: 10px 11px;
}
.pair .col h4 { margin: 0 0 8px; font-size: 12px; color: var(--text-2); font-weight: 700; }
.pair .col.col-extra h4 { color: var(--warn); }
.item-row { display: flex; gap: 10px; align-items: center; padding: 5px 0; }
.item-row + .item-row { border-top: 1px dashed var(--line); }
.product-img {
  width: 62px; height: 76px; flex: none; border-radius: 8px; cursor: zoom-in;
  object-fit: contain; background: #e9ebef; border: 1px solid var(--line-strong);
}
.img-missing {
  width: 62px; min-height: 76px; flex: none; border-radius: 8px;
  border: 1px dashed var(--line-strong); color: var(--text-3);
  font-size: 10px; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 4px; line-height: 1.35;
}
.item-info { min-width: 0; font-size: 13px; }
.item-name { font-weight: 700; }
.item-attrs { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 3px; }
.item-attrs .a {
  font-size: 11px; color: var(--text-2); border: 1px solid var(--line-strong);
  border-radius: 5px; padding: 0.5px 7px; background: rgba(255, 255, 255, 0.03);
}
.item-attrs .a.size { color: var(--text); font-weight: 700; border-color: rgba(79, 140, 255, 0.4); }
.item-note { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }
.img-missing-reason { font-size: 11.5px; color: var(--warn); margin-top: 3px; }

.judgment {
  font-size: 13px; margin: 10px 0 2px; color: var(--text);
  border-left: 2.5px solid var(--accent-b); padding-left: 10px;
}
.pending {
  font-size: 13px; color: var(--warn); margin: 8px 0 2px;
  border-left: 2.5px solid var(--warn); padding-left: 10px;
}

details.sources { margin-top: 10px; }
details.sources > summary, details.audit-details > summary {
  cursor: pointer; font-size: 12px; color: var(--text-3);
}
details.sources .detail-body {
  font-size: 11.5px; color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 9px 11px; margin-top: 7px; line-height: 1.8;
  overflow-x: auto; white-space: nowrap;
}

/* 警告區 */
.warnings {
  background: var(--surface); border: 1px solid rgba(242, 201, 76, 0.3);
  border-radius: var(--radius); padding: 12px 15px; margin: 2px 0 14px;
}
.warnings h3 { margin: 0 0 7px; font-size: 13px; color: var(--warn); }
.warnings ul { margin: 0; padding-left: 18px; }
.warnings li { font-size: 12.5px; color: var(--text-2); margin: 3px 0; }
.warnings li .trace { color: var(--text-3); font-size: 11.5px; }

/* 稽核區（技術與契約資訊集中處，預設收合） */
details.audit-details {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 11px 15px; margin: 2px 0 14px;
}
.audit-body {
  font-size: 11.5px; color: var(--text-3); margin-top: 8px; line-height: 1.9;
  overflow-x: auto;
}

/* ── 圖片放大檢視 ── */
.lightbox {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(8, 11, 20, 0.82); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.lightbox-panel {
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-width: min(480px, 92vw); width: 100%; padding: 14px;
}
.lightbox-panel img {
  width: 100%; height: min(56vh, 460px); object-fit: contain;
  border-radius: var(--radius-s); background: #e9ebef;
}
.lightbox-cap { font-size: 13.5px; font-weight: 700; margin: 10px 2px 2px; }
.lightbox-sub { font-size: 12px; color: var(--text-2); margin: 0 2px; }
.lightbox-close {
  width: 100%; margin-top: 11px; background: var(--surface-3); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  font-size: 13px; padding: 8px;
}

/* ── 驗收演示面板／頁尾 ── */
.dev-panel {
  max-width: 1180px; margin: 6px auto 0; padding: 10px 20px;
  border-top: 1px solid var(--line); color: var(--text-3);
}
.dev-panel summary { cursor: pointer; font-size: 12px; }
.dev-panel-buttons { display: flex; flex-wrap: wrap; gap: 7px; margin: 10px 0 6px; }
.dev-panel-buttons button {
  background: var(--surface); color: var(--text-2);
  border: 1px solid var(--line-strong); border-radius: 999px;
  font-size: 12px; padding: 5px 12px;
}
.dev-panel-buttons button[aria-pressed="true"] {
  color: var(--text); border-color: var(--accent-b); background: rgba(79, 140, 255, 0.12);
}
.dev-toggle { font-size: 11.5px; display: block; margin-top: 4px; }
.page-foot {
  max-width: 1180px; margin: 0 auto; padding: 12px 20px 26px;
  font-size: 11.5px; color: var(--text-3); text-align: center;
}

/* ── 響應式 ── */
@media (max-width: 719px) {
  .container { padding: 14px 13px 24px; }
  .brand-page { display: none; }
  .page-head h1 { font-size: 18px; }
  .env-chips { margin-left: 0; }
  .headline { font-size: 15px; }
  .metrics { gap: 6px; }
  .metric .v { font-size: 17px; }
  .metric .k { font-size: 10px; }
  .module-card { padding: 13px 14px 11px; }
  .pair { grid-template-columns: 1fr; }
  .filter-bar { margin-left: 0; display: flex; }
  .filter-bar button { flex: 1; padding: 5px 6px; }
  .product-img { width: 54px; height: 66px; }
}
@media (min-width: 720px) and (max-width: 979px) {
  .pair { grid-template-columns: 1fr 1fr; }
}
