/* ============================================================
   訂單／採購追蹤系統 — 全域化樣式 v3（主表精簡 + 展開分區表單）
   ============================================================ */

:root {
  --bg: #f4f6fa; --card: #fff; --line: #e3e8f0; --txt: #1c2333; --mut: #7a8497;
  --brand: #3b5bdb; --brand-hover: #2b4ac7; --brand-light: #e7f5ff;
  --danger: #e03131; --danger-light: #ffe3e3;
  --ok: #2f9e44; --ok-light: #d3f9d8; --ok-hover: #2b8a3e;
  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; --radius-xl: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08); --shadow-md: 0 4px 12px rgba(0,0,0,.1);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.15);
  --transition: 180ms ease;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin:0; padding:0; background:var(--bg); color:var(--txt); font-family:var(--font); font-size:14px; line-height:1.5; }

/* ====== 全域表單控制 ====== */
input[type="text"],input[type="number"],input[type="search"],input[type="password"],select,textarea {
  font-family:var(--font); font-size:13.5px; color:var(--txt); background:#fff;
  border:1px solid var(--line); border-radius:var(--radius-sm); padding:8px 10px; outline:none;
  transition: border-color var(--transition), box-shadow var(--transition); width:100%;
}
input:focus,select:focus,textarea:focus { border-color:var(--brand); box-shadow:0 0 0 3px rgba(59,91,219,.12); }
input::placeholder { color:var(--mut); opacity:.7; }
button { font-family:var(--font); font-size:13.5px; cursor:pointer; border:none; border-radius:var(--radius-md); padding:8px 14px; font-weight:600; transition:all var(--transition); }
button:active:not(:disabled) { transform:scale(.97); }
button:disabled { opacity:.4; cursor:not-allowed; }
input[type="checkbox"] { width:16px; height:16px; cursor:pointer; accent-color:var(--brand); margin:0; vertical-align:middle; }

/* ====== 按鈕類別 ====== */
.btn { border:none; border-radius:var(--radius-md); padding:10px 14px; font-size:14px; cursor:pointer; font-weight:600; transition:all var(--transition); display:inline-flex; align-items:center; gap:6px; white-space:nowrap; }
.btn:active:not(:disabled) { transform:scale(.97); }
.btn:disabled { opacity:.4; cursor:not-allowed; }
.btn.primary { background:var(--brand); color:#fff; width:100%; margin-top:4px; }
.btn.primary:hover:not(:disabled) { background:var(--brand-hover); }
.btn.ghost { background:transparent; color:var(--mut); border:1px solid var(--line); padding:8px 12px; }
.btn.ghost:hover:not(:disabled) { background:var(--brand-light); color:var(--brand); border-color:var(--brand); }
.btn.export { background:var(--ok); color:#fff; }
.btn.export:hover:not(:disabled) { background:var(--ok-hover); }
.btn.import { background:#1864ab; color:#fff; }
.btn.import:hover:not(:disabled) { background:#125092; }
.btn.small { padding:5px 9px; font-size:12.5px; }
.btn.ghost.small { padding:6px 10px; font-size:12.5px; }
.btn.add-item { background:var(--brand-light); color:#1864ab; border:1px solid #a5d8ff; padding:6px 12px; }
.btn.add-item:hover:not(:disabled) { background:#c3e1ff; }

/* ====== 登入閘門 ====== */
.gate { position:fixed; inset:0; background:rgba(20,28,48,.55); z-index:1000; align-items:center; justify-content:center; display:flex; backdrop-filter:blur(4px); }
.gate[hidden] { display:none; }
.gate-box { background:#fff; border-radius:var(--radius-xl); padding:32px 28px; width:300px; box-shadow:var(--shadow-lg); text-align:center; }
.gate-title { font-size:18px; font-weight:700; margin-bottom:6px; }
.gate-sub { color:var(--mut); margin:0 0 16px; font-size:13px; }
.gate-box input { width:100%; padding:11px 12px; margin-bottom:10px; border:1px solid var(--line); border-radius:var(--radius-md); font-size:14px; }
.err { color:var(--danger); margin:4px 0 8px; font-size:13px; }

/* ====== 頂部導航 ====== */
.topbar { background:var(--card); border-bottom:1px solid var(--line); display:flex; justify-content:space-between; align-items:center; padding:14px 24px; position:sticky; top:0; z-index:50; box-shadow:0 1px 4px rgba(0,0,0,.04); }
.brand { font-size:18px; font-weight:800; }
.userbox { display:flex; align-items:center; gap:12px; }
.who { color:var(--mut); font-size:13px; }

/* ====== 主內容區 ====== */
.wrap { max-width:1680px; margin:0 auto; padding:20px 24px; }
.toolbar { display:flex; gap:10px; flex-wrap:wrap; margin-bottom:14px; align-items:center; }
#search { flex:1; min-width:240px; padding:10px 12px; border:1px solid var(--line); border-radius:var(--radius-md); font-size:14px; }
#search:focus { border-color:var(--brand); box-shadow:0 0 0 3px rgba(59,91,219,.12); }
.subbar { display:flex; gap:10px; align-items:center; margin-bottom:10px; }
.stats { display:flex; gap:14px; flex-wrap:wrap; margin-bottom:14px; }
.stat { background:var(--card); border:1px solid var(--line); border-radius:var(--radius-lg); padding:12px 16px; min-width:120px; transition:box-shadow var(--transition); }
.stat:hover { box-shadow:var(--shadow-sm); }
.stat .k { color:var(--mut); font-size:12px; }
.stat .v { font-size:17px; font-weight:700; margin-top:2px; }

/* ====== 表格（精簡主表） ====== */
.table-wrap { background:var(--card); border:1px solid var(--line); border-radius:var(--radius-lg); overflow:auto; max-height:72vh; box-shadow:var(--shadow-sm); }
table { border-collapse:collapse; width:max-content; min-width:100%; white-space:nowrap; }
thead th { position:sticky; top:0; background:#eef1f8; z-index:2; font-weight:700; font-size:12.5px; color:#333d55; padding:10px 8px; border-bottom:2px solid var(--line); text-align:left; user-select:none; }
th.resizable { position:relative; }
th .resizer { position:absolute; top:0; right:0; width:6px; height:100%; cursor:col-resize; z-index:3; border-radius:2px; }
th .resizer:hover { background:var(--brand); }
thead th.sticky-l, tbody td.sticky-l { position:sticky; z-index:4; background:#eef1f8; }
tbody td.sticky-l { background:#fff; }
th.sticky-l.c0, tbody td.sticky-l.c0 { left:0; z-index:5; }
tbody td { padding:3px 4px; border-bottom:1px solid #eef1f5; vertical-align:middle; }
tbody tr.order-row:nth-child(even) { background:#fafbfe; }
tbody tr.order-row:hover { background:#f2f5ff; }
tbody tr.order-row.dirty-row td { background:#fff8e6; }
td input { border:1px solid transparent; background:transparent; padding:7px 6px; border-radius:var(--radius-sm); font-size:13.5px; width:100%; min-width:60px; color:inherit; transition:all var(--transition); }
td input:focus { border-color:var(--brand); background:#fff; outline:none; box-shadow:0 0 0 2px rgba(59,91,219,.1); }
td input.num { text-align:right; font-variant-numeric:tabular-nums; }
td.tc { text-align:center; }
button.exp { background:#fff; border:1px solid var(--line); border-radius:var(--radius-sm); cursor:pointer; font-size:11px; padding:3px 6px; color:#333d55; transition:all var(--transition); }
button.exp:hover { background:var(--brand-light); border-color:var(--brand); color:var(--brand); }
button.del-order { background:none; border:1px solid transparent; cursor:pointer; font-size:15px; border-radius:var(--radius-sm); padding:2px 5px; transition:all var(--transition); }
button.del-order:hover { background:var(--danger-light); border-color:#ffa8a8; }
button.del-order:disabled { opacity:.35; cursor:not-allowed; }
.risk-red { background:var(--danger-light) !important; border:1px solid #ffa8a8; }
.risk { font-weight:600; }
.items-chips { background:var(--brand-light); color:#1864ab; font-size:12px; padding:3px 9px; border-radius:20px; font-weight:600; }

/* ============================================================
   展開表單（分區佈局）
   ============================================================ */
.detail-row td { background:#f0f4ff !important; padding:16px 20px; }
.detail-form {
  display: flex; flex-direction: column; gap: 16px;
}

/* --- 分區區塊 --- */
.form-section {
  background: #fff; border: 1px solid #d0d7e8; border-radius: var(--radius-lg);
  overflow: hidden;
}
.form-section-title {
  background: #eef1f8; padding: 8px 14px; font-weight: 700; font-size: 13.5px;
  color: #333d55; border-bottom: 1px solid #d0d7e8;
}
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px 16px; padding: 12px 14px;
}
.form-row { display: flex; flex-direction: column; gap: 3px; }
.form-row label { font-size: 12px; color: var(--mut); font-weight: 500; }
.form-row input { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 13.5px; }
.form-row input:focus { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(59,91,219,.1); }
.form-row input.num { text-align: right; font-variant-numeric: tabular-nums; }
.form-row.wide { grid-column: 1 / -1; }
.form-check {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13.5px; transition: all var(--transition);
  align-self: start; margin-top: 18px;
}
.form-check:hover { background: var(--brand-light); border-color: var(--brand); }
.form-check input { accent-color: var(--brand); }

/* --- 品項明細區 --- */
.detail-items { background: #fff; border: 1px solid #d0d7e8; border-radius: var(--radius-lg); overflow: hidden; }
.detail-items-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: #eef1f8; border-bottom: 1px solid #d0d7e8; font-weight: 700; font-size: 13.5px;
}
.detail-items-head .btn { margin-left: auto; }
.items-table { padding: 8px 14px; }
.items-header {
  display: grid; grid-template-columns: 36px 1.5fr 1.2fr 60px 60px 90px 90px 90px 90px 80px;
  gap: 6px; font-size: 11.5px; color: var(--mut); font-weight: 600;
  padding: 4px 0; border-bottom: 1px solid var(--line); margin-bottom: 4px;
}
.item-row {
  display: grid; grid-template-columns: 36px 1.5fr 1.2fr 60px 60px 90px 90px 90px 90px 80px;
  gap: 6px; align-items: center; margin-bottom: 4px;
}
.item-row input { padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 13px; width: 100%; }
.item-row input:focus { border-color:var(--brand); box-shadow:0 0 0 2px rgba(59,91,219,.1); }
.item-amt { font-weight:700; color:var(--ok); text-align:right; font-variant-numeric:tabular-nums; font-size:13px; }
.item-cost-amt { font-weight:700; color:var(--danger); text-align:right; font-variant-numeric:tabular-nums; font-size:13px; }
.tax-note { font-size:10px; color:var(--mut); font-weight:400; margin-left:2px; }
.tax-total { font-size:11.5px; color:var(--mut); margin-top:2px; font-weight:500; }
.form-tax-hint { font-size:11.5px; color:var(--brand); margin-top:2px; font-weight:500; }
.ih-act { display: flex; gap: 4px; justify-content: center; }
.ih-arr { width: 36px; text-align: center; }
.f-item-cb { width: 16px; height: 16px; accent-color: var(--ok); cursor: pointer; }
.no-items { color:var(--mut); font-size:13px; padding:8px 0; }
.delivery-bar {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
  padding: 10px 14px; background: #f8f9fb; border-bottom: 1px solid #e3e8f0;
}
.delivery-bar .form-row { min-width: 140px; flex: 1; }
.delivery-bar .form-row label { font-size: 11.5px; color: var(--mut); font-weight: 500; }
.delivery-bar .form-row input { padding: 6px 8px; font-size: 13px; }
.delivery-bar .form-check { margin-top: 0; margin-bottom: 0; }

/* ====== Toast ====== */
.toast { position:fixed; bottom:24px; left:50%; transform:translateX(-50%); background:var(--txt); color:#fff; padding:11px 18px; border-radius:var(--radius-md); font-size:14px; font-weight:500; z-index:2000; box-shadow:var(--shadow-lg); opacity:0; transition:opacity .25s, transform .25s; pointer-events:none; max-width:90vw; text-align:center; }
.toast.show { opacity:1; transform:translateX(-50%) translateY(-4px); }

/* ====== 響應式 ====== */
@media (max-width:900px) {
  .brand { font-size:15px; }
  .topbar { padding:10px 16px; flex-wrap:wrap; gap:8px; }
  .wrap { padding:12px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .items-header, .item-row { grid-template-columns: 1fr 1fr 50px 50px 80px 80px 70px; }
}
@media (max-width:600px) {
  .form-grid { grid-template-columns: 1fr; }
  .items-header, .item-row { grid-template-columns: 1fr 50px 80px 70px; }
  .items-header .ih-spec, .items-header .ih-unit,
  .item-row .ih-spec, .item-row .ih-unit { display:none; }
}

/* ====== 捲動條 ====== */
.table-wrap::-webkit-scrollbar { width:8px; height:8px; }
.table-wrap::-webkit-scrollbar-track { background:#f1f3f5; border-radius:4px; }
.table-wrap::-webkit-scrollbar-thumb { background:#c1c8d4; border-radius:4px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background:#a0a8b4; }

/* ====== 分頁標籤 ====== */
.tab-bar {
  display: flex; gap: 0; background: #fff; border-bottom: 2px solid var(--line);
  padding: 0 24px; position: sticky; top: 56px; z-index: 40;
}
.tab-btn {
  padding: 12px 20px; font-size: 14px; font-weight: 600; color: var(--mut);
  border: none; border-bottom: 3px solid transparent; border-radius: 0;
  background: transparent; cursor: pointer; transition: all var(--transition);
}
.tab-btn:hover { color: var(--brand); background: var(--brand-light); }
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ====== 底部操作列 ====== */
.bottom-bar {
  display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px;
  padding: 12px 0; border-top: 1px solid var(--line);
}

/* ====== 條件篩選 ====== */
.filter-panel { background:#fff; border:1px solid var(--line); border-radius:var(--radius-lg); padding:16px; margin-bottom:16px; }
.filter-row { display:flex; gap:12px; flex-wrap:wrap; margin-bottom:10px; align-items:flex-end; }
.filter-row:last-child { margin-bottom:0; }
.filter-group { display:flex; flex-direction:column; gap:3px; min-width:140px; flex:1; }
.filter-group label { font-size:11.5px; color:var(--mut); font-weight:500; }
.filter-group input, .filter-group select { padding:6px 8px; border:1px solid var(--line); border-radius:var(--radius-sm); font-size:13px; }
.filter-group input:focus, .filter-group select:focus { border-color:var(--brand); box-shadow:0 0 0 2px rgba(59,91,219,.1); }
.filter-actions { display:flex; gap:8px; align-items:center; margin-left:auto; }
.filter-actions .btn { white-space:nowrap; }
.filter-count { font-size:13px; color:var(--mut); font-weight:500; }

/* ====== 操作紀錄 ====== */
.log-action {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.log-create { background: #d3f9d8; color: #2b8a3e; }
.log-update { background: #fff3bf; color: #e67700; }
.log-delete { background: #ffe3e3; color: #c92a2a; }
.log-login { background: #e7f5ff; color: #1864ab; }

/* ====== Print ====== */
@media print {
  .topbar,.toolbar,.subbar,.toast,button { display:none !important; }
  .table-wrap { max-height:none; overflow:visible; }
  .detail-row td { background:#fff !important; }
}
