/* 代營運出貨平台：共用樣式（內勤與客戶網站） */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --line: #e3e6eb;
  --line-strong: #cfd4dc;
  --primary: #2f5bd3;
  --primary-ink: #ffffff;
  --primary-soft: #e8eefc;
  --danger: #c2343a;
  --ok: #1f8a4c;
  --warn: #b26a00;
  --nav-bg: #1f2633;
  --nav-ink: #c9d1de;
  --nav-active: #ffffff;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 20px; margin: 0; }
h3 { font-size: 15px; margin: 0; }
h4 { font-size: 14px; margin: 12px 0 6px; }
.muted { color: var(--muted); }
.pre { white-space: pre-wrap; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ── 版面（內勤）── */
.layout { display: flex; min-height: 100vh; }
.sidenav { width: 210px; background: var(--nav-bg); color: var(--nav-ink); flex-shrink: 0; display: flex; flex-direction: column; }
.sidenav .brand { padding: 16px; font-weight: 700; color: #fff; font-size: 15px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidenav .brand small { display: block; font-weight: 400; color: var(--nav-ink); font-size: 12px; }
.sidenav .group { padding: 10px 16px 4px; font-size: 12px; color: #8792a6; letter-spacing: .04em; }
.sidenav a.nav { display: block; padding: 7px 16px 7px 22px; color: var(--nav-ink); text-decoration: none; border-left: 3px solid transparent; }
.sidenav a.nav:hover { background: rgba(255,255,255,.05); color: #fff; }
.sidenav a.nav.active { background: rgba(255,255,255,.09); color: var(--nav-active); border-left-color: #7aa2ff; }
.sidenav .nav-foot { margin-top: auto; padding: 12px 16px; font-size: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.sidenav .nav-foot button { background: none; border: 0; color: var(--nav-ink); padding: 2px 0; cursor: pointer; font: inherit; }
.sidenav .nav-foot button:hover { color: #fff; text-decoration: underline; }
.main { flex: 1; min-width: 0; padding: 20px 24px 40px; }
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidenav { width: 100%; }
  .main { padding: 14px; }
}

/* ── 版面（客戶網站）── */
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.topbar .brand { font-weight: 700; }
.topbar .brand small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.topnav { display: flex; gap: 4px; flex-wrap: wrap; }
.topnav a { padding: 6px 12px; border-radius: 6px; color: var(--text); text-decoration: none; }
.topnav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.topnav a:hover { background: #f0f2f5; }
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

/* ── 頁首、卡片、KPI ── */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 8px; flex-wrap: wrap; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.card-body { padding: 14px 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi-click { cursor: pointer; }
.kpi-click:hover { border-color: var(--primary); }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-size: 26px; font-weight: 700; line-height: 1.2; margin-top: 2px; }
.kpi-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi-red .kpi-value { color: var(--danger); }
.kpi-green .kpi-value { color: var(--ok); }
.kpi-amber .kpi-value { color: var(--warn); }
.kpi-blue .kpi-value { color: var(--primary); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.loading { padding: 20px; color: var(--muted); }
.error-box { padding: 12px 14px; background: #fdecec; color: var(--danger); border-radius: var(--radius); border: 1px solid #f5c2c4; }
.notice { padding: 10px 14px; background: #fff7e6; border: 1px solid #f3d29a; border-radius: var(--radius); color: #6b4a00; margin-bottom: 12px; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }

/* ── 按鈕 ── */
.btn { font: inherit; border: 1px solid var(--line-strong); background: var(--panel); color: var(--text); border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { background: #f3f4f6; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover:not(:disabled) { background: #264cb5; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a62a30; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--primary); }
.btn-sm { padding: 3px 8px; font-size: 13px; }

/* ── 徽章 ── */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; line-height: 20px; white-space: nowrap; }
.badge-gray { background: #eef0f3; color: #4a5263; }
.badge-blue { background: #e6eeff; color: #2346a8; }
.badge-purple { background: #f0e8fd; color: #6234b0; }
.badge-green { background: #e3f5ea; color: #17673a; }
.badge-teal { background: #dff4f2; color: #0d6b62; }
.badge-amber { background: #fff1d6; color: #8a5300; }
.badge-red { background: #fde4e5; color: #a3242a; }

/* ── 表格 ── */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 600; color: #475066; background: #f8f9fb; border-bottom: 1px solid var(--line); padding: 8px 10px; white-space: nowrap; }
.tbl td { border-bottom: 1px solid #eef0f3; padding: 8px 10px; vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover td { background: #f5f8ff; }
.tbl tr.row-warn td { background: #fffaf0; }
.tbl tr.row-bad td { background: #fff3f3; }
.tbl .col-check { width: 34px; text-align: center; }
.empty-cell { text-align: center; color: var(--muted); padding: 24px !important; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 10px 2px; }
.dt-filters { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }
.dt-toolbar { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; align-items: center; }

/* ── 表單 ── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 14px; }
.form-inline .form-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); align-items: end; }
.form-inline { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-inline .form-grid { flex: 1; }
.form-inline .form-actions { padding-top: 0; }
.form-section { grid-column: 1 / -1; margin: 6px 0 0; padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.w-full { grid-column: 1 / -1; }
.field label { font-size: 13px; color: #475066; }
.field .req { color: var(--danger); margin-left: 2px; }
.field .help { font-size: 12px; color: var(--muted); }
.field-check { justify-content: flex-end; }
.check { display: flex; gap: 6px; align-items: center; cursor: pointer; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], input[type=email], select, textarea {
  font: inherit; border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 8px; background: #fff; color: var(--text); width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b9cbff; border-color: var(--primary); }
input[readonly] { background: #f6f7f9; }
.static { padding: 6px 0; }
.form-error, .field-error { color: var(--danger); font-size: 13px; min-height: 0; }
.form-error:not(:empty) { margin-top: 8px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 12px; }

/* ── 分頁籤 ── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tab { font: inherit; background: none; border: 0; padding: 8px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ── 對話框與提示 ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 10px; box-shadow: 0 20px 50px rgba(0,0,0,.25); max-width: 100%; }
.modal:focus { outline: none; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-x { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 18px; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: #1f2633; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); white-space: pre-wrap; }
.toast-ok { background: #17673a; }
.toast-error { background: #a3242a; }

/* ── 時間軸 ── */
.timeline { list-style: none; margin: 0; padding: 0 0 0 4px; }
.timeline li { position: relative; padding: 0 0 14px 20px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid var(--primary); }
.timeline li.tl-bad::before { border-color: var(--danger); }
.timeline li.tl-muted::before { border-color: var(--line-strong); }
.timeline .tl-time { color: var(--muted); font-size: 12px; }
.timeline .tl-msg { font-weight: 500; }
.timeline .tl-note { color: var(--muted); font-size: 12.5px; }

/* ── 掃描作業 ── */
.scan-input { font-size: 20px !important; padding: 12px 14px !important; border: 2px solid var(--primary) !important; letter-spacing: .05em; }
.scan-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.scan-ok { background: #e3f5ea !important; }
.scan-bad { background: #fde4e5 !important; }

/* ── 圖表 ── */
.chart-wrap { width: 100%; overflow-x: auto; }
.chart { width: 100%; min-width: 320px; height: auto; display: block; }
.chart .grid { stroke: #eceff3; }
.chart .axis { font-size: 10px; fill: #8a93a5; }
.chart .bar.clickable { cursor: pointer; }
.chart .bar:hover { opacity: .8; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); padding: 6px 0 0 36px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* ── 登入 ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 26px; }
.login-box h1 { font-size: 19px; margin: 0 0 4px; }
.login-box p { margin: 0 0 18px; color: var(--muted); }
.login-box .form-grid { grid-template-columns: 1fr; }
.login-box .form-actions .btn { width: 100%; }
