/* 叫貨後台 外框＋共用元件（各畫面專屬樣式寫在 views.css）
   版面：≥1024 左側欄；<1024 頂欄＋底部分頁列＋「更多」抽屜
   防破版：grid 一律 minmax(0,1fr)；長字 overflow-wrap:anywhere；寬表只讓表格本身橫捲 */

/* ── 登入 ───────────────────────────── */
.hq-login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.hq-login-card { width: min(420px, 100%); background: var(--white); border: 1px solid var(--hair); border-radius: var(--r); padding: 28px 24px; display: grid; gap: 4px; }
.hq-back { display: inline-flex; align-items: center; min-height: 48px; color: var(--ink); font-weight: 700; text-decoration: none; font-size: 17px; }
.hq-login-card .logo.lg { height: 88px; margin: 8px auto 4px; }
.hq-login-title { font-family: var(--serif); font-size: 26px; font-weight: 600; text-align: center; margin: 4px 0 0; }
.hq-login-hint { text-align: center; color: var(--ink-2); margin: 0 0 8px; }
.hq-check { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 16px; color: var(--ink-2); }
.hq-check input { width: 22px; height: 22px; accent-color: var(--red); margin: 0; }
.hq-err { color: var(--red); min-height: 1.4em; font-size: 15px; font-weight: 700; overflow-wrap: anywhere; }
.hq-wrong { border: 1px solid var(--red); background: var(--red-wash); border-radius: var(--r); padding: 12px; display: grid; gap: 8px; }
.hq-wrong p { margin: 0; font-weight: 700; color: var(--red); }
.hq-login-foot { display: flex; justify-content: center; margin-top: 16px; }

/* ── 欄位 ───────────────────────────── */
.field { display: grid; gap: 6px; font-size: 14px; color: var(--ink-2); margin: 0 0 12px; min-width: 0; }
.field input, .field select, .field textarea { width: 100%; min-width: 0; height: 44px; padding: 0 12px; border: 1px solid var(--hair); border-radius: var(--r);
  background: var(--white); color: var(--ink); font-size: 16px; }
.field textarea { height: auto; min-height: 96px; padding: 10px 12px; line-height: 1.5; resize: vertical; font-family: var(--sans); }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--ink); outline-offset: 0; }
.hq-hint { color: var(--ink-3); font-size: 13px; line-height: 1.45; }
.hq-req { color: var(--red); font-size: 12px; font-weight: 700; margin-left: 4px; }
.hq-form { display: grid; gap: 0 16px; }
.mo-modal.wide { width: min(100%, 720px); }
@media (min-width: 720px) { .mo-modal.wide .hq-form { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ── 外框 ───────────────────────────── */
.hq-app { min-height: 100dvh; }
.hq-side { display: none; }
.hq-top { position: sticky; top: 0; z-index: 20; height: 52px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 0 12px; padding-top: env(safe-area-inset-top); background: var(--paper); border-bottom: 1px solid var(--hair); }
.hq-top .logo { height: 30px; }
.hq-top-t { margin: 0; font-family: var(--serif); font-size: 19px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mo-btn.sm { min-height: 40px; padding: 0 12px; font-size: 15px; }
.hq-readonly { background: #F5EAD0; color: #7A5A0E; border-bottom: 1px solid #C99A2E; padding: 8px 16px; font-size: 14px; font-weight: 700; }
body.readonly [data-write] { display: none !important; }
.hq-main { padding: 16px 12px calc(88px + env(safe-area-inset-bottom)); max-width: 1440px; margin: 0 auto; min-width: 0; }
.hq-main:focus { outline: none; }

.hq-tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  background: var(--white); border-top: 1px solid var(--hair); padding-bottom: env(safe-area-inset-bottom); }
.hq-tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 60px; padding: 4px 2px;
  color: var(--ink-2); text-decoration: none; background: transparent; border: 0; border-radius: 0; font-size: 13px; }
.hq-tab .s { font-size: 18px; line-height: 1; }
.hq-tab .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.hq-tab.active { color: var(--ink); font-weight: 700; box-shadow: inset 0 3px 0 var(--red); }
.hq-tab .b.on { position: absolute; top: 4px; left: 50%; margin-left: 10px; }

.hq-sheet-bg { position: fixed; inset: 0; z-index: 40; background: rgba(28, 28, 28, .45); display: flex; align-items: flex-end; }
.hq-sheet { width: 100%; max-height: 82dvh; overflow: auto; background: var(--white); border-radius: var(--r) var(--r) 0 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); }
.hq-sheet-i { display: flex; align-items: center; justify-content: space-between; min-height: 52px; padding: 0 8px; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--hair); font-size: 17px; }
.hq-sheet-i.active { font-weight: 700; box-shadow: inset 4px 0 0 var(--red); }
.hq-sheet-foot { display: grid; gap: 12px; padding-top: 16px; }

/* 導覽數字標籤 */
.b { display: none; }
.b.on { display: inline-flex; min-width: 22px; height: 22px; padding: 0 6px; align-items: center; justify-content: center; border-radius: 3px;
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--red); color: #fff; }
.b.on.warn { background: #C99A2E; }

.hq-nav-gt { font-size: 13px; color: var(--ink-2); padding: 14px 12px 4px; }
.hq-side-foot .sig, .hq-sheet-foot .sig { white-space: normal; flex-wrap: wrap; row-gap: 2px; }
.hq-who { font-size: 15px; font-weight: 700; overflow-wrap: anywhere; }
.hq-who small { display: block; font-weight: 400; color: var(--ink-2); font-size: 13px; }
.hq-side-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hq-help { color: var(--ink-2); font-size: 14px; }

@media (min-width: 1024px) {
  .hq-app { display: grid; grid-template-columns: 208px minmax(0, 1fr); }
  .hq-side { display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh; overflow-y: auto; background: var(--white); border-right: 1px solid var(--hair); }
  .hq-brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 8px; }
  .hq-brand .logo { height: 32px; }
  .hq-brand-t { font-family: var(--serif); font-weight: 600; font-size: 17px; }
  .hq-nav { flex: 1; padding: 0 8px; }
  .hq-nav-i { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; padding: 0 12px; color: var(--ink); text-decoration: none;
    border-radius: var(--r); font-size: 15px; }
  .hq-nav-i:hover { background: var(--paper); }
  .hq-nav-i.active { background: var(--paper-2); font-weight: 700; box-shadow: inset 4px 0 0 var(--red); }
  .hq-nav-i .t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .hq-side-foot { display: grid; gap: 10px; padding: 16px; border-top: 1px solid var(--hair); }
  .hq-top, .hq-tabbar, .hq-sheet-bg { display: none !important; }
  .hq-app > .hq-readonly, .hq-app > .hq-main { grid-column: 2; }
  .hq-readonly { grid-column: 2; }
  .hq-main { padding: 24px 28px 48px; width: 100%; }
  .mo-toasts { bottom: 24px; }
}
@media (min-width: 1024px) and (max-width: 1279px) { .hq-app { grid-template-columns: 184px minmax(0, 1fr); } }

/* ── 共用頁面元件 ─────────────────────── */
.hq-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.hq-head-t { min-width: 0; }
.hq-head h1 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 24px; line-height: 1.3; overflow-wrap: anywhere; }
.hq-head-sub { color: var(--ink-2); font-size: 14px; margin-top: 4px; overflow-wrap: anywhere; }
.hq-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.hq-tools .field { margin: 0; }
.hq-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.hq-filters .field { margin: 0; min-width: 140px; flex: 0 1 auto; }
.hq-filters .field.grow { flex: 1 1 220px; }

.panel { background: var(--white); border: 1px solid var(--hair); border-radius: var(--r); padding: 16px; margin-bottom: 16px; min-width: 0; }
.panel > h2, .panel-h h2 { margin: 0 0 12px; font-size: 17px; font-weight: 700; color: var(--ink); }
.panel-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.panel-h h2 { margin: 0; }
.panel.accent { box-shadow: inset 4px 0 0 var(--red); }
.panel.warn { box-shadow: inset 4px 0 0 #C99A2E; }

.grid2 { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }
@media (min-width: 768px) { .kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); } }
.kpi { background: var(--white); border: 1px solid var(--hair); border-radius: var(--r); padding: 12px 14px; min-width: 0; container-type: inline-size; }
.kpi .k { font-size: 13px; color: var(--ink-2); }
.kpi .v { font-family: var(--serif); font-weight: 600; font-size: 26px; font-size: clamp(16px, 16cqi, 30px); line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .v small { font-size: .55em; color: var(--ink-2); font-family: var(--sans); font-weight: 500; }
.kpi.bad .v { color: var(--red); } .kpi.ok .v { color: var(--green); }
.kpi.accent { box-shadow: inset 4px 0 0 var(--red); }

/* 表格：容器橫捲（只捲表格本身），手機可改用 .cards 列表 */
.tbl-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--hair); border-radius: var(--r); background: var(--white); }
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th { text-align: left; font-weight: 700; color: var(--ink-2); font-size: 13px; padding: 10px 10px; border-bottom: 1px solid var(--hair); background: var(--paper); white-space: nowrap; position: sticky; top: 0; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--hair); vertical-align: middle; font-variant-numeric: tabular-nums; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--paper); }
.tbl tr.click { cursor: pointer; }
.tbl .r { text-align: right; } .tbl .c { text-align: center; }
.tbl .nowrap { white-space: nowrap; }
.tbl .name { min-width: 160px; overflow-wrap: anywhere; }
.tbl .sub { display: block; color: var(--ink-2); font-size: 13px; }
.tbl tr.muted td { color: var(--ink-3); background: var(--paper); }

.cards { display: grid; gap: 8px; }
.card { background: var(--white); border: 1px solid var(--hair); border-radius: var(--r); padding: 12px 14px; min-width: 0; display: grid; gap: 6px; }
.card.click { cursor: pointer; }
.card-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-h b { overflow-wrap: anywhere; min-width: 0; font-size: 16px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--ink-2); font-size: 14px; }
.show-desk { display: none; } .show-mob { display: block; }
@media (min-width: 900px) { .show-desk { display: block; } .show-mob { display: none; } }

/* 分段選擇（篩選鈕） */
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--paper-2); padding: 3px; border-radius: var(--r); }
.seg button { min-height: 38px; border: 0; background: transparent; padding: 0 12px; font-size: 14px; color: var(--ink-2); border-radius: 4px; }
.seg button.on { background: var(--ink); color: var(--paper); font-weight: 700; }

/* 側邊編輯抽屜（電腦右側滑出、手機全螢幕） */
.drawer-bg { position: fixed; inset: 0; z-index: 60; background: rgba(28, 28, 28, .35); display: flex; justify-content: flex-end; }
.drawer { width: min(560px, 100%); height: 100%; background: var(--white); display: flex; flex-direction: column; box-shadow: var(--shadow-md); }
.drawer-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top)); border-bottom: 1px solid var(--hair); }
.drawer-h h2 { margin: 0; font-family: var(--serif); font-size: 20px; overflow-wrap: anywhere; }
.drawer-b { flex: 1; overflow: auto; padding: 16px; }
.drawer-f { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--hair); flex-wrap: wrap; }

.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.red-t { color: var(--red); } .green-t { color: var(--green); }
.copy-box { width: 100%; min-height: 120px; font-size: 15px; padding: 10px; border: 1px solid var(--hair); border-radius: var(--r); background: var(--paper); font-family: var(--sans); line-height: 1.6; }

@media print {
  .hq-side, .hq-top, .hq-tabbar, .hq-tools, .no-print, .mo-toasts { display: none !important; }
  .hq-app { display: block; }
  .hq-main { padding: 0; }
  body { background: #fff; }
}
