/* Shared styles for the receipt converter, document generator and image
   enhancer tools. Builds on tools.css + theme.css variables. */

/* ---------- Drop zone ---------- */
.dropzone {
  display: grid; place-items: center; gap: 10px; text-align: center;
  padding: 34px 20px; border: 2px dashed var(--border); border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 5%, transparent);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.drag {
  border-color: var(--accent); background: color-mix(in srgb, var(--accent) 11%, transparent); outline: none;
}
.dropzone svg { width: 40px; height: 40px; color: var(--accent); }
.dropzone b { font-size: 17px; color: var(--text); }
.dropzone span { color: var(--text-secondary); font-size: 14px; }
.dropzone input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.tool-row-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }

.tool-status { min-height: 22px; margin: 14px 0 6px; font-size: 14px; color: var(--text-secondary); }
.tool-status[data-kind="error"] { color: #e5484d; }
.tool-status[data-kind="ok"] { color: #2a9d78; }
progress.tool-progress { width: 100%; height: 6px; accent-color: var(--accent); }

/* ---------- Receipt converter cards ---------- */
.rc-card { border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-top: 16px; background: var(--surface); }
.rc-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.rc-thumb { width: 52px; height: 68px; flex: none; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-alt); }
.rc-title { flex: 1; min-width: 0; display: grid; gap: 4px; }
.rc-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.rc-check { font-size: 12.5px; font-weight: 600; }
.rc-check.ok { color: #2a9d78; }
.rc-check.warn { color: #c98a12; }
.rc-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 700px) { .rc-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.rc-items, .rc-raw { margin-top: 12px; }
.rc-items summary, .rc-raw summary { cursor: pointer; font-weight: 650; color: var(--text); }
.rc-items table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.rc-items th { text-align: left; font-size: 12px; color: var(--text-secondary); padding: 4px 6px; }
.rc-items td { padding: 3px 4px; }
.rc-items td:nth-child(2) { width: 70px; }
.rc-items td:nth-child(3) { width: 110px; }
.rc-items td:nth-child(4) { width: 44px; }
.rc-items input { padding: 8px 9px; }
.rc-raw textarea { width: 100%; margin: 8px 0; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.rc-export { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.rc-export p { color: var(--text-secondary); font-size: 13.5px; margin: 8px 0 0; }

/* ---------- Document generator ---------- */
.doc-modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 18px; }
@media (max-width: 600px) { .doc-modes { grid-template-columns: 1fr; } }
.doc-modes label { position: relative; border: 1px solid var(--border); border-radius: 10px; padding: 12px; cursor: pointer; display: grid; gap: 3px; background: var(--surface); }
.doc-modes label:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, transparent); }
.doc-modes input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.doc-modes b { color: var(--text); }
.doc-modes small { color: var(--text-secondary); font-size: 12.5px; }
.doc-section { margin-top: 20px; }
.doc-section > h3 { font-size: 13px; letter-spacing: .07em; text-transform: uppercase; color: var(--text-secondary); margin: 0 0 10px; }
.doc-lines { width: 100%; border-collapse: collapse; }
.doc-lines th { text-align: left; font-size: 12px; color: var(--text-secondary); padding: 4px 5px; }
.doc-lines td { padding: 3px 3px; }
.doc-lines td:nth-child(2) { width: 70px; }
.doc-lines td:nth-child(3) { width: 110px; }
.doc-lines td:nth-child(4) { width: 76px; }
.doc-lines td:nth-child(5) { width: 40px; }
.doc-lines input { padding: 8px 9px; }
.doc-lines-wrap { margin: 0 0 10px; }
@media (max-width: 640px) {
  .doc-lines thead { display: none; }
  .doc-lines, .doc-lines tbody { display: block; }
  .doc-lines tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 6px; align-items: end; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .doc-lines td { padding: 0; width: auto !important; min-width: 0; }
  .doc-lines td:first-child { grid-column: 1 / -1; }
  .doc-lines td[data-label]::before { content: attr(data-label); display: block; font-size: 11.5px; color: var(--text-secondary); margin-bottom: 3px; }
  .doc-lines input { width: 100%; min-width: 0; }
}
.doc-remember { display: flex; gap: 8px; align-items: center; margin-top: 14px; font-size: 14px; color: var(--text-secondary); }

.doc-paper {
  background: #fff; color: #17233b; border-radius: 6px; padding: 34px 32px; margin-top: 22px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 14px 34px -16px rgba(0,0,0,.35);
  font: 13.5px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-wrap: anywhere; -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.doc-paper * { color: inherit; }
.doc-paper .dp-top { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; border-bottom: 2px solid #17315a; padding-bottom: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.doc-paper .dp-title { font-size: 26px; font-weight: 750; letter-spacing: -.01em; color: #101d35; margin: 0; }
.doc-paper .dp-flag { display: inline-block; margin-top: 6px; padding: 3px 8px; border-radius: 4px; background: #fff4d6; color: #7a5300; font-size: 11.5px; font-weight: 700; letter-spacing: .03em; }
.doc-paper .dp-meta { text-align: right; font-size: 12.5px; color: #4a5a73; }
.doc-paper .dp-meta b { color: #101d35; }
.doc-paper .dp-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.doc-paper .dp-label { font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: #64738b; font-weight: 700; margin-bottom: 3px; }
.doc-paper .dp-pre { white-space: pre-line; }
.doc-paper table { width: 100%; border-collapse: collapse; margin: 6px 0 12px; }
.doc-paper th { text-align: left; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: #fff; background: #17315a; padding: 7px 8px; }
.doc-paper td { padding: 8px; border-bottom: 1px solid #dfe5ee; vertical-align: top; }
.doc-paper .num { text-align: right; white-space: nowrap; }
.doc-paper .dp-totals { margin-left: auto; width: min(100%, 300px); }
.doc-paper .dp-totals td { border: 0; padding: 4px 8px; }
.doc-paper .dp-totals tr.grand td { border-top: 2px solid #17315a; font-weight: 750; font-size: 15px; padding-top: 8px; }
.doc-paper .dp-notes { margin-top: 18px; padding: 10px 12px; background: #f5f8fc; border-radius: 6px; white-space: pre-line; font-size: 12.5px; }
.doc-paper .dp-decl { margin-top: 18px; padding: 12px 14px; border-left: 3px solid #2a9d78; background: #f1f8f5; font-size: 12.5px; }
.doc-paper .dp-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 34px; font-size: 12px; color: #4a5a73; }
.doc-paper .dp-sign div { border-top: 1px solid #8a97ab; padding-top: 6px; }
.doc-paper .dp-foot { margin-top: 22px; font-size: 10.5px; color: #8a97ab; }
@media (max-width: 600px) {
  .doc-paper { padding: 22px 16px; }
  .doc-paper .dp-parties, .doc-paper .dp-sign { grid-template-columns: 1fr; }
  .doc-paper .dp-meta { text-align: left; }
}
@media print {
  body.printing-doc > *:not(main), body.printing-doc main > *:not(.tool-card), body.printing-doc .tool-card > *:not(#doc-print-area), body.printing-doc aside { display: none !important; }
  body.printing-doc main.tool-shell { display: block !important; padding: 0 !important; margin: 0 !important; max-width: none !important; }
  body.printing-doc .tool-card { border: 0 !important; box-shadow: none !important; padding: 0 !important; background: #fff !important; }
  body.printing-doc .doc-paper { box-shadow: none !important; margin: 0 !important; padding: 0 !important; }
  @page { size: A4; margin: 16mm; }
}

/* ---------- Image enhancer ---------- */
.ie-stage { position: relative; margin-top: 16px; border-radius: 10px; overflow: hidden; background: repeating-conic-gradient(#8881 0 25%, transparent 0 50%) 0 0 / 18px 18px; border: 1px solid var(--border); touch-action: none; }
.ie-stage canvas { display: block; width: 100%; height: auto; }
.ie-stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.ie-stage .ie-quad { fill: color-mix(in srgb, var(--accent) 16%, transparent); stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.ie-stage .ie-handle { fill: #fff; stroke: var(--accent); stroke-width: 3; vector-effect: non-scaling-stroke; cursor: grab; }
.ie-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; margin-top: 16px; }
@media (max-width: 600px) { .ie-controls { grid-template-columns: 1fr; } }
.ie-controls label { display: grid; gap: 6px; font-size: 14px; color: var(--text); font-weight: 600; }
.ie-controls input[type="range"] { width: 100%; padding: 0; accent-color: var(--accent); }
.ie-controls output { color: var(--text-secondary); font-weight: 500; font-variant-numeric: tabular-nums; }
.ie-modes { display: flex; flex-wrap: wrap; gap: 8px; }
.ie-modes button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.ie-toggle { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--text); }
.ie-note { font-size: 13px; color: var(--text-secondary); margin: 8px 0 0; }

/* Buttons and panels toggled by the scripts. */
.tool-card [hidden] { display: none !important; }
/* tools.css gives data tables a 620px minimum; these tables manage their own width. */
.doc-paper table, .doc-lines, .rc-items table { min-width: 0; }
.tool-shell > .tool-card { min-width: 0; }
@media (max-width: 480px) {
  .rc-card { padding: 12px; }
  .rc-items td:nth-child(2) { width: 46px; }
  .rc-items td:nth-child(3) { width: 78px; }
  .rc-items td:nth-child(4) { width: 36px; }
  .rc-items input { padding: 7px 6px; }
}
.rc-items table { table-layout: fixed; }
.rc-items input, .rc-fields input, .rc-fields select { min-width: 0; width: 100%; }
@media (max-width: 480px) {
  .rc-items thead { display: none; }
  .rc-items table, .rc-items tbody { display: block; }
  .rc-items tr { display: grid; grid-template-columns: 56px minmax(0, 1fr) 40px; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--border); }
  .rc-items td { padding: 0; width: auto !important; }
  .rc-items td:first-child { grid-column: 1 / -1; }
}
@media (max-width: 480px) {
  .rc-head { align-items: flex-start; }
  .rc-head > button { padding: 8px 12px; font-size: 13px; }
  .rc-check { overflow-wrap: anywhere; }
}

/* ---------- Mileage log generator ---------- */
.ml-shell { grid-template-columns: minmax(0, 1fr); }
.ml-aside { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
@media (max-width: 760px) { .ml-aside { grid-template-columns: 1fr; } }
.ml-h { font-size: 13px; letter-spacing: .07em; text-transform: uppercase; color: var(--text-secondary); margin: 22px 0 10px; }
.ml-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 900px) { .ml-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .ml-grid { grid-template-columns: 1fr; } }
.ml-ev { align-self: end; padding-bottom: 12px; }
.ml-rate-note { margin: 14px 0 0; font-size: 14px; color: var(--text); }
.ml-table-wrap { overflow-x: auto; }
.ml-trips { width: 100%; min-width: 0; border-collapse: collapse; table-layout: fixed; }
.ml-trips th { text-align: left; font-size: 11.5px; color: var(--text-secondary); padding: 4px 4px; font-weight: 650; hyphens: auto; -webkit-hyphens: auto; overflow-wrap: anywhere; }
.ml-trips td { padding: 3px 3px; vertical-align: middle; }
.ml-trips input { padding: 8px 7px; font-size: 13.5px; width: 100%; min-width: 0; }
.ml-trips input.ml-auto { background: color-mix(in srgb, var(--accent) 8%, transparent); border-style: dashed; }
.ml-trips th:nth-child(1) { width: 136px; }
.ml-trips th:nth-child(5), .ml-trips th:nth-child(6) { width: 98px; }
.ml-trips th:nth-child(7) { width: 70px; }
.ml-trips th:nth-child(8) { width: 76px; }
.ml-trips th:nth-child(9) { width: 84px; }
.ml-trips th:nth-child(10) { width: 72px; }
.ml-example table { min-width: 0; font-size: 13.5px; }
.ml-example th, .ml-example td { padding: 8px 7px; }
.ml-trips .ml-amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; color: var(--text); font-size: 13.5px; white-space: nowrap; }
.ml-row-actions { white-space: nowrap; text-align: right; }
.ml-row-actions button { padding: 6px 9px; min-width: 0; }
.ml-flag-row td { font-size: 12.5px; color: #c98a12; padding: 0 4px 6px; }
.ml-empty td { padding: 18px 6px; color: var(--text-secondary); font-size: 14px; }
.ml-trip-actions { margin-top: 12px; }
.ml-totals { display: grid; gap: 6px; margin: 18px 0 4px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.ml-totals > div { display: flex; justify-content: space-between; gap: 14px; font-size: 14px; color: var(--text-secondary); }
.ml-totals > div b { color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }
.ml-totals > div.grand { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 2px; font-size: 15.5px; }
.ml-totals > div.grand span, .ml-totals > div.grand b { color: var(--text); font-weight: 750; }
.ml-export { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.ml-export h3 { margin: 4px 0 10px; font-size: 16px; }
.ml-export h3 + .actions, .ml-export .actions + h3 { margin-top: 0; }
.ml-export .actions + h3 { margin-top: 18px; }
.ml-example td.num, .ml-example th.num { text-align: right; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 860px) {
  .ml-trips thead { display: none; }
  .ml-trips, .ml-trips tbody { display: block; }
  .ml-trips tr[data-i] { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 12px 0 10px; border-top: 1px solid var(--border); }
  .ml-trips td { padding: 0; width: auto; min-width: 0; }
  .ml-trips td[data-label]::before { content: attr(data-label); display: block; font-size: 11.5px; color: var(--text-secondary); margin-bottom: 3px; }
  .ml-trips td[data-label]:nth-child(4) { grid-column: 1 / -1; }
  .ml-trips .ml-amount { align-self: end; text-align: left; font-size: 15px; padding-bottom: 8px; }
  .ml-row-actions { align-self: end; }
  .ml-flag-row { display: block; }
  .ml-flag-row[hidden] { display: none; }
  .ml-flag-row td { display: block; padding: 0 0 8px; }
  .ml-empty { display: block; }
  .ml-empty td { display: block; }
}

/* ---------- Receipt PDF merger ---------- */
.pm-settings { margin-bottom: 18px; }
.pm-settings > h3 { font-size: 13px; letter-spacing: .07em; text-transform: uppercase; color: var(--text-secondary); margin: 0 0 10px; }
.pm-options { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-top: 16px; }
.pm-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; margin: 18px 0 8px; font-size: 14px; color: var(--text-secondary); }
.pm-bar b { color: var(--text); }
.pm-sort { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }
.pm-sort button { padding: 6px 12px; min-height: 0; font-size: 13px; }
.pm-list { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 10px; counter-reset: none; }
.pm-item { display: grid; grid-template-columns: 84px minmax(0, 1fr) auto; gap: 14px; align-items: start; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.pm-item.dragging { opacity: .45; }
.pm-item[draggable="true"] { cursor: grab; }
.pm-thumb { position: relative; width: 84px; height: 108px; display: grid; place-items: center; background: var(--bg-alt); border-radius: 8px; overflow: hidden; }
.pm-thumb img { max-width: 100%; max-height: 100%; }
.pm-no { position: absolute; top: 4px; left: 4px; min-width: 22px; padding: 1px 6px; border-radius: 999px; background: var(--accent); color: var(--bg); font-size: 12px; font-weight: 700; text-align: center; }
.pm-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 8px 12px; min-width: 0; }
.pm-fields label { display: grid; gap: 3px; font-size: 12px; color: var(--text-secondary); min-width: 0; }
.pm-fields input { width: 100%; min-width: 0; padding: 7px 9px; font-size: 14px; }
.pm-file { grid-column: 1 / -1; font-size: 13px; color: var(--text-secondary); overflow-wrap: anywhere; }
.pm-file em { font-style: normal; color: var(--accent); }
.pm-file .pm-warn { color: #e5484d; }
.pm-actions { display: grid; grid-template-columns: repeat(2, 36px); gap: 6px; }
.pm-actions button { width: 36px; height: 36px; min-height: 0; padding: 0; font-size: 16px; line-height: 1; }
@media (max-width: 520px) {
  .pm-item { grid-template-columns: 64px minmax(0, 1fr); }
  .pm-thumb { width: 64px; height: 84px; }
  .pm-actions { grid-column: 1 / -1; grid-template-columns: repeat(4, 1fr); }
  .pm-actions button { width: 100%; }
  .pm-fields { grid-template-columns: 1fr; }
  .pm-sort { margin-left: 0; }
}
