/* 視覺規範見 UIUX.md：白底、深灰文字、藍色強調、Excel 式表格、資料密集優先 */
:root {
  --bg: #ffffff;
  --text: #2b2f33;
  --muted: #6b7280;
  --line: #d8dde3;
  --accent: #1f5fbf;
  --accent-soft: #eaf1fb;
  --auto-bg: #eef5ff;      /* 已自動帶入 */
  --default-bg: #f5f6f8;   /* 內建預設值 */
  --error: #c0392b;
  --error-bg: #fdecea;
  --ok: #1e7e46;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}
a { color: var(--accent); }

/* 頂部列 */
header.topbar {
  display: flex; align-items: baseline; gap: 12px;
  padding: 10px 18px; border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}
header.topbar h1 { margin: 0; font-size: 16px; font-weight: 700; }
header.topbar .sub { color: var(--muted); font-size: 12px; }

/* 左側導覽 + 主內容 */
.layout { display: flex; min-height: calc(100vh - 44px); }
nav.side {
  width: 168px; flex: none; border-right: 1px solid var(--line);
  padding: 14px 0; background: #fbfcfd;
}
nav.side a {
  display: block; padding: 8px 18px; text-decoration: none; color: var(--text);
}
nav.side a:hover { background: var(--accent-soft); }
nav.side a.active {
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; border-left: 3px solid var(--accent); padding-left: 15px;
}
main { flex: 1; padding: 18px 24px 48px; min-width: 0; }
h2 { font-size: 17px; margin: 0 0 14px; }
h3 { font-size: 14px; margin: 20px 0 8px; color: var(--muted); }

/* 表單 */
.field-row { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 14px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
input[type=text], input[type=date], input[type=file], select {
  padding: 5px 8px; border: 1px solid var(--line); border-radius: 3px;
  font: inherit; background: #fff; min-width: 170px;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
button {
  padding: 7px 18px; border: 1px solid var(--accent); border-radius: 3px;
  background: var(--accent); color: #fff; font: inherit; cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.secondary { background: #fff; color: var(--accent); }
button[disabled] {
  background: #e5e7eb; border-color: #d1d5db; color: #9ca3af; cursor: not-allowed;
}

/* Excel 式表格 */
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
th { background: #f2f4f7; font-weight: 700; white-space: nowrap; }
td.num { text-align: right; white-space: nowrap; }
tr.ignored td { color: var(--muted); background: #fafbfc; }
tr.unrecognized td { background: var(--error-bg); color: var(--error); font-weight: 700; }

/* 狀態標記 */
.tag { font-size: 12px; padding: 1px 6px; border-radius: 3px; white-space: nowrap; }
.tag.ok { color: var(--ok); }
.tag.skip { color: var(--muted); }
.tag.bad { color: var(--error); }

/* 提示區塊 */
.notice { padding: 10px 14px; border-radius: 4px; margin-bottom: 16px; border: 1px solid; }
.notice.error { background: var(--error-bg); border-color: #f0b4ad; color: var(--error); }
.notice.info { background: var(--accent-soft); border-color: #bcd4f2; color: #17457f; }
.notice.ok { background: #e9f7ef; border-color: #b7e0c6; color: var(--ok); }
.notice > b:first-child { display: block; margin-bottom: 4px; }

/* 出貨明細表編輯 */
.sheet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 8px 16px; }
.cell { display: grid; grid-template-columns: 130px 1fr; align-items: center; gap: 8px; }
.cell > span { color: var(--muted); font-size: 13px; text-align: right; }
.cell input, .cell textarea {
  width: 100%; padding: 4px 7px; border: 1px solid var(--line); border-radius: 3px;
  font: inherit; resize: vertical;
}
.cell.auto input, .cell.auto textarea { background: var(--auto-bg); }
.cell.builtin input { background: var(--default-bg); color: #444; }
.legend { display: flex; gap: 18px; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.legend i { display: inline-block; width: 11px; height: 11px; border: 1px solid var(--line); margin-right: 4px; vertical-align: -1px; }
.actions { margin-top: 22px; display: flex; align-items: center; gap: 14px; }

/* ── 雙視窗工作區 ─────────────────────────────────────────────────── */
body.workspace { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.wsbar {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px; background: #16233a; color: #fff; flex: none;
}
.wsbar .title { font-size: 15px; font-weight: 700; margin-right: auto; }
.wsbar .title .gear { opacity: .75; margin-right: 6px; }
.wsbar a { color: #cfe0f7; text-decoration: none; font-size: 13px; }
.wsbar button, .wsbar .filebtn {
  padding: 6px 14px; border-radius: 4px; font-size: 13px; cursor: pointer;
  border: 1px solid rgba(255,255,255,.35); background: transparent; color: #fff;
}
.wsbar .filebtn { background: #2563c9; border-color: #2563c9; }
.wsbar input[type=file] { display: none; }

.split { flex: 1; display: flex; min-height: 0; }
.pane-form { width: 46%; min-width: 380px; overflow-y: auto; padding: 14px 16px 60px; border-right: 1px solid var(--line); }
.pane-preview { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #eef0f3; }
.pane-preview .bar {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  background: #fff; border-bottom: 1px solid var(--line); flex: none;
}
.pane-preview .bar .t { font-weight: 700; }
.pane-preview .bar .sync { font-size: 12px; color: var(--muted); background: #eef2f7; padding: 2px 8px; border-radius: 10px; }
.pane-preview .bar .dl {
  margin-left: auto; background: #157347; border-color: #157347; color: #fff;
}
.pane-preview .scroll { flex: 1; overflow: auto; padding: 14px; }
.a4-wrap { transform-origin: top left; box-shadow: 0 1px 6px rgba(0,0,0,.18); width: max-content; }

/* 左側表單卡片 */
.card { border: 1px solid var(--line); border-radius: 5px; padding: 10px 12px; margin-bottom: 8px; background: #fff; }
.card > .head { font-size: 13px; font-weight: 700; margin-bottom: 7px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card > .head .src { background: var(--accent-soft); color: var(--accent); padding: 1px 7px; border-radius: 3px; font-weight: 600; }
.card > .head .arrow { color: var(--muted); }
.card .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card .pair > label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.card textarea {
  border: 1px solid var(--line); border-radius: 3px; padding: 5px 7px;
  font: inherit; font-size: 13px; resize: vertical; min-height: 34px;
}
.card textarea.auto { background: var(--auto-bg); }
.card textarea.builtin { background: var(--default-bg); }
.section-title { font-size: 12px; font-weight: 700; color: var(--muted); margin: 16px 0 7px; letter-spacing: 1px; }
.basic { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.basic label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.basic input { padding: 5px 8px; border: 1px solid var(--line); border-radius: 3px; font: inherit; }
.saved-hint { font-size: 12px; color: var(--ok); margin-left: 8px; opacity: 0; transition: opacity .2s; }
.saved-hint.on { opacity: 1; }
