  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  :root {
    --bg: #f5f4f0;
    --surface: #ffffff;
    --surface2: #f0efe9;
    --border: #dddbd3;
    --border2: #c9c7be;
    --text: #1a1a18;
    --text2: #6b6960;
    --text3: #9c9a91;
    --accent: #1a6b4a;
    --accent-light: #e4f2eb;
    --accent-text: #0f4a33;
    --danger: #8b2020;
    --danger-light: #fceaea;
    --radius: 10px;
    --radius-sm: 6px;
  }

  body {
    font-family: 'Noto Sans TC', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 40px 24px 80px;
  }

  .page {
    max-width: 900px;
    margin: 0 auto;
  }

  /* ── Top bar ── */
  .topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
  }
  .brand-logo {
    height: 24px;
    width: auto;
    display: block;
    margin-bottom: 12px;
  }
  .page-title {
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
  }
  .topbar-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
  }
  .rate-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 16px;
  }
  .rate-box label {
    font-size: 12px;
    color: var(--text2);
    white-space: nowrap;
  }
  .rate-box input {
    width: 80px;
    border: none;
    background: transparent;
    font-family: 'DM Mono', monospace;
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    text-align: right;
    outline: none;
  }
  .rate-box span {
    font-size: 12px;
    color: var(--text3);
  }
  .action-bar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

  /* ── Meta (client / quote info) ── */
  .meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
  }
  .meta-field {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
  }
  .meta-field label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.05em;
    color: var(--text3);
    margin-bottom: 5px;
  }
  .meta-field input {
    width: 100%;
    border: none;
    background: transparent;
    font-family: 'Noto Sans TC', sans-serif;
    font-size: 14px;
    color: var(--text);
    outline: none;
  }
  .meta-field input::placeholder { color: var(--border2); }
  .meta-field .valid-hint { font-size: 11px; color: var(--text3); margin-top: 4px; }

  /* ── Summary cards ── */
  .summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 28px;
  }
  .s-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
  }
  .s-label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text3);
    margin-bottom: 8px;
  }
  .s-value {
    font-family: 'DM Mono', monospace;
    font-size: 26px;
    font-weight: 500;
    color: var(--text);
    line-height: 1;
  }
  .s-value.green { color: var(--accent); }
  .s-unit {
    font-size: 13px;
    font-weight: 400;
    color: var(--text3);
    margin-left: 3px;
  }

  /* ── Phase block ── */
  .phase {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 14px;
    overflow: hidden;
  }
  .phase-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
  }
  .phase-color { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
  .phase-name-input {
    flex: 1;
    min-width: 80px;
    font-family: 'Noto Sans TC', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    background: transparent;
    border: none;
    outline: none;
  }
  .phase-meta {
    font-family: 'DM Mono', monospace;
    font-size: 12px;
    color: var(--text3);
    white-space: nowrap;
  }
  .phase-btns { display: flex; gap: 6px; }

  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ── Buttons ── */
  .btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 6px 11px;
    font-family: 'Noto Sans TC', sans-serif;
    font-size: 12px;
    color: var(--text2);
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    white-space: nowrap;
  }
  .btn:hover { background: var(--surface2); color: var(--text); }
  .btn.danger { color: var(--danger); border-color: #f0bebe; }
  .btn.danger:hover { background: var(--danger-light); }
  .btn.primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    font-weight: 500;
  }
  .btn.primary:hover { background: var(--accent-text); border-color: var(--accent-text); }
  .btn.ghost {
    border: 1.5px dashed var(--border2);
    color: var(--text3);
    background: transparent;
  }
  .btn.ghost:hover { color: var(--text); border-color: var(--text3); background: var(--surface2); }
  .phase-head .btn { background: transparent; }
  .phase-head .btn:hover { background: var(--surface); }

  /* ── Table ── */
  table { width: 100%; border-collapse: collapse; min-width: 720px; }
  thead tr { border-bottom: 1px solid var(--border); }
  th {
    padding: 8px 16px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text3);
    text-align: left;
  }
  th.r { text-align: right; }
  td {
    padding: 10px 16px;
    font-size: 13.5px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    vertical-align: top;
  }
  tr:last-child td { border-bottom: none; }
  tbody tr:hover td { background: #fafaf8; }
  td.r { text-align: right; }
  td.mono {
    font-family: 'DM Mono', monospace;
    font-size: 13px;
  }
  td.price-cell {
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    text-align: right;
    font-weight: 500;
    color: var(--accent-text);
  }
  td.idx { color: var(--text3); font-size: 12px; width: 36px; }

  .td-edit {
    border: none;
    background: transparent;
    font-family: 'Noto Sans TC', sans-serif;
    font-size: 13.5px;
    color: var(--text);
    width: 100%;
    outline: none;
    resize: none;
    overflow: hidden;
    line-height: 1.5;
    padding: 1px 0;
  }
  .td-edit:focus { color: var(--accent-text); }
  .hours-input {
    width: 52px;
    border: 1px solid transparent;
    background: transparent;
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    color: var(--text);
    text-align: right;
    outline: none;
    border-radius: var(--radius-sm);
    padding: 2px 4px;
    transition: border-color 0.12s;
  }
  .hours-input:focus { border-color: var(--border2); background: var(--surface2); }
  .del-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text3);
    font-size: 16px;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color 0.12s, background 0.12s;
  }
  .del-btn:hover { color: var(--danger); background: var(--danger-light); }

  .add-row-row { border-top: 1px solid var(--border); }
  .add-row-row td { padding: 0; }
  .add-row-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 9px 16px;
    font-family: 'Noto Sans TC', sans-serif;
    font-size: 12px;
    color: var(--text3);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
  }
  .add-row-btn:hover { background: #f9f8f5; color: var(--text); }

  /* ── Add phase ── */
  .bottom-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 20px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .add-phase-btn {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 11px 18px;
    border: 1.5px dashed var(--border2);
    border-radius: var(--radius);
    background: transparent;
    font-family: 'Noto Sans TC', sans-serif;
    font-size: 13px;
    color: var(--text3);
    cursor: pointer;
    transition: all 0.12s;
    flex: 1;
    justify-content: center;
  }
  .add-phase-btn:hover { color: var(--text); border-color: var(--text3); background: var(--surface); }

  /* ── Billing summary ── */
  .billing {
    margin-top: 28px;
    margin-left: auto;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 20px;
  }
  .bill-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    color: var(--text2);
  }
  .bill-row:last-child { border-bottom: none; }
  .bill-row label { display: flex; align-items: center; gap: 6px; }
  .bill-row .pct-input {
    width: 48px;
    border: 1px solid var(--border);
    background: var(--surface2);
    border-radius: var(--radius-sm);
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    color: var(--text);
    text-align: right;
    outline: none;
    padding: 2px 5px;
  }
  .bill-row .pct-input:focus { border-color: var(--accent); }
  .bill-row input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
  .bill-val {
    font-family: 'DM Mono', monospace;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
  }
  .bill-val.neg { color: var(--danger); }
  .bill-row.total { padding: 14px 0; }
  .bill-row.total span:first-child { font-size: 14px; font-weight: 600; color: var(--text); }
  .bill-row.total .bill-val { font-size: 19px; }
  .bill-val.green { color: var(--accent); }
  .bill-row.deposit { color: var(--text3); }

  /* ── SVG icons ── */
  .icon { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; flex-shrink: 0; }
  .icon-lg { width: 16px; height: 16px; }

  /* ── Saved indicator ── */
  .saved-dot {
    font-size: 11px;
    color: var(--text3);
    display: inline-flex;
    align-items: center;
    gap: 5px;
  }
  .saved-dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

  /* ── Read-only (viewer) mode ── */
  body.readonly .editor-only,
  body.readonly .phase-btns,
  body.readonly .add-row-btn,
  body.readonly .add-row-row,
  body.readonly .add-phase-btn,
  body.readonly .bottom-actions,
  body.readonly .del-cell,
  body.readonly .del-btn,
  body.readonly .reset-wrap { display: none !important; }
  body.readonly .rate-box,
  body.readonly .meta-field { background: transparent; }
  body.readonly input,
  body.readonly textarea { pointer-events: none; }
  body.readonly .hours-input:focus,
  body.readonly .td-edit:focus { border-color: transparent; background: transparent; color: var(--text); }
  /* empty meta fields shouldn't show placeholder in viewer */
  body.readonly .meta-field input::placeholder { color: transparent; }

  /* hide controls while capturing PDF */
  body.exporting .action-bar,
  body.exporting .bottom-actions,
  body.exporting .reset-wrap,
  body.exporting .phase-btns,
  body.exporting .add-row-row,
  body.exporting .del-cell { display: none !important; }

  /* ── Responsive ── */
  @media (max-width: 720px) {
    body { padding: 22px 12px 64px; }
    .topbar { align-items: stretch; gap: 14px; }
    .page-title { font-size: 23px; }
    .topbar-right { align-items: stretch; width: 100%; }
    .rate-box { justify-content: space-between; }
    .rate-box input { width: 110px; }
    .action-bar { justify-content: stretch; }
    .action-bar .btn { flex: 1 1 auto; justify-content: center; min-height: 40px; }
    .meta-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .summary { grid-template-columns: 1fr; gap: 10px; }
    .s-card { display: flex; align-items: baseline; justify-content: space-between; padding: 13px 16px; }
    .s-label { margin-bottom: 0; }
    .s-value { font-size: 22px; }
    .billing { max-width: none; }

    /* phase header: title full-width, buttons + meta below */
    .phase-head { flex-wrap: wrap; }
    .phase-name-input { flex: 1 1 100%; order: 1; }
    .phase-btns { order: 2; margin-left: 19px; }
    .phase-meta { order: 3; margin-left: auto; }
    .phase-head .btn { min-height: 38px; }

    /* table → one card per row */
    .table-scroll { overflow: visible; }
    table { min-width: 0; }
    thead { display: none; }
    table, tbody, tfoot, tr, td { display: block; width: auto; }
    tbody tr {
      position: relative;
      margin: 10px 12px;
      padding: 30px 12px 8px;
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      background: var(--surface);
    }
    tbody tr:hover td { background: transparent; }
    tbody td {
      border: none;
      padding: 5px 0;
      display: flex;
      align-items: flex-start;
      gap: 10px;
    }
    tbody td::before {
      content: attr(data-label);
      flex: 0 0 58px;
      font-size: 11px;
      color: var(--text3);
      padding-top: 4px;
    }
    td.idx {
      position: absolute; top: 8px; left: 12px; padding: 0;
      display: block; font-size: 11px; font-weight: 600; color: var(--text3);
    }
    td.idx::before { content: '項目 '; }
    td.del-cell { position: absolute; top: 3px; right: 4px; padding: 0; display: block; }
    .del-btn { font-size: 18px; padding: 7px 9px; }
    td.r, td.price-cell { text-align: left; }
    td.price-cell { font-size: 14px; }
    .hours-input { width: 80px; min-height: 32px; text-align: left; }
    .td-edit { font-size: 15px; }
    .add-row-btn { min-height: 44px; justify-content: center; }
    .add-phase-btn { min-height: 50px; }
  }
  @media (max-width: 440px) {
    .meta-grid { grid-template-columns: 1fr; }
  }

  /* ── v2: 數量 / 單位 / 單價 欄位 ── */
  .num-input {
    width: 60px; border: 1px solid transparent; background: transparent;
    font-family: 'DM Mono', monospace; font-size: 13px; color: var(--text);
    text-align: right; outline: none; border-radius: var(--radius-sm);
    padding: 2px 4px; transition: border-color 0.12s;
  }
  .num-input.unit { width: 56px; text-align: left; font-family: 'Noto Sans TC', sans-serif; border-bottom: 1px dashed var(--border); border-radius: 0; }
  .num-input.unit:hover { border-bottom-color: var(--border2); background: var(--surface2); }
  body.readonly .num-input.unit, body.exporting .num-input.unit { border-bottom-color: transparent; background: transparent; }
  .num-input.price { width: 86px; }
  .num-input:focus { border-color: var(--border2); background: var(--surface2); }
  .rate-box .unit-mini {
    width: 48px; border: none; background: transparent;
    font-family: 'Noto Sans TC', sans-serif; font-size: 14px; color: var(--text); outline: none;
  }
  .rate-box .cur-sel {
    border: none; background: transparent; font-family: 'DM Mono', monospace; font-size: 14px;
    color: var(--text2); outline: none; cursor: pointer; padding-right: 2px; margin-right: 2px;
    border-right: 1px solid var(--border);
  }

  /* drag handle */
  .drag-handle { cursor: grab; color: var(--border2); font-size: 13px; padding: 0 2px; user-select: none; }
  .drag-handle:hover { color: var(--text3); }
  tr.dragging { opacity: 0.4; }
  tr.drag-over td { box-shadow: inset 0 2px 0 var(--accent); }

  /* status badge + meta select */
  .status-badge {
    display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 10px;
    border-radius: 20px; vertical-align: middle; margin-left: 10px;
  }
  .status-draft { background: var(--surface2); color: var(--text2); }
  .status-sent { background: #e6eef7; color: #1f5aa8; }
  .status-accepted { background: var(--accent-light); color: var(--accent-text); }
  .status-expired { background: var(--danger-light); color: var(--danger); }
  .valid-hint.expired { color: var(--danger); font-weight: 600; }
  select.meta-select {
    width: 100%; border: none; background: transparent;
    font-family: 'Noto Sans TC', sans-serif; font-size: 14px; color: var(--text);
    outline: none; cursor: pointer;
  }

  /* template cards */
  .tpl-card {
    display: block; width: 100%; text-align: left; cursor: pointer;
    padding: 14px 16px; border: 1px solid var(--border); background: var(--surface);
    border-radius: var(--radius); margin: 6px; font-family: 'Noto Sans TC', sans-serif;
    transition: border-color 0.12s, background 0.12s;
  }
  .tpl-card:hover { border-color: var(--accent); background: var(--accent-light); }
  .tpl-name { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
  .tpl-desc { font-size: 12.5px; color: var(--text2); }
  .tpl-meta { font-size: 11px; color: var(--text3); margin-top: 6px; font-family: 'DM Mono', monospace; }
  .tpl-user { position: relative; }
  .tpl-del { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border:none; border-radius: 50%; background: var(--danger-light); color: var(--danger); cursor: pointer; font-size: 12px; }
  .tpl-tag { font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 10px; background: #e6eef7; color: #1f5aa8; vertical-align: middle; margin-left: 4px; }

  /* ── 印章：報價單上的簽章區 ── */
  .stamp-area {
    display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-end;
    justify-content: flex-end; min-height: 10px; margin-top: 12px;
  }
  .stamp-applied { position: relative; }
  .stamp-applied img { display: block; height: var(--stamp-h, 96px); width: auto; }
  .stamp-ctrl {
    position: absolute; top: -12px; right: -8px; display: none; gap: 3px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 2px 4px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.12); z-index: 5;
  }
  .stamp-applied:hover .stamp-ctrl { display: inline-flex; }
  .stamp-szbtn, .stamp-ctrl .stamp-x {
    width: 20px; height: 20px; border-radius: 50%; border: none; cursor: pointer;
    font-size: 13px; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
  }
  .stamp-szbtn { background: var(--surface2); color: var(--text); }
  .stamp-szbtn:hover { background: var(--accent-light); }
  .stamp-ctrl .stamp-x { background: var(--danger); color: #fff; position: static; }
  body.readonly .stamp-ctrl, body.exporting .stamp-ctrl { display: none !important; }

  /* 印章庫面板 */
  .stamp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; padding: 6px; }
  .stamp-cell {
    position: relative; border: 1px solid var(--border); border-radius: var(--radius);
    background: #fbfbf9; padding: 10px; text-align: center; cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
  }
  .stamp-cell:hover { border-color: var(--accent); background: var(--accent-light); }
  .stamp-cell img { height: 76px; width: auto; max-width: 100%; object-fit: contain; }
  .stamp-cell .stamp-name { font-size: 11px; color: var(--text2); margin-top: 6px; word-break: break-all; }
  .stamp-cell .stamp-del {
    position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border:none;
    border-radius: 50%; background: var(--danger-light); color: var(--danger); cursor: pointer; font-size: 12px;
  }
  .stamp-upload {
    grid-column: 1 / -1; border: 1.5px dashed var(--border2); border-radius: var(--radius);
    padding: 14px; text-align: center; color: var(--text3); font-size: 13px; cursor: pointer; background: transparent;
  }
  .stamp-upload:hover { color: var(--text); border-color: var(--text3); }

  /* 備註區 */
  .note-block {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 16px; margin-bottom: 14px;
  }
  .note-label { display:block; font-size: 11px; font-weight: 500; letter-spacing: 0.05em; color: var(--text3); margin-bottom: 5px; }
  .note-input {
    width: 100%; border: none; background: transparent; resize: none; overflow: hidden;
    font-family: 'Noto Sans TC', sans-serif; font-size: 13.5px; color: var(--text); outline: none; line-height: 1.6;
  }
  .note-input::placeholder { color: var(--border2); }
  body.readonly .note-block:has(.note-input:placeholder-shown) { display: none; }

  /* 報價/請款 切換 */
  .doctype-toggle { display: inline-flex; gap: 0; margin-top: 10px; border: 1px solid var(--border2); border-radius: var(--radius-sm); overflow: hidden; }
  .dt-btn {
    border: none; background: var(--surface); color: var(--text2); cursor: pointer;
    font-family: 'Noto Sans TC', sans-serif; font-size: 13px; padding: 6px 16px; transition: background 0.12s, color 0.12s;
  }
  .dt-btn + .dt-btn { border-left: 1px solid var(--border2); }
  .dt-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

  .qno-row { display: flex; align-items: center; gap: 4px; }
  .qno-row input { flex: 1; min-width: 0; }
  .qno-gen { border: none; background: transparent; cursor: pointer; font-size: 15px; padding: 0 2px; line-height: 1; }
  .qno-gen:hover { transform: scale(1.15); }

  /* 後台總覽 */
  #listOverlay .overlay-box { max-width: 800px; }
  .ql-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
  .ql-filters { display: inline-flex; border: 1px solid var(--border2); border-radius: var(--radius-sm); overflow: hidden; }
  .ql-pill { border: none; background: var(--surface); color: var(--text2); cursor: pointer; font-family: 'Noto Sans TC', sans-serif; font-size: 12.5px; padding: 5px 14px; }
  .ql-pill + .ql-pill { border-left: 1px solid var(--border2); }
  .ql-pill.active { background: var(--accent); color: #fff; font-weight: 600; }
  .ql-sum { font-size: 13px; color: var(--text2); font-family: 'DM Mono', monospace; }
  .ql-search { padding: 8px 14px 4px; }
  .ql-search input {
    width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 7px 12px; font-family: 'Noto Sans TC', sans-serif; font-size: 13px; color: var(--text); outline: none; background: #fbfbf9;
  }
  .ql-search input:focus { border-color: var(--border2); }
  .ql-colhead, .ql-row { display: grid; grid-template-columns: 78px 1fr 48px 58px auto 76px 64px; gap: 9px; align-items: center; padding: 9px 14px; }
  .ql-colhead { font-size: 11px; color: var(--text3); letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
  .ql-colhead .r, .ql-row .r { text-align: right; }
  .ql-row { border-bottom: 1px solid var(--border); cursor: pointer; font-size: 13.5px; color: var(--text); }
  .ql-row:last-child { border-bottom: none; }
  .ql-row:hover { background: var(--surface2); }
  .ql-type { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 4px; white-space: nowrap; }
  .ql-type.quo { background: var(--accent-light); color: var(--accent-text); }
  .ql-type.inv { background: #e6eef7; color: #1f5aa8; }
  .ql-read { display: inline-block; font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 10px; background: var(--accent-light); color: var(--accent-text); vertical-align: middle; }
  .ql-acts { display: inline-flex; gap: 2px; justify-content: flex-end; }
  .ql-act { border: none; background: transparent; cursor: pointer; font-size: 14px; padding: 3px 4px; border-radius: 4px; opacity: 0.6; }
  .ql-act:hover { opacity: 1; background: var(--surface); }
  .ql-act.danger:hover { background: var(--danger-light); }
  @media (max-width: 560px) {
    .ql-colhead { display: none; }
    .ql-row { grid-template-columns: 1fr auto auto; row-gap: 3px; }
    .ql-row .li-client { grid-column: 1 / -1; color: var(--text2); }
    .ql-row .li-date { display: none; }
  }

  body.readonly select,
  body.readonly .drag-handle { pointer-events: none; }
  body.readonly .drag-handle { display: none; }
  body.exporting .drag-handle { display: none; }

  /* ── Print styles ── */
  @media print {
    body { background: white; padding: 20px; }
    .phase-btns, .add-row-btn, .bottom-actions, .del-btn, .action-bar,
    .add-row-row, #toast, .reset-wrap, .drag-handle { display: none !important; }
    .phase { page-break-inside: avoid; }
    .table-scroll { overflow: visible; }
    .meta-field, .s-card, .phase, .billing, .rate-box { border-color: #ccc; }
    .bill-row .pct-input, .bill-row input[type=checkbox] { border: none; background: transparent; -webkit-appearance: none; appearance: none; }
  }

  /* ── Document footer (company letterhead + payment) ── */
  .doc-footer {
    margin-top: 30px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 12.5px;
    color: var(--text2);
    line-height: 1.9;
  }
  .doc-footer .df-company {
    display: flex; gap: 14px; flex-wrap: wrap; align-items: baseline;
  }
  .doc-footer .df-company strong { font-size: 14px; color: var(--text); font-weight: 600; }
  .doc-footer .df-addr { color: var(--text3); }
  .doc-footer .df-pay { margin-top: 10px; }
  .doc-footer .df-label {
    display: inline-block; background: var(--accent-light); color: var(--accent-text);
    font-size: 11px; padding: 1px 8px; border-radius: 4px; margin-right: 8px; font-weight: 500;
  }
  @media (max-width: 560px) { .doc-footer .df-company { gap: 8px; } }

  /* ── Quote list overlay ── */
  .overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(26,26,24,0.45);
    z-index: 900;
    align-items: flex-start;
    justify-content: center;
    padding: 60px 16px;
  }
  .overlay-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%; max-width: 620px;
    max-height: 80vh; display: flex; flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
  }
  .overlay-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--border);
    font-weight: 600; font-size: 15px; background: var(--surface2);
  }
  .overlay-body { overflow-y: auto; padding: 6px; }
  .list-item {
    display: grid;
    grid-template-columns: 1fr 1.3fr auto auto;
    gap: 12px; align-items: center;
    width: 100%; text-align: left;
    padding: 12px 14px; border: none; background: transparent;
    border-radius: var(--radius-sm); cursor: pointer;
    font-family: 'Noto Sans TC', sans-serif; font-size: 13.5px; color: var(--text);
    border-bottom: 1px solid var(--border);
  }
  .list-item:last-child { border-bottom: none; }
  .list-item:hover { background: var(--surface2); }
  .li-no { font-family: 'DM Mono', monospace; font-weight: 500; }
  .li-client { color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .li-total { font-family: 'DM Mono', monospace; color: var(--accent-text); white-space: nowrap; }
  .li-date { color: var(--text3); font-size: 12px; white-space: nowrap; }
  @media (max-width: 560px) {
    .list-item { grid-template-columns: 1fr auto; row-gap: 4px; }
    .li-client { grid-column: 1 / -1; }
    .li-date { display: none; }
  }

  /* ── Toast ── */
  #toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: white;
    padding: 10px 20px;
    border-radius: 30px;
    font-size: 13px;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    z-index: 999;
  }
  #toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
