:root {
  --bg: #f3f6f9;
  --surface: #ffffff;
  --surface-alt: #f7fafc;
  --surface-tint: #eef7f5;
  --sidebar: #10263a;
  --sidebar-hover: #1b3a54;
  --ink: #13293d;
  --ink-muted: #4b6175;
  --ink-subtle: #5d7387;
  --border: #dce5ec;
  --border-strong: #c3d2de;
  --accent: #0f8577;
  --accent-hover: #0a6b5f;
  --accent-soft: #e3f5f1;
  --accent-ink: #0c6257;
  --warn: #c4621e;
  --warn-soft: #fff2e6;
  --warn-ink: #964914;
  --focus: #2b8cbe;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 8px rgba(16, 38, 58, 0.04);
  --shadow-md: 0 8px 24px rgba(16, 38, 58, 0.07);
  --ease: cubic-bezier(0.2, 0, 0, 1);
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.5;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; touch-action: manipulation; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, label.file-btn:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.tabular { font-variant-numeric: tabular-nums; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.85; stroke-linecap: round; stroke-linejoin: round; }

.shell { display: flex; min-height: 100dvh; }
.sidebar {
  width: 248px;
  flex: none;
  background: var(--sidebar);
  color: #ffffff;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 32px; }
.brand-mark {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2ec4ad, #138f80);
  border-radius: 12px;
  width: 42px;
  height: 42px;
  color: #062f2b;
  box-shadow: 0 4px 12px rgba(46, 196, 173, 0.25);
}
.brand strong { display: block; font-size: 17px; letter-spacing: 0.02em; }
.brand small { display: block; color: #9db7c9; font-size: 11px; letter-spacing: 0.16em; margin-top: 2px; }

.sidebar nav { display: grid; gap: 6px; }
.nav {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 0;
  color: #c2d4e0;
  text-align: left;
  padding: 11px 14px;
  min-height: 44px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
  transition: background 150ms var(--ease), color 150ms var(--ease);
}
.nav:hover { background: var(--sidebar-hover); color: #ffffff; }
.nav.active {
  background: var(--sidebar-hover);
  color: #ffffff;
  box-shadow: inset 3px 0 0 #3ad1b8;
}
.nav-badge {
  margin-left: auto;
  background: #f6a859;
  color: var(--sidebar);
  border-radius: 99px;
  min-width: 22px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  padding: 2px 7px;
  font-variant-numeric: tabular-nums;
}
.nav-badge:empty { display: none; }

.sidebar-foot {
  margin-top: auto;
  padding: 14px 10px 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: #c2d4e0;
  font-size: 13px;
  line-height: 1.5;
}
.sidebar-foot p { font-size: 12px; color: #9ab3c4; margin: 4px 0 0; }
.connection-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #36d3b2;
  border-radius: 50%;
  margin-right: 6px;
  box-shadow: 0 0 0 3px rgba(54, 211, 178, 0.18);
}

main { width: min(100%, 1520px); padding: 32px 40px 64px; margin: 0 auto; }
.topbar { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin-bottom: 24px; }
.eyebrow { font-size: 12px; font-weight: 800; letter-spacing: 0.14em; color: var(--accent-ink); }
.topbar h1 { font-size: 30px; margin: 4px 0 6px; letter-spacing: -0.025em; line-height: 1.2; }
.topbar p, .section-bar p { color: var(--ink-muted); margin: 0; font-size: 15px; line-height: 1.5; }
.top-actions, .button-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  font-weight: 700;
  font-size: 14px;
  background: var(--surface);
  color: var(--ink);
  white-space: nowrap;
  transition: background 150ms var(--ease), border-color 150ms var(--ease), box-shadow 150ms var(--ease);
}
.btn:hover { border-color: var(--accent); background: var(--surface-alt); }
.btn:active { opacity: 0.9; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #ffffff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.text-btn {
  border: 0;
  background: none;
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 14px;
  padding: 8px 4px;
  min-height: 40px;
}
.text-btn:hover { text-decoration: underline; }

.view { display: none; }
.view.active { display: block; animation: viewIn 160ms var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.metrics { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  border-top: 3px solid var(--border-strong);
  text-align: left;
  width: 100%;
  display: flex;
  flex-direction: column;
}
.metric.metric-btn {
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(16, 38, 58, 0.06);
  transition: transform 140ms var(--ease), box-shadow 140ms var(--ease), border-color 140ms var(--ease), background 140ms var(--ease);
}
.metric.metric-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
  background: #fcfefe;
}
.metric.metric-btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}
.metric-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; }
.metric .label { color: var(--ink-muted); font-size: 14px; font-weight: 600; }
.metric-arrow {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 99px;
  background: var(--surface-alt);
  color: var(--ink-subtle);
  font-size: 13px;
  font-weight: 700;
  flex: none;
  transition: background 140ms var(--ease), color 140ms var(--ease), transform 140ms var(--ease);
}
.metric.metric-btn:hover .metric-arrow {
  background: var(--accent);
  color: #ffffff;
  transform: translateX(2px);
}
.metric strong { display: block; font-size: 34px; margin: 8px 0 4px; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.metric small { color: var(--ink-subtle); font-size: 13px; line-height: 1.45; }
.metric.warn { border-top-color: #e28945; }
.metric.warn strong { color: var(--warn); }
.metric.good { border-top-color: var(--accent); }
.metric.good strong { color: var(--accent-ink); }

.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}
.card-heading, .section-bar { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.section-bar { flex-wrap: wrap; align-items: flex-end; margin-bottom: 20px; }
.section-bar > div:first-child { flex: 1 1 340px; min-width: 0; }
.section-bar .button-row { flex: 0 1 auto; justify-content: flex-end; margin-left: auto; }
.card h2, .section-bar h2 { font-size: 20px; margin: 4px 0 12px; }
.section-bar h2 { font-size: 22px; margin: 0 0 4px; }
.section-bar h3 { margin: 0; font-size: 18px; }
.section-bar.below { margin-top: 28px; margin-bottom: 14px; }

.line-item { display: flex; justify-content: space-between; gap: 12px; padding: 13px 0; border-bottom: 1px solid #edf1f4; align-items: center; }
.line-item:last-child { border-bottom: 0; }
.line-item strong { display: block; font-size: 14px; }
.line-item small { display: block; color: var(--ink-subtle); font-size: 13px; margin-top: 3px; }
.line-date { font-weight: 700; color: var(--accent-ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { color: var(--ink-subtle); padding: 28px 12px; text-align: center; font-size: 14px; }

.workflow { margin-top: 18px; }
.workflow h2 { margin: 4px 0 18px; }
.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.steps div { background: var(--surface-tint); border: 1px solid #d7ece8; border-radius: var(--radius-md); padding: 16px; }
.steps b { display: block; color: var(--accent-ink); font-size: 12px; margin-bottom: 8px; letter-spacing: 0.08em; }
.steps strong { display: block; font-size: 15px; }
.steps span { display: block; color: var(--ink-muted); font-size: 13px; margin-top: 4px; line-height: 1.45; }

.upload-dropzone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  transition: border-color 150ms var(--ease), background 150ms var(--ease);
}
.upload-dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.upload-dropzone strong { display: block; font-size: 15px; }
.upload-dropzone small { display: block; color: var(--ink-muted); font-size: 13px; margin-top: 3px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { width: min(380px, 100%); }
.toolbar span { margin-left: auto; color: var(--ink-muted); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.toolbar input, .toolbar select, input, select {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface);
  color: var(--ink);
  min-height: 44px;
}
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
table { border-collapse: collapse; width: 100%; min-width: 940px; }
th {
  background: var(--surface-alt);
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  padding: 13px 16px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
td { border-top: 1px solid #edf1f4; padding: 13px 16px; vertical-align: middle; font-size: 14px; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #f9fbfc; }
td strong { display: block; }
td small { display: block; color: var(--ink-subtle); margin-top: 3px; font-size: 12px; }
td .cell-action { border: 0; background: none; color: var(--accent-ink); font-weight: 700; min-height: 36px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; }
td .cell-action:hover { background: var(--accent-soft); }
#ordersView table td:nth-child(1),
#ordersView table td:nth-child(2),
#ordersView table td:last-child { white-space: nowrap; }
#ordersView table td:last-child { text-align: right; width: 1%; }
.status-stack .pill { white-space: normal; line-height: 1.35; text-align: left; }

.pill {
  display: inline-block;
  border-radius: 99px;
  padding: 4px 10px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.pill.warn { background: var(--warn-soft); color: var(--warn-ink); }
.pill.muted { background: #edf1f5; color: var(--ink-muted); }

.form-card { padding: 24px; }
.manual-box { margin-top: 24px; }
.manual-box > summary { cursor: pointer; font-weight: 700; font-size: 15px; color: var(--ink-muted); padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); list-style: none; display: flex; align-items: center; justify-content: space-between; }
.manual-box > summary::after { content: '展開 ▾'; font-size: 13px; color: var(--accent-ink); }
.manual-box[open] > summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom: 0; }
.manual-box[open] > summary::after { content: '收合 ▴'; }
.manual-box[open] > .form-card { border-top-left-radius: 0; border-top-right-radius: 0; }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; color: var(--ink-muted); font-size: 14px; font-weight: 700; }
.form-grid input { width: 100%; font-weight: 400; }
.form-grid .wide { grid-column: span 2; }
em { color: var(--warn); font-style: normal; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.review-summary { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.summary-chip { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; font-size: 14px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.summary-chip b { color: var(--ink); margin-left: 8px; }
.review-list { display: grid; gap: 12px; }
.review-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 14px;
  align-items: start;
}
.review-item input[type="checkbox"] { width: 20px; height: 20px; min-height: 20px; margin-top: 2px; accent-color: var(--accent); }
.review-item.blocked { border-left: 4px solid #e28945; }
.review-item.ready { border-left: 4px solid var(--accent); }
.review-item .title { font-weight: 800; }
.review-item .sub { color: var(--ink-subtle); font-size: 13px; margin-top: 4px; }
.review-item .details { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; color: var(--ink-muted); font-size: 14px; font-variant-numeric: tabular-nums; align-items: center; }
.review-item .details b { color: var(--ink); }
.review-item .details .diff-changed { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; border-radius: 6px; padding: 3px 9px; font-weight: 700; }
.review-item .details .diff-changed b { color: #912018; }
.review-item .reason { font-size: 13px; color: var(--warn-ink); font-weight: 600; margin-top: 8px; }

.calendar-head { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 18px 0; }
.calendar-head h3 { font-size: 20px; min-width: 150px; text-align: center; margin: 0; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-sm);
  font-size: 22px;
  width: 44px;
  height: 44px;
  line-height: 1;
}
.icon-btn:hover { border-color: var(--accent); background: var(--surface-alt); }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; background: var(--border); gap: 1px; }
.weekday { background: var(--surface-alt); text-align: center; padding: 12px; color: var(--ink-muted); font-size: 13px; font-weight: 800; }
.day { background: var(--surface); min-height: 118px; padding: 10px; border: 0; text-align: left; color: var(--ink); vertical-align: top; }
.day:hover { background: var(--surface-alt); }
.day.other { background: #f6f8fa; color: #8da0b0; }
.day.selected { box-shadow: inset 0 0 0 2px var(--accent); background: #f7fcfb; }
.day .num { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.day .event { display: block; background: var(--accent-soft); color: var(--accent-ink); border-radius: 5px; font-size: 11px; font-weight: 600; padding: 4px 6px; margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day .event.updated { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; font-weight: 700; }
.day .more { display: block; font-size: 11px; color: var(--ink-muted); font-weight: 600; margin-top: 5px; }
.calendar-detail { margin-top: 18px; }
.calendar-detail h3 { margin: 0 0 6px; }
.calendar-caveat { color: var(--ink-subtle); font-size: 13px; line-height: 1.5; margin-top: 14px; }
.pill.canon-unconfirmed { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; }
.pill.canon-baseline { background: #f2f4f7; color: #344054; border: 1px solid #d0d5dd; }
.pill.canon-changed { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; }
.pill.canon-confirmed { background: #ecfdf3; color: #027a48; border: 1px solid #abefc6; }
.pill.canon-qty { background: #fffaeb; color: #b54708; border: 1px solid #fedf89; }
.pill.canon-overdue { background: #f4f3ff; color: #5925dc; border: 1px solid #d9d6fe; }
.day .event.unconfirmed { background: #f2f4f7; color: #344054; border: 1px solid #d0d5dd; }
.day .event.confirmed { background: #ecfdf3; color: #027a48; border: 1px solid #abefc6; font-weight: 700; }
.day .event.qty-changed { background: #fffaeb; color: #b54708; border: 1px solid #fedf89; font-weight: 700; }
.status-stack { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 4px; }
td .status-stack { align-items: flex-start; }
.outlook-cat-hint { display: block; font-size: 11px; color: var(--ink-subtle); font-weight: 500; }

dialog { border: 0; border-radius: var(--radius-lg); padding: 26px; width: min(850px, calc(100vw - 24px)); box-shadow: 0 24px 80px rgba(12, 39, 60, 0.35); }
dialog::backdrop { background: rgba(12, 38, 59, 0.55); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.dialog-head h2 { margin: 0; }

.notice { padding: 14px 18px; background: var(--accent-soft); color: var(--accent-ink); border: 1px solid #bfe6dc; border-radius: 10px; margin-bottom: 18px; font-weight: 600; }
.notice.error { background: var(--warn-soft); color: var(--warn-ink); border-color: #f4cdb0; }
.sync-compact-card { padding: 14px 18px; margin-bottom: 16px; }
.sync-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.sync-bar-info { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.sync-inline-summary { font-size: 13px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.sync-time { font-size: 12px; color: var(--ink-subtle); font-variant-numeric: tabular-nums; }
.sync-bar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.compact-select { min-width: 190px; max-width: 260px; min-height: 40px; padding: 6px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); font-size: 13px; }
.sync-settings-drawer { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border-strong); }
.sync-settings-drawer .graph-live-box { margin-top: 0; padding-top: 0; border-top: 0; }
.sync-advanced-box { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border-strong); }
.graph-live-box { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--border-strong); }
.graph-live-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.graph-live-head > button { flex: none; }
.graph-live-controls { display: flex; flex-direction: column; gap: 10px; }
.graph-live-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.graph-live-row input[type="password"],
.graph-live-row input[type="text"] { flex: 1 1 360px; min-width: 240px; min-height: 40px; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font: inherit; background: var(--surface); }
.graph-live-row select { flex: 1 1 280px; min-width: 220px; min-height: 40px; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font: inherit; background: var(--surface); }
.remember-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-muted); font-weight: 600; cursor: pointer; white-space: nowrap; user-select: none; }
.remember-toggle input[type="checkbox"] { width: 16px; height: 16px; min-height: 16px; margin: 0; accent-color: var(--accent); }
#syncPlanSummary.review-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
@media (max-width: 1024px) {
  .sidebar { width: 204px; }
  main { padding: 24px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 14px 16px; }
  .brand { padding: 0 4px 12px; }
  .sidebar nav { display: flex; overflow-x: auto; gap: 6px; }
  .nav { white-space: nowrap; padding: 9px 12px; font-size: 14px; }
  .sidebar-foot { display: none; }
  main { padding: 20px 14px 48px; }
  .topbar, .section-bar, .upload-dropzone { align-items: flex-start; flex-direction: column; }
  .topbar h1 { font-size: 26px; }
  .metrics { gap: 10px; }
  .metric { padding: 16px; }
  .metric strong { font-size: 26px; }
  .steps { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: span 1; }
  .calendar-grid .day { min-height: 78px; padding: 6px; }
  .day .event { font-size: 10px; }
  .weekday { padding: 8px 2px; }
  .review-item { grid-template-columns: 28px 1fr; }
  .review-item .pill { grid-column: 2; justify-self: start; }
}
