/* ==========================================================================
   Receipts drawer
   Per-transaction receipts/documents manager. 420px right-docked push drawer
   (modeled on the mobile receipts workflow + the Indy document drawer).
   Opened via window.openReceiptsDrawer(cfg) in ui.js — the drawer, its two
   modals (receipt preview + Get-the-app QR) and the scrim are built in JS and
   appended to <body>.

   Pages that use it must also link: button.css, input.css (.checkbox),
   dropdown.css (.menu), modal.css (.modal-scrim/.modal). Catalogued in
   preview/index.html. Motion: txDrawerIn open bounce (see CLAUDE.md "Motion").
   ========================================================================== */

@keyframes txDrawerIn { 0% { transform: translateX(100%); } 78% { transform: translateX(-8px); } 100% { transform: translateX(0); } }

.doc-scrim { position: fixed; inset: 0; background: rgba(12,12,13,0.28); z-index: 9995; opacity: 0; transition: opacity .25s ease; }
.doc-scrim.is-open { opacity: 1; }

.doc-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(420px, 100vw);
  background: var(--color-surface);
  z-index: 9997; overflow-y: auto;          /* above the preview so the drawer's shadow falls on it */
  box-shadow: var(--shadow-drawer, var(--shadow-dropdown));
  transform: translateX(100%);
  padding: var(--drawer-pad) var(--drawer-pad) 0; /* global drawer rhythm; the sticky footer owns the bottom */
}
/* Standard drawer footer — a clear primary action so attaching feels saved (Peter, 29 Jun 2026). */
.doc-foot {
  position: sticky; bottom: 0;
  margin: 28px calc(var(--drawer-pad) * -1) 0;
  padding: 16px var(--drawer-pad) var(--drawer-pad-bottom);
  background: var(--color-surface);
  border-top: var(--border-width) solid var(--color-border);
}
.doc-foot .btn { width: 100%; }
.doc-drawer.is-open { animation: txDrawerIn .44s cubic-bezier(0.22,1,0.36,1) both; }
@media (prefers-reduced-motion: reduce) { .doc-drawer.is-open { animation: none; transform: translateX(0); } }

/* Header: transaction title + date · amount, X close (top-right, standard) */
.doc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.doc-head__main { flex: 1; min-width: 0; }
.doc-head__title { font-size: var(--text-title); font-weight: var(--weight-regular); line-height: 1.2; letter-spacing: -0.02em; } /* match the page title exactly — 29px, regular weight (Peter, 25 Jun 2026) */
.doc-head__sub { margin-top: 6px; font-size: var(--text-sm); color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.doc-x { flex: none; width: 30px; height: 30px; margin-top: -2px; border: none; background: none; border-radius: 50%; color: var(--color-text-muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.doc-x:hover { background: var(--color-bg-subtle); color: var(--color-text); }
.doc-x svg { width: 18px; height: 18px; }

.doc-rule { border: none; border-top: var(--border-width) solid var(--color-border); margin: 28px -32px 32px; }

/* Add documents — dashed dropzone */
.doc-drop { position: relative; border: 1.5px dashed var(--color-border-pink); border-radius: var(--radius-lg); padding: 34px 24px; text-align: center; background: transparent; }
/* "Get the app" corner affordance — opens a QR to download the mobile app */
.doc-getapp { position: absolute; top: 10px; right: 10px; display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px 5px 8px; border: var(--border-width) solid var(--color-border-pink); border-radius: 999px; background: var(--color-surface); font: inherit; font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--color-text); cursor: pointer; }
.doc-getapp:hover { background: var(--color-bg-pink-light); }
.doc-getapp svg { width: 15px; height: 15px; color: var(--color-text); }
.doc-drop__icon { width: 44px; height: 44px; border-radius: 50%; background: var(--color-surface); display: inline-flex; align-items: center; justify-content: center; color: var(--color-text); margin-bottom: 12px; box-shadow: var(--shadow-dropdown); }
.doc-drop__icon svg { width: 22px; height: 22px; }
.doc-drop__title { font-weight: var(--weight-bold); font-size: var(--text-base); }
.doc-drop__hint { font-size: var(--text-xs); color: var(--color-text-muted); margin: 8px 0 20px; }

/* Forward receipt — secondary add-channel button, and its takeover of the box */
.doc-fwd-btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; margin-top: 14px; padding: 15px; border: var(--border-width) solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); font: inherit; font-size: var(--text-sm); color: var(--color-text); cursor: pointer; }
.doc-fwd-btn:hover { background: var(--color-bg-subtle); }
.doc-fwd-btn svg { width: 18px; height: 18px; }

.doc-drop__fwd { display: none; }
.doc-drop.is-forwarding { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.doc-drop.is-forwarding .doc-drop__default { display: none; }
.doc-drop.is-forwarding .doc-getapp { display: none; }
.doc-drop.is-forwarding .doc-drop__fwd { display: block; }
.doc-fwd__close { position: absolute; top: 10px; right: 10px; width: 26px; height: 26px; border: none; background: none; border-radius: 50%; color: var(--color-text-muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.doc-fwd__close:hover { background: var(--color-surface); color: var(--color-text); }
.doc-fwd__close svg { width: 15px; height: 15px; }
.doc-fwd__icon { width: 44px; height: 44px; border-radius: 50%; background: var(--color-surface); display: inline-flex; align-items: center; justify-content: center; color: var(--color-success); margin-bottom: 12px; box-shadow: var(--shadow-dropdown); }
.doc-fwd__icon svg { width: 22px; height: 22px; }
.doc-fwd__lead { font-size: var(--text-xs); color: var(--color-text-muted); margin-bottom: 8px; }
.doc-fwd__email { font-weight: var(--weight-bold); font-size: var(--text-base); }
.doc-fwd__copied { display: inline-flex; align-items: center; gap: 5px; margin-top: 10px; font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--color-success); }
.doc-fwd__copied svg { width: 14px; height: 14px; }

/* Receipts section: heading + All/Matched/Unmatched tabs + help */
.doc-listhead { display: flex; align-items: center; justify-content: space-between; margin: 40px 0 18px; }
/* The first section header sits right under the drawer rule — it doesn't need the 40px gap that
   separates one section from the previous one. */
.doc-listhead--first { margin-top: 4px; }
.doc-listhead h3 { font-size: var(--text-base); font-weight: var(--weight-bold); }
.doc-listhead span { font-size: var(--text-xs); color: var(--color-text-muted); }
.doc-tabs { margin-bottom: 18px; }  /* All/Matched/Unmatched use the standard .chip-row--tabs */
.doc-help { display: flex; gap: 8px; align-items: flex-start; font-size: var(--text-xs); color: var(--color-text-muted); line-height: 1.5; margin: 0 2px 24px; }
.doc-help svg { width: 15px; height: 15px; flex: none; margin-top: 1px; color: var(--color-border-strong); }

/* Receipt row: checkbox (attach to this txn) + thumb + body + kebab */
.doc-row { position: relative; display: flex; align-items: center; gap: 14px; padding: var(--drawer-row-pad); border: var(--border-width) solid var(--color-border); border-radius: var(--radius-md); margin-bottom: var(--drawer-row-gap); background: var(--color-surface); }
/* The receipt currently shown in the preview — black border like a selected card */
.doc-row.is-previewing { border-color: var(--color-text); box-shadow: inset 0 0 0 1px var(--color-text); }
/* Ticked (staged) this session — green border + subtle tint + a persistent "Applied" badge so it's
   unmistakable (the thin border alone wasn't registering — Peter, 25 Jun 2026); commits on close */
.doc-row.is-applied { border-color: var(--color-success); background: linear-gradient(to right, var(--color-bg-subtle), var(--color-bg-subtle-light)); }
.doc-row__applied { display: none; flex: none; align-items: center; gap: 4px; padding: 4px 9px; border-radius: 999px; background: var(--color-text); color: #fff; font-size: var(--text-xs); font-weight: var(--weight-bold); white-space: nowrap; }
.doc-row__applied svg { width: 13px; height: 13px; }
.doc-row.is-applied .doc-row__applied { display: inline-flex; }
/* Badge takes the kebab's slot when applied so it doesn't crush the name/date text (Peter, 25 Jun 2026). */
.doc-row.is-applied .doc-kebab { display: none; }
/* Transient "Receipt applied / detached" confirmation that briefly covers the row + a timer bar */
.doc-applied { position: absolute; inset: 0; border-radius: var(--radius-md); background: var(--color-surface); display: flex; align-items: center; justify-content: center; gap: 7px; overflow: hidden; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-success); animation: docAppliedIn .18s ease both; }
.doc-applied.is-out { opacity: 0; transition: opacity .3s ease; }
.doc-applied svg { width: 16px; height: 16px; }
.doc-applied__bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: var(--color-success); animation: docAppliedBar 1.3s linear forwards; }
.doc-applied--off { color: var(--color-text-muted); }
.doc-applied--off .doc-applied__bar { background: var(--color-text-muted); }
@keyframes docAppliedIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes docAppliedBar { to { width: 100%; } }
@media (prefers-reduced-motion: reduce) { .doc-applied { animation: none; } .doc-applied__bar { animation: none; width: 100%; } }
.doc-row .checkbox { flex: none; }
.doc-row__thumb { position: relative; flex: none; width: 42px; height: 42px; border-radius: var(--radius-sm); background: var(--color-bg-subtle); display: inline-flex; align-items: center; justify-content: center; color: var(--color-text-muted); cursor: pointer; border: none; padding: 0; }
.doc-row__thumb:hover { background: var(--color-border); color: var(--color-text); }
.doc-row__thumb svg { width: 18px; height: 18px; }
/* Magnifier badge so it's obvious the receipt opens to preview. */
.doc-row__thumb::after { content: ''; position: absolute; bottom: 2px; right: 2px; width: 17px; height: 17px; border-radius: 50%; background: var(--color-text) center/10px 10px no-repeat; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.5' y2='16.5'/%3E%3C/svg%3E"); box-shadow: 0 0 0 1.5px var(--color-surface); }
.doc-row__thumb--img { background: #fff; border: var(--border-width) solid var(--color-border); overflow: hidden; }
.doc-row__thumb--img img { width: 100%; height: 100%; object-fit: cover; object-position: top center; }
.doc-row__body { flex: 1; min-width: 0; }
.doc-row__name { display: block; font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-row__sub { display: block; font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-kebab { flex: none; width: 28px; height: 28px; border: none; background: none; border-radius: 50%; color: var(--color-text-muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.doc-kebab:hover, .doc-kebab[aria-expanded="true"] { background: var(--color-bg-subtle); color: var(--color-text); }
.doc-kebab svg { width: 18px; height: 18px; }
.doc-empty { font-size: var(--text-sm); color: var(--color-text-muted); text-align: center; padding: 22px 8px; }

.doc-rowmenu { position: absolute; top: 44px; right: 8px; z-index: 5; }
.menu__item--danger { color: var(--color-danger); }

/* Get-the-app QR modal */
.qr-modal { width: 340px; padding: 26px 26px 30px; text-align: center; }
.qr-modal__title { font-size: var(--text-section); font-weight: var(--weight-bold); }
.qr-modal__lede { font-size: var(--text-sm); color: var(--color-text-muted); line-height: 1.45; margin: 8px 0 20px; }
.qr-code { width: 188px; height: 188px; margin: 0 auto; padding: 12px; background: #fff; border: var(--border-width) solid var(--color-border); border-radius: var(--radius-md); }
.qr-code svg { display: block; width: 100%; height: 100%; }
.qr-stores { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }
.qr-store { display: inline-flex; align-items: center; gap: 7px; padding: 8px 13px; border: var(--border-width) solid var(--color-border); border-radius: var(--radius-md); font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--color-text); }
.qr-store svg { width: 16px; height: 16px; }

/* Receipt preview — docked in the body to the LEFT of the drawer (non-blocking, so
   the list stays clickable). Narrow screens fall back to a centered modal. */
.rcpt-preview { position: fixed; top: 0; bottom: 0; left: 0; right: min(420px, 100vw); z-index: 9996; display: flex; align-items: center; justify-content: center; padding: 40px; background: rgba(255, 255, 255, 0.74); }
.rcpt-preview[hidden] { display: none; }
.rcpt-preview .rcpt-modal { box-shadow: var(--shadow-dropdown); }
@media (max-width: 900px) { .rcpt-preview { right: 0; background: rgba(0, 0, 0, 0.43); } }

/* Receipt preview card — image or a styled paper receipt */
.rcpt-modal { width: 360px; max-width: 100%; padding: 22px 22px 28px; }
.rcpt-img { display: block; width: auto; max-width: 100%; max-height: 62vh; margin: 0 auto; border: var(--border-width) solid var(--color-border); border-radius: var(--radius-md); }
.rcpt-paper { border: var(--border-width) solid var(--color-border); border-radius: var(--radius-md); background: #fff; padding: 22px 20px; display: flex; flex-direction: column; gap: 7px; font-size: var(--text-sm); color: var(--color-text); }
.rcpt-paper__h { font-weight: var(--weight-bold); font-size: var(--text-base); }
.rcpt-paper__sh { color: var(--color-text-muted); font-size: var(--text-xs); margin-bottom: 6px; }
.rcpt-paper__row { display: flex; justify-content: space-between; }
.rcpt-paper__row span:last-child { font-variant-numeric: tabular-nums; }
.rcpt-paper__rule { border-top: 1px dashed var(--color-border-strong); margin: 5px 0; }
.rcpt-paper__total { display: flex; justify-content: space-between; font-weight: var(--weight-bold); }

/* GMAIL IN THE DRAWER (28 Aug 2026): the connect row sits with Forward receipt;
   once connected it becomes this quiet standing line. */
.doc-gmail-on {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
.doc-gmail-on svg { width: 16px; height: 16px; color: var(--color-success); flex: none; }
.doc-gmail-on a { color: inherit; }


/* == No receipt (Peter, 3 Sep 2026) ======================================= */
.doc-none { margin: 14px 0 18px; border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 4px 18px; }
.doc-none__toggle { display: flex; align-items: center; gap: 12px; width: 100%; border: none; background: none; font: inherit; color: var(--color-text); padding: 14px 0; cursor: pointer; text-align: left; }
.doc-none__box { width: 18px; height: 18px; border: 1.5px solid var(--color-text); border-radius: 5px; flex: none; position: relative; }
.doc-none.is-on .doc-none__box::after { content: ""; position: absolute; inset: 3px; background: var(--color-text); border-radius: 2px; }
.doc-none__body { display: none; padding: 0 0 18px; }
.doc-none.is-on .doc-none__body { display: block; }
.doc-none__q { margin: 0 0 10px; color: var(--color-text-muted); font-size: var(--text-sm); }
.doc-none__pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.doc-none__pill { border: 1px solid var(--color-border); background: #fff; color: var(--color-text); border-radius: 999px; padding: 8px 14px; font: inherit; font-size: var(--text-sm); cursor: pointer; }
.doc-none__pill.is-on { background: var(--color-text); color: #fff; border-color: var(--color-text); }

.doc-info { display: inline-grid; place-items: center; width: 18px; height: 18px; border: none; background: none; color: var(--color-text-muted); padding: 0; margin-left: 4px; vertical-align: -3px; cursor: default; }
.doc-info svg { width: 16px; height: 16px; }
