/* 後台樣式 */

.app-header { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
.header-inner { max-width: 1320px; margin: 0 auto; padding: 0 20px; min-height: 64px; display: flex; align-items: center; gap: 20px; }
.header-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; flex: none; }
.header-brand img { height: 36px; width: auto; }
.header-brand .brand-name { display: block; font-weight: 800; color: var(--navy); font-size: 1rem; line-height: 1.2; }
.header-brand .brand-sub { display: block; font-size: 0.74rem; color: var(--muted); }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: var(--radius-sm); color: #475569; font-weight: 600; font-size: 0.9rem; text-decoration: none; white-space: nowrap; }
.nav a:hover { background: var(--soft); color: var(--navy); }
.nav a.active { background: var(--navy); color: #fff; }
.nav .count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--gold); color: #fff; font-size: 0.72rem; display: inline-flex; align-items: center; justify-content: center; }
.user-menu { position: relative; flex: none; }
.user-btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px 4px 4px; cursor: pointer; font: inherit; font-size: 0.88rem; color: var(--text); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--navy); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; }
.user-pop { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); min-width: 180px; padding: 6px; display: none; }
.user-pop.open { display: block; }
.user-pop button, .user-pop a { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; font: inherit; font-size: 0.88rem; color: var(--text); cursor: pointer; text-decoration: none; }
.user-pop button:hover, .user-pop a:hover { background: var(--soft); }
.user-pop .meta { padding: 6px 10px 8px; font-size: 0.78rem; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; }

.page { max-width: 1320px; margin: 0 auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.4rem; color: var(--navy); }
.page-head p { color: var(--muted); font-size: 0.88rem; margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card-title { font-size: 1.02rem; color: var(--navy); display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.step-no { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; background: var(--navy); color: #fff; font-size: 0.82rem; font-weight: 800; flex: none; }
.card-sub { font-weight: 400; color: var(--muted); font-size: 0.82rem; }

/* --- 篩選列 --- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input[type="search"] { flex: 1 1 220px; max-width: 320px; }
.filters select, .filters input[type="date"] { width: auto; min-width: 130px; }
.toggle-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid #cbd5e1; background: #fff; font: inherit; font-size: 0.9rem; font-weight: 600; color: #475569; cursor: pointer; }
.toggle-btn[aria-pressed="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }
.stat-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.stat-chip { border: 1px solid var(--line); background: #fff; border-radius: var(--radius-sm); padding: 8px 14px; cursor: pointer; font: inherit; text-align: left; display: flex; flex-direction: column; min-width: 104px; }
.stat-chip strong { font-size: 1.3rem; color: var(--navy); line-height: 1.2; }
.stat-chip span { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.stat-chip.active { border-color: var(--navy); box-shadow: inset 0 0 0 1px var(--navy); }

/* --- 表格 --- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.list th { text-align: left; font-size: 0.78rem; color: var(--muted); font-weight: 700; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #f8fafc; }
table.list td { padding: 12px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
table.list tr:hover td { background: #fafcff; }
.cell-title a { color: var(--navy); font-weight: 700; text-decoration: none; }
.cell-title a:hover { text-decoration: underline; }
.cell-sub { font-size: 0.78rem; color: var(--muted); }
.cell-money { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--navy); }
.cell-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.note-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-size: 0.76rem; font-weight: 700; white-space: nowrap; }
.empty-row td { text-align: center; color: var(--muted); padding: 40px 10px; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }

/* --- 開單頁 --- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.editor-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.editor-side { position: sticky; top: 80px; display: flex; flex-direction: column; gap: 16px; max-height: calc(100vh - 96px); overflow: auto; }

.cat-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.cat-tab { border: 1px solid var(--line); background: #f8fafc; border-radius: var(--radius-sm); padding: 10px 8px; font: inherit; font-weight: 700; color: #475569; cursor: pointer; font-size: 0.9rem; }
.cat-tab.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.cat-tab .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); margin-left: 6px; vertical-align: middle; }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.plan-card { position: relative; border: 2px solid var(--line); border-radius: var(--radius); padding: 14px; cursor: pointer; background: #fff; text-align: left; font: inherit; display: flex; flex-direction: column; gap: 6px; transition: border-color 0.15s, box-shadow 0.15s; }
.plan-card:hover { border-color: var(--cyan); }
.plan-card.selected { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(11, 63, 118, 0.12); background: #f8fbff; }
.plan-card .badge { align-self: flex-start; font-size: 0.7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #fdf0dc; color: var(--gold-dark); }
.plan-card .pname { font-weight: 800; color: var(--navy); font-size: 0.98rem; }
.plan-card .pprice { font-weight: 800; font-size: 1.1rem; color: var(--text); }
.plan-card .pprice small { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.plan-card .pmeta { font-size: 0.78rem; color: var(--muted); }
.plan-card .phl { font-size: 0.8rem; color: #475569; }
.plan-card .pnote { font-size: 0.78rem; font-weight: 700; color: var(--gold-dark); }
.plan-card .pick { margin-top: auto; font-size: 0.82rem; font-weight: 700; color: var(--blue); }
.plan-card.selected .pick { color: var(--ok); }

.addon-group { margin-bottom: 10px; }
.addon-group h4 { font-size: 0.82rem; color: var(--muted); margin-bottom: 6px; }
.addon-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.addon-chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid #cbd5e1; border-radius: 999px; padding: 6px 14px; background: #fff; font: inherit; font-size: 0.86rem; cursor: pointer; color: var(--text); }
.addon-chip b { color: var(--navy); font-variant-numeric: tabular-nums; }
.addon-chip.selected { background: var(--navy); border-color: var(--navy); color: #fff; }
.addon-chip.selected b { color: var(--cyan); }
.addon-chip.custom { background: var(--blue); border-color: var(--blue); }
.addon-chip.add-custom { border-style: dashed; color: var(--blue); font-weight: 700; background: #f8fbff; }
.addon-chip.add-custom:hover { border-color: var(--blue); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.inline-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-row input[type="number"] { width: 90px; }
.client-suggest { position: relative; }
.suggest-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); max-height: 260px; overflow: auto; margin-top: 4px; }
.suggest-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 12px; font: inherit; font-size: 0.9rem; cursor: pointer; }
.suggest-list button:hover, .suggest-list button:focus { background: var(--soft); outline: none; }
.suggest-list small { color: var(--muted); margin-left: 6px; }

.disc-box { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; display: flex; flex-direction: column; gap: 10px; }

details.adv { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
details.adv > summary { list-style: none; cursor: pointer; padding: 16px 18px; font-weight: 700; color: var(--navy); display: flex; align-items: center; gap: 8px; }
details.adv > summary::after { content: "▾"; margin-left: auto; color: var(--muted); }
details[open].adv > summary::after { content: "▴"; }
details.adv > .adv-body { padding: 0 18px 18px; display: flex; flex-direction: column; gap: 12px; }
.line-editor { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; display: flex; flex-direction: column; gap: 10px; background: #fcfdff; }
.line-editor-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.line-editor-head input[data-f="name"] { flex: 1 1 220px; font-weight: 700; }
.line-editor-head input[data-f="price"] { width: 130px; }
.line-editor-head select { width: auto; }
.row-editor { border-left: 3px solid var(--cyan); padding: 6px 0 6px 10px; display: flex; flex-direction: column; gap: 6px; }
.row-editor-head { display: flex; gap: 6px; align-items: center; }
.row-editor-head input { flex: 1; font-weight: 600; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; width: 32px; height: 32px; cursor: pointer; color: #475569; font-size: 0.9rem; flex: none; }
.icon-btn:hover { border-color: var(--blue); color: var(--navy); }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.hint { font-size: 0.78rem; color: var(--muted); }

.side-total { display: flex; flex-direction: column; gap: 6px; }
.side-total .big { font-size: 1.6rem; font-weight: 800; color: var(--navy); line-height: 1.2; }
.side-total .big small { font-size: 0.85rem; color: var(--muted); }
.side-rows { display: flex; flex-direction: column; gap: 4px; font-size: 0.86rem; }
.side-rows div { display: flex; justify-content: space-between; gap: 10px; }
.side-rows .disc { color: var(--gold-dark); }
.side-rows .grp { margin-top: 6px; font-weight: 700; color: var(--navy); font-size: 0.8rem; }
.side-pay .first-line { margin-top: 4px; color: var(--gold-dark); font-weight: 600; }
.side-pay .first-line b { color: var(--navy); }
.side-pay { font-size: 0.8rem; color: #475569; display: flex; flex-direction: column; gap: 4px; border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 4px; }
.side-actions { display: flex; flex-direction: column; gap: 8px; }
.side-actions .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.save-state { font-size: 0.78rem; color: var(--muted); text-align: center; }
.save-state.dirty { color: var(--warn); font-weight: 600; }
.link-box { display: flex; flex-direction: column; gap: 6px; background: #f8fafc; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; font-size: 0.82rem; }
.link-box code { word-break: break-all; color: var(--navy); font-size: 0.78rem; }

.notes { display: flex; flex-direction: column; gap: 8px; }
.note { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; font-size: 0.86rem; display: flex; flex-direction: column; gap: 6px; background: #fffbeb; border-color: #fde68a; }
.note.resolved { background: #f8fafc; border-color: var(--line); color: var(--muted); }
.note.resolved .note-body { text-decoration: line-through; }
.note-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 0.76rem; color: var(--muted); }
.note-body { white-space: pre-wrap; word-break: break-word; }
.note-actions { display: flex; gap: 10px; align-items: center; }

.locked-banner { background: var(--ok-soft); color: var(--ok); border-radius: var(--radius-sm); padding: 12px 16px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.locked-banner.void { background: #f1f5f9; color: #475569; }
fieldset.locked { border: 0; padding: 0; margin: 0; min-width: 0; }

.mobile-bar { display: none; }

/* --- 客戶回傳 --- */
.return-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.return-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 10px; border-top: 4px solid var(--ok); }
.return-card.acked { border-top-color: var(--line); }
.return-card h3 { font-size: 1rem; color: var(--navy); }
.return-sigs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.return-sigs > div { border: 1px dashed #cbd5e1; border-radius: var(--radius-sm); height: 90px; display: flex; align-items: center; justify-content: center; padding: 6px; background: #fff; }
.return-sigs svg { width: 100%; height: 100%; }
.return-sigs img { max-height: 100%; max-width: 100%; object-fit: contain; }
.return-meta { font-size: 0.82rem; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }

.preview-frame { background: var(--bg); border-radius: var(--radius); padding: 12px; }

/* --- 登入 --- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(135deg, var(--navy) 0%, var(--blue) 100%); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 28px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25); display: flex; flex-direction: column; gap: 16px; }
.login-card .header-brand { justify-content: center; }
.login-card h1 { font-size: 1.15rem; text-align: center; color: var(--navy); }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 0.88rem; font-weight: 600; }

@media (max-width: 1080px) {
  .editor { grid-template-columns: 1fr; }
  .editor-side { position: static; max-height: none; }
}

@media (max-width: 720px) {
  .header-inner { padding: 0 12px; gap: 10px; flex-wrap: wrap; min-height: 56px; }
  .header-brand .brand-sub { display: none; }
  .nav { order: 3; flex-basis: 100%; padding-bottom: 8px; }
  .user-btn .uname { display: none; }
  .user-menu { margin-left: auto; }
  .page { padding: 12px; }
  .cat-tabs { grid-template-columns: 1fr 1fr; }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  table.list.responsive thead { display: none; }
  table.list.responsive tr { display: block; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 10px; background: #fff; }
  table.list.responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 6px 12px; }
  table.list.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 0.78rem; font-weight: 600; flex: none; }
  table.list.responsive td.cell-title { display: block; padding-top: 12px; }
  table.list.responsive td.cell-title::before { display: none; }
  table.list.responsive .empty-row td { display: block; }
  .editor-side .side-actions { display: none; }
  .mobile-bar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(15, 23, 42, 0.08); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); gap: 8px; align-items: center; }
  .mobile-bar .mb-total { flex: 1; font-weight: 800; color: var(--navy); font-size: 0.95rem; line-height: 1.2; }
  .mobile-bar .mb-total small { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 600; }
  .has-mobile-bar { padding-bottom: 90px; }
}
