/* Quantori Expenses — shared styles.
 * Palette and primitives lifted from webQCV/login.html. Tab/grid widgets
 * land here when we port them from webQCV/index.html. */

/* Theme palette lifted from sibling DubStudio (/Users/lalex/Projects/DubStudio/static/styles.css).
 * Same variable names + values so we can mirror look-and-feel between projects.
 * `--card` / `--border` are kept as aliases for `--panel` / `--line` so the
 * older Xero rules that still reference them don't have to be touched.
 */
:root,
[data-theme="light"] {
  --bg: #dce3ed;
  --panel: #ffffff;
  --panel-trans: rgba(255, 255, 255, 0.72);
  --head: #e8ecf2;
  --hover: rgba(99, 102, 241, 0.06);
  --selected: rgba(99, 102, 241, 0.15);
  --text: #0f172a;
  --heading: #334155;
  --muted: #475569;
  --muted-2: #64748b;
  --line: #a8b5c4;
  --line-soft: #d0d7e2;
  --primary: #08142d;
  --primary-hover: #0d1d40;
  --primary-fg: #ffffff;
  --soft: #e8ecf2;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --warning: #f59e0b;
  --success: #16a34a;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-btn: 0 10px 24px rgba(8, 20, 45, 0.18);

  /* Status badge colors — light theme */
  --status-draft-bg: #e2e8f0;       --status-draft-fg: #475569;
  --status-submitted-bg: #dbeafe;   --status-submitted-fg: #1d4ed8;
  --status-approved-bg: #fef3c7;    --status-approved-fg: #92400e;
  --status-paid-bg: #dcfce7;        --status-paid-fg: #166534;
  --status-rejected-bg: #fee2e2;    --status-rejected-fg: #991b1b;

  /* Back-compat aliases for older Xero rules that still use these names. */
  --card: var(--panel);
  --border: var(--line);
  --header-bg: var(--primary);
  --header-fg: var(--primary-fg);
}

[data-theme="dark"] {
  --bg: #0b1220;
  --panel: #131e30;
  --panel-trans: rgba(19, 30, 48, 0.72);
  --head: #1a2638;
  --hover: rgba(148, 163, 255, 0.08);
  --selected: rgba(148, 163, 255, 0.16);
  --text: #e4ecf7;
  --heading: #cbd5e1;
  --muted: #94a3b8;
  --muted-2: #7c8aa0;
  --line: #2c3a52;
  --line-soft: #22304a;
  --primary: #dbe6f5;
  --primary-hover: #f2f6fc;
  --primary-fg: #08142d;
  --soft: #1b2638;
  --danger: #f87171;
  --danger-soft: #3a1c1c;
  --warning: #fbbf24;
  --success: #4ade80;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-btn: 0 10px 24px rgba(0, 0, 0, 0.35);

  /* Status badge colors — dark theme (lower saturation backgrounds, lighter text) */
  --status-draft-bg: #1f2a3e;       --status-draft-fg: #94a3b8;
  --status-submitted-bg: #1e3a5f;   --status-submitted-fg: #93c5fd;
  --status-approved-bg: #3a2e1a;    --status-approved-fg: #fcd34d;
  --status-paid-bg: #1f3a2a;        --status-paid-fg: #86efac;
  --status-rejected-bg: #3a1f1f;    --status-rejected-fg: #fca5a5;

  --card: var(--panel);
  --border: var(--line);
  --header-bg: #0a1020;
  --header-fg: var(--text);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}

/* ── Top header (slim, webQCV-style: 22px logo + name + ver + slim controls) ── */
:root { --app-max-width: 1100px; }

.app-header {
  background: var(--bg);  /* opaque so scrolled content doesn't bleed through */
  color: var(--text);
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header-inner {
  max-width: var(--app-max-width);
  margin: 0 auto;
  padding: 6px 16px;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-header .brand-logo {
  width: 22px; height: 22px;
  object-fit: contain;
  display: block;
  flex: 0 0 auto;
}
.app-header .brand {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.app-header .brand-ver {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  margin-left: 6px;
}
.app-header .spacer { flex: 1; }
.app-header .user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.app-header .user button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.app-header .user button:hover { background: var(--soft); color: var(--text); border-color: var(--primary); }
.app-header .theme-toggle {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  width: 22px; height: 22px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}
.app-header .theme-toggle:hover { background: var(--soft); color: var(--text); }

/* ── Tab bar (DubStudio-style: compact pills, sticky under app-header) ── */
.tab-bar {
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  max-width: var(--app-max-width);
  margin: 0 auto;
  padding: 6px 16px 0;
  display: flex;
  gap: 12px;
  align-items: flex-end;
  position: sticky;
  top: 36px;  /* matches .app-header-inner height */
  z-index: 9;
}
.tab-bar-tabs {
  display: flex;
  gap: 2px;
}
.tab-bar-extras {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 4px;
}
.tab-extras { display: flex; align-items: center; gap: 10px; }
.tab-extras[hidden] { display: none; }
.tab-stat {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.tab-stat b {
  color: var(--text);
  font-weight: 700;
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}
/* Scope tab-button styling to the .tab-bar-tabs row so .btn buttons inside
 * .tab-extras keep their primary-button look. */
.tab-bar-tabs button {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--muted-2);
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  border-radius: 6px 6px 0 0;
  position: relative;
  top: 1px;
}
.tab-bar-tabs button:hover:not(.active) { color: var(--heading); background: var(--hover); }
.tab-bar-tabs button.active {
  color: var(--primary);
  background: var(--panel);
  border-color: var(--line);
}
.tab-bar-tabs button[hidden] { display: none; }
/* Buttons inside extras inherit the .btn rules; keep them small to match
 * the tab-bar density. */
.tab-extras .btn { padding: 5px 12px; font-size: 12px; }

/* The HTML `hidden` attribute is supposed to hide elements unconditionally,
 * but our `.dropzone` and `.receipt-preview` set `display: flex` which wins
 * over the UA stylesheet. Make `hidden` authoritative across the editor. */
[hidden] { display: none !important; }

/* ── Content area (fixed width like webQCV — body scrolls horizontally on
 *    narrow viewports instead of squishing the grids inside) ── */
.tab-content {
  padding: 16px;
  /* Fixed width (not max-width) so the card can be dragged wider or narrower
     than the default via the edge handles (webQCV-style). max-width clamps it
     to just under the viewport so the drag handles always stay reachable. */
  width: var(--app-max-width);
  max-width: calc(100vw - 24px);
  min-width: min(500px, calc(100vw - 24px));
  margin: 0 auto;
  position: relative;
  box-sizing: border-box;
}

/* Edge drag-handles for resizing the content card (ported from webQCV). */
.page-resize-handle, .page-resize-handle-l {
  position: absolute; top: 0; bottom: 0; width: 12px;
  cursor: col-resize; z-index: 10;
}
.page-resize-handle { right: -6px; }
.page-resize-handle-l { left: -6px; }
.page-resize-handle:hover, .page-resize-handle.active,
.page-resize-handle-l:hover, .page-resize-handle-l.active {
  background: rgba(99, 102, 241, .12); border-radius: 4px;
}
.tab-content > section { display: none; }
.tab-content > section.active { display: block; }

/* .page-header is only used inside Admin sub-panes now (the top-level
 * tab headings moved to the sticky tab-bar). */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.page-header h1, .page-header h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--heading);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  background: var(--primary);
  color: var(--primary-fg);
  border: 1px solid var(--primary);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
}
.btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--primary-fg); }
.btn.secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.secondary:hover { background: var(--soft); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Status badges ── */
.status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.status.draft     { background: var(--status-draft-bg);     color: var(--status-draft-fg); }
.status.submitted { background: var(--status-submitted-bg); color: var(--status-submitted-fg); }
.status.approved  { background: var(--status-approved-bg);  color: var(--status-approved-fg); }
.status.paid      { background: var(--status-paid-bg);      color: var(--status-paid-fg); }
.status.rejected  { background: var(--status-rejected-bg);  color: var(--status-rejected-fg); }

/* .summary cards moved into the sticky tab-bar (see .tab-stat). */

/* ── Empty state ── */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty h2 { font-size: 16px; font-weight: 500; margin-bottom: 8px; color: var(--text); }

/* ── Section heading (status group) ── */
.group-heading {
  font-size: 12px;
  font-weight: 700;
  color: var(--heading);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 18px 0 6px;
  padding: 0 4px;
}
.group-heading .count { color: var(--muted); font-weight: 400; margin-left: 4px; }

/* ── Claim rows (Xero-style: icon, title, meta line, [add-btn], status,
 *    attach, amount, [×]). The two trailing "auto" slots hold inline
 *    "+ Add expense" and "×" delete for drafts owned by the current user;
 *    empty placeholders keep the grid aligned on other rows. ── */
.claim-row {
  display: grid;
  /* body(flex) + however-many right-side controls. Only the leading body
     track is explicit; the right-side cells flow into implicit columns
     (one per actual cell) via grid-auto-flow. A fixed repeat(N) here would
     leave trailing empty columns whose gutters add phantom whitespace on
     the right edge. (The leading icon column was removed.) */
  grid-template-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: auto;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom: none;
  cursor: pointer;
  font-size: 13px;
}
.claim-row:first-child { border-radius: 8px 8px 0 0; }
.claim-row:last-child  { border-radius: 0 0 8px 8px; border-bottom: 1px solid var(--border); }
.claim-row:only-child  { border-radius: 8px; border-bottom: 1px solid var(--border); }
.claim-row:hover { background: var(--soft); }
.claim-row + .claim-row { border-top: 1px solid var(--border); }

.claim-row .icon {
  width: 22px; height: 22px;
  background: var(--soft);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  font-size: 13px;
}
.claim-row .body { min-width: 0; }
.claim-row .title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--text);
}
.claim-row .desc { color: var(--muted); font-weight: 400; margin-left: 6px; }
.claim-row .meta {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.claim-row .meta b { color: var(--text); font-weight: 500; }
.claim-row .attach { color: var(--muted); font-size: 13px; }
.claim-row .amount { font-weight: 700; min-width: 80px; text-align: right; font-size: 13px; }
.claim-row .amount .ccy { color: var(--muted); font-weight: 400; font-size: 10px; margin-left: 3px; }
.claim-row .kebab {
  background: transparent; border: none; cursor: pointer;
  color: var(--muted); padding: 4px 8px; border-radius: 4px;
}
.claim-row .kebab:hover { background: var(--border); color: var(--text); }
.claim-row .add-to-claim {
  padding: 5px 11px;
  font-size: 12px;
}
.claim-row .add-to-claim-slot {
  /* Empty placeholder keeps the grid columns aligned across rows with and
   * without the add-expense button. */
  display: inline-block; width: 0;
}
.claim-row-delete {
  background: transparent; border: none; cursor: pointer;
  color: var(--muted); font-size: 18px; line-height: 1;
  width: 24px; height: 24px; border-radius: 4px;
}
.claim-row-delete:hover { background: var(--danger-soft); color: var(--danger); }
.claim-row-delete-slot { display: inline-block; width: 0; }

/* ── Claim editor (slide-over over the whole page, Xero-style) ── */
.editor-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: none;
  z-index: 50;
}
.editor-backdrop.open { display: block; }
.editor {
  position: fixed; inset: 0;
  background: var(--card);
  display: none;
  flex-direction: column;
  z-index: 51;
}
.editor.open { display: flex; }
.editor-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}
.editor-header .close {
  background: transparent; border: none; cursor: pointer;
  font-size: 22px; color: var(--muted); line-height: 1;
  width: 32px; height: 32px; border-radius: 4px;
}
.editor-header .close:hover { background: var(--bg); color: var(--text); }
.editor-header h2 {
  font-size: 17px; font-weight: 600; flex: 1;
}
.editor-header .status { margin-right: 8px; }
.editor-body {
  display: grid;
  grid-template-columns: 1fr 480px;
  flex: 1;
  overflow: hidden;
}
.editor-body > .left, .editor-body > .right { overflow: auto; padding: 32px; }
.editor-body > .left {
  background: var(--soft);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Drop zone — patterned background like Xero's */
.dropzone {
  width: 100%;
  max-width: 520px;
  height: 100%;
  min-height: 400px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background:
    repeating-linear-gradient(45deg, transparent 0 14px, rgba(148, 163, 184, 0.08) 14px 28px),
    var(--card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.dropzone.dragover {
  border-color: var(--primary);
  background-color: var(--hover);
}
.dropzone .icon {
  font-size: 48px;
  margin-bottom: 16px;
  color: var(--muted-2);
}
.dropzone .title { font-weight: 600; color: var(--text); margin-bottom: 6px; }
.dropzone .hint { font-size: 13px; }
.dropzone .btn { margin-top: 16px; }
.dropzone input[type="file"] { display: none; }

.ocr-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  cursor: pointer;
  user-select: none;
}
.ocr-toggle input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--primary);
}

.receipt-preview {
  position: relative;
  max-width: 520px;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.receipt-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}
.receipt-preview .actions {
  display: flex; gap: 8px; margin-top: 12px;
}
.receipt-preview .filename {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
  word-break: break-all;
}

/* Form fields */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-weight: 600;
  font-size: 12px;
  color: var(--heading);
  margin-bottom: 4px;
}
.field label .opt { color: var(--muted); font-weight: 400; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  background: var(--panel);
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.field input:disabled, .field select:disabled, .field textarea:disabled {
  background: var(--bg);
  color: var(--muted);
  cursor: not-allowed;
}
.field textarea { resize: vertical; min-height: 70px; }
.field .row { display: grid; grid-template-columns: 120px 1fr; gap: 8px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.char-counter { float: right; color: var(--muted); font-size: 12px; font-weight: 400; }

.editor-footer {
  border-top: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.editor-footer .left-slot { margin-right: auto; }

/* Stack to single column on narrow viewports */
@media (max-width: 900px) {
  .editor-body { grid-template-columns: 1fr; }
  .editor-body > .left { min-height: 240px; padding: 16px; }
  .editor-body > .right { padding: 20px; }
}

/* ── Multi-line editor: single scrollable column. The old two-column
 *    grid (left=receipt, right=form) stays defined above for back-compat
 *    with any read-only-only views, but the multi-line editor uses
 *    .editor-body-stack as an override. ── */
.editor-body.editor-body-stack {
  display: block;
  overflow: hidden;
}
.editor-scroll {
  height: 100%;
  overflow: auto;
  /* Default content column ≈ 960px (was hard-cap); widen if a wide line
   * group card needs the room. The line card itself sets its own min-width
   * so cells can auto-size to their content. */
  padding: 28px max(24px, calc(50% - 640px));
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.trip-header { display: flex; flex-direction: column; gap: 0; }
.trip-header .field { margin-bottom: 14px; }
.trip-header textarea { min-height: 56px; }

.lines-section { display: flex; flex-direction: column; gap: 10px; }
.lines-header {
  display: flex; justify-content: space-between; align-items: baseline;
}
.lines-header h3 { font-size: 14px; font-weight: 600; }
.lines-total { color: var(--muted); font-size: 13px; }
.lines-total b { color: var(--text); font-weight: 600; }
#addLineBtn { align-self: flex-start; }

.line-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  overflow: hidden;
}
.line-card + .line-card { margin-top: 10px; }
.line-card-summary {
  display: grid;
  grid-template-columns: 1fr auto 24px 24px;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
}
.line-summary-remove {
  background: transparent; border: none; cursor: pointer;
  color: var(--muted); font-size: 18px; line-height: 1;
  width: 24px; height: 24px; border-radius: 4px;
}
.line-summary-remove:hover { background: var(--danger-soft); color: var(--danger); }
.line-card.expanded .line-card-summary { border-bottom: 1px solid var(--border); }
.line-card-summary:hover { background: var(--soft); }

.line-summary-body { min-width: 0; }
.line-summary-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.line-summary-meta {
  font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
.line-summary-amount {
  font-weight: 600;
  font-size: 14px;
  text-align: right;
  white-space: nowrap;
}
.line-summary-amount .ccy {
  color: var(--muted); font-weight: 400; font-size: 11px; margin-left: 3px;
}

.line-toggle {
  background: transparent; border: none; cursor: pointer;
  color: var(--muted); font-size: 14px;
  width: 24px; height: 24px; border-radius: 4px;
  transition: transform 0.15s, color 0.15s;
}
.line-toggle:hover { color: var(--text); }
.line-card.expanded .line-toggle { transform: rotate(180deg); }

.line-card-body {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 18px;
  padding: 16px 14px;
  background: var(--soft);
}
@media (max-width: 720px) {
  .line-card-body { grid-template-columns: 1fr; }
}

.line-receipt { display: flex; flex-direction: column; }
.line-dropzone {
  min-height: 180px;
  padding: 16px;
  width: 100%;
}
.line-dropzone .title { font-weight: 500; color: var(--text); margin-bottom: 6px; font-size: 13px; }
.line-dropzone .hint { font-size: 12px; line-height: 1.5; }
.line-dropzone input[type="file"] { display: none; }

.line-receipt-preview {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  padding: 12px;
  display: flex; flex-direction: column; align-items: center;
  min-height: 180px;
}
.line-receipt-preview .filename {
  font-size: 11px; color: var(--muted); margin-bottom: 8px; word-break: break-all;
}
.line-receipt-preview img {
  max-width: 100%; max-height: 220px; object-fit: contain; border-radius: 4px;
}
.line-receipt-pdf {
  width: 100%; height: 280px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--soft);
  /* The OS PDF plugin inside <embed> swallows mouse events, so our
   * click-to-enlarge handler never fires on the embed itself. Let the
   * click pass through to the surrounding preview wrapper, which carries
   * the lightbox handler. */
  pointer-events: none;
}
.line-receipt-fallback {
  padding: 40px 16px; text-align: center; color: var(--muted);
  font-size: 13px;
}
.line-receipt-preview .actions { display: flex; gap: 6px; margin-top: 10px; }
.line-receipt-preview .actions .btn { padding: 4px 10px; font-size: 12px; }

.lines-readonly-hint {
  padding: 10px 14px;
  background: var(--soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  box-sizing: border-box;
}
/* When the notice lives inside a card body (either single or group),
 * span both grid columns so it stretches edge-to-edge. */
.line-card-body .lines-readonly-hint.card-inline {
  grid-column: 1 / -1;
  margin-top: 4px;
}
.line-status-banner {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 12px;
  line-height: 1.4;
}
.line-status-banner.warn {
  background: var(--status-approved-bg); border: 1px solid var(--warning);
  color: var(--status-approved-fg);
}
.line-status-banner.info {
  background: var(--status-submitted-bg); border: 1px solid var(--primary);
  color: var(--status-submitted-fg);
}

/* ── Busy overlay (full-screen blocker shown during OCR / upload) ── */
.busy-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.busy-overlay[hidden] { display: none; }
.busy-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 40px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  box-shadow: var(--shadow);
  min-width: 240px;
}
.busy-label {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.busy-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--line-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: busy-spin 0.8s linear infinite;
}
@keyframes busy-spin { to { transform: rotate(360deg); } }

/* ── Receipt lightbox (floating panel; NOT fullscreen) ── */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.lightbox[hidden] { display: none; }
.lightbox-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  width: min(820px, 92vw);
  /* Fixed vertical size — `max-height` alone let the panel shrink to
   * iframe content height for tall portrait PDFs. */
  height: 86vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.lightbox-toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.lightbox-filename {
  flex: 1; min-width: 0;
  font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lightbox-body {
  flex: 1; min-height: 0;
  /* Column direction so flex items (img / pdf-wrap) stretch to the full
   * width by default. Row direction caused images to render at their
   * intrinsic size instead of fit-to-width — only the PDF wrap was
   * filling because it explicitly took `flex: 1`. */
  display: flex; flex-direction: column;
  padding: 12px;
  background: var(--card);
  overflow: auto;
}
.lightbox-img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: 4px;
  cursor: zoom-in;
}
.lightbox-img.zoomed {
  /* Click toggles to natural size for portrait scans where fit-to-width
   * isn't readable. align-self breaks the column stretch. */
  width: auto;
  max-width: none; max-height: none;
  align-self: flex-start;
  cursor: zoom-out;
}
.lightbox-pdf-wrap {
  flex: 1; min-width: 0; min-height: 0;
  background: var(--panel);
  border-radius: 4px;
  overflow: hidden;
}
.lightbox-pdf {
  width: 100%; height: 100%;
  border: none;
  background: var(--panel);
}
.lightbox-open-new {
  color: var(--primary);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}
.lightbox-open-new:hover { background: var(--soft); }
.lightbox-close {
  background: transparent; border: 1px solid var(--line);
  color: var(--muted); font-size: 20px; line-height: 1;
  width: 28px; height: 28px; border-radius: 6px;
  cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.lightbox-close:hover { background: var(--soft); color: var(--text); border-color: var(--primary); }

/* Make receipt previews feel clickable. */
.line-receipt-preview,
.line-receipt-preview img,
.line-receipt-pdf {
  cursor: zoom-in;
}

/* ── Multi-row line group card (used when 2+ lines share one receipt) ── */
.line-group-card {
  /* Shrink the card to fit the preview + table content (instead of
   * stretching to the lines-section's full width). max-width keeps it
   * from blowing past the editor area on absurdly long descriptions. */
  width: max-content;
  max-width: 100%;
  align-self: flex-start;
}
.line-group-card .line-card-body {
  /* `auto` (not `1fr`) on the table column so the card grows with the
   * widest row instead of clipping. Outer .editor-scroll handles overflow
   * if the whole card ends up wider than the viewport. */
  grid-template-columns: 260px auto;
}
.line-group-table-wrap {
  overflow-x: auto;
}
.line-group-table {
  /* `width: auto` lets the table size to its (auto-fit) cells; combined
   * with the line-card-body's auto column this lets the card widen as
   * needed. */
  width: auto;
  border-collapse: collapse;
  font-size: 13px;
}
.line-group-table th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
}
.line-group-table td {
  padding: 4px 4px;
  vertical-align: middle;
  border-bottom: 1px solid var(--line-soft);
}
.line-group-table tr:last-child td { border-bottom: none; }
.line-group-table input,
.line-group-table select {
  /* Auto-size to content (Chrome/Edge ≥123). Without explicit width the
   * input falls back to the browser's default text width in older engines. */
  field-sizing: content;
  width: auto;
  padding: 3px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: var(--card);
  min-width: 0;
  max-width: 280px;
}
.line-group-table input:focus, .line-group-table select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.1);
}
.line-group-table .col-amount input { text-align: right; }
.line-group-table .col-remove       { width: 28px; text-align: center; }
/* Per-column floors — set just where the browser's own intrinsic min is
 * unfriendly (date picker chrome, very short amounts/currencies). */
.line-group-table .col-date input        { min-width: 108px; }
.line-group-table .col-amount input      { min-width: 60px; }
.line-group-table .col-currency select   { min-width: 56px; }
.line-group-table .col-description input { max-width: 320px; }
.line-group-table .col-remove .line-summary-remove { margin: 0 auto; }
@media (max-width: 720px) {
  .line-group-card .line-card-body { grid-template-columns: 1fr; }
}

.line-fields .field { margin-bottom: 12px; }
.line-fields .field-row { margin-bottom: 12px; }
.line-fields .field-row .field { margin-bottom: 0; }
.line-actions { display: flex; justify-content: flex-end; margin-top: 4px; }
.btn.danger-text {
  color: var(--danger);
  border-color: var(--danger);
}
.btn.danger-text:hover { background: var(--danger-soft); }

/* History / read-only block on submitted+ claims */
.history-block {
  background: var(--soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.history-block h3 { font-size: 13px; margin-bottom: 8px; font-weight: 600; }
.history-block ol { list-style: none; padding: 0; font-size: 13px; }
.history-block li { padding: 4px 0; color: var(--muted); }
.history-block li b { color: var(--text); font-weight: 500; }
.history-block li .at { font-size: 11px; }

/* ── Finance queue row: like .claim-row but with action buttons in the last
 *    slot (Approve / Reject / Mark paid) instead of the kebab. ── */
.claim-row .actions {
  display: flex;
  gap: 6px;
}
.claim-row .actions .btn {
  padding: 5px 11px;
  font-size: 12px;
}
.claim-row .actions .btn.danger {
  background: var(--card);
  color: var(--danger);
  border: 1px solid var(--danger);
}
.claim-row .actions .btn.danger:hover { background: var(--danger-soft); }
.claim-row .actions .btn.success {
  background: var(--success);
}
.claim-row .actions .btn.success:hover { background: #15803d; }
/* Finance rows reuse the same flexible grid as base .claim-row — the
   override that pinned this to 6 columns broke once admin-only Delete
   was added (7th cell would wrap). Generous repeat(auto) handles any
   combination of optional buttons. */
#financeList .claim-row { grid-template-columns: minmax(0, 1fr); }

/* Row-level Reject sitting directly in the grid (not wrapped in .actions
   like Finance rows). Match the compact size + outlined-danger look so it
   doesn't get clipped or compete visually with the × delete next to it. */
.claim-row .row-reject {
  padding: 5px 11px;
  font-size: 12px;
  background: var(--card);
  color: var(--danger);
  border: 1px solid var(--danger);
  white-space: nowrap;
}
.claim-row .row-reject:hover { background: var(--danger-soft); }

/* ── Admin → API keys: integration tiles with a "configured" badge ── */
.admin-keys-hint {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 14px;
}
.admin-keys-hint code {
  background: var(--soft);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}
.admin-keys-form { display: flex; flex-direction: column; gap: 12px; }
.admin-key-tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}
.admin-key-tile header { margin-bottom: 10px; }
.admin-key-tile h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--heading);
  display: flex;
  align-items: center;
  gap: 10px;
}
.admin-key-tile .hint {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
}
.admin-key-tile .badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--status-draft-bg);
  color: var(--status-draft-fg);
}
.admin-key-tile .badge.ok {
  background: var(--status-paid-bg);
  color: var(--status-paid-fg);
}
.admin-key-tile .key-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 6px 12px;
  align-items: center;
}
.admin-key-tile .key-grid label {
  font-weight: 600;
  font-size: 12px;
  color: var(--heading);
  margin: 0;
}
.admin-key-tile .key-grid input {
  width: 100%;
  padding: 5px 9px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.admin-key-tile .key-grid input:focus {
  outline: none;
  border-color: var(--primary);
}
.admin-keys-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}
#adminKeysSavedMsg { font-size: 12px; }

/* ── Admin sub-tab bar (Users / API keys) — same pill style as main tabs ── */
.sub-tab-bar {
  display: flex;
  gap: 2px;
  padding: 0 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.sub-tab-bar button {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--muted-2);
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  border-radius: 6px 6px 0 0;
  position: relative;
  top: 1px;
}
.sub-tab-bar button:hover:not(.active) { color: var(--heading); background: var(--hover); }
.sub-tab-bar button.active {
  color: var(--primary);
  background: var(--panel);
  border-color: var(--line);
}
.admin-subpane { display: none; }
.admin-subpane.active { display: block; }

/* ── Generic table (Users etc.) ── */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 13px;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table th {
  background: var(--soft);
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.data-table tbody tr:hover { background: var(--soft); }
.data-table .role-tag {
  display: inline-block;
  background: var(--status-submitted-bg);
  color: var(--status-submitted-fg);
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 10px;
  margin-right: 4px;
}
.data-table .role-tag.admin { background: var(--status-rejected-bg); color: var(--status-rejected-fg); }
.data-table .role-tag.finance { background: var(--status-submitted-bg); color: var(--status-submitted-fg); }
.data-table .role-select {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.data-table .role-select:hover { border-color: var(--primary); }
.data-table .active-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}
.data-table .active-toggle input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--primary);
}
.data-table .inactive { color: var(--muted); font-style: italic; }
.data-table .row-actions { white-space: nowrap; text-align: right; }
.data-table .row-actions button {
  background: transparent;
  border: 1px solid var(--line);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  margin-left: 4px;
  font-family: inherit;
}
.data-table .row-actions button:hover { background: var(--bg); }
.data-table .row-actions button.danger { color: var(--danger); border-color: var(--danger); }
.data-table .row-actions button.danger:hover { background: var(--danger-soft); }

/* ── Health-insurance editor ──
   Tuned dense: this form is mostly small inputs (dates, money, codes), so
   we shrink section padding, row gaps, and label margins aggressively so
   the whole 16-field card fits without scrolling on a 13" laptop. */
.ins-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
.ins-section + .ins-section { margin-top: 6px; }
.ins-section h3 {
  font-size: 11px;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.ins-readonly {
  display: flex; gap: 20px;
  font-size: 12px; color: var(--text);
}
.ins-readonly b {
  display: block;
  font-size: 10px; font-weight: 600;
  color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.04em; margin-bottom: 1px;
}
.ins-row3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px 8px;
}
.ins-row3 .field label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 1px; font-weight: 600; }
.ins-row3 .field input, .ins-row3 .field select {
  width: 100%; padding: 3px 6px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--card); color: var(--text);
  font-size: 12px; font-family: inherit;
}
.ins-checkbox {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 4px; font-size: 12px; color: var(--text);
  cursor: pointer;
}
.ins-checkbox input { accent-color: var(--primary); cursor: pointer; }
.ins-files {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.ins-file-slot {
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 6px;
  background: var(--bg);
}
.ins-file-title {
  font-size: 11px; font-weight: 700; color: var(--text);
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.ins-dropzone { min-height: 90px; padding: 10px; }
.ins-dropzone .title { font-size: 13px; }
.ins-dropzone .hint { font-size: 11px; }
.ins-preview { background: var(--card); }
.ins-computed-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px 12px;
  font-size: 12px; color: var(--text);
}
.ins-computed-grid b {
  display: block;
  font-size: 10px; font-weight: 600;
  color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.04em; margin-bottom: 1px;
}
.ins-hint { margin-top: 4px; font-size: 11px; color: var(--muted); }
/* Tighter top/bottom padding for the insurance editor only — the form is
   field-dense and benefits from less wasted whitespace. The horizontal
   centering math (`max(24px, calc(50% - 640px))`) is kept. */
#insuranceEditor .editor-scroll { padding-top: 12px; padding-bottom: 12px; }

.ins-list-section { margin-top: 24px; }
.claims-group-header {
  font-size: 12px; font-weight: 700;
  color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.05em; margin-bottom: 8px;
}

@media (max-width: 720px) {
  .ins-row3, .ins-computed-grid, .ins-files { grid-template-columns: 1fr; }
}

/* Travel-Project category requires a non-empty project — pre-submit warning
   shown inline on the input. Server rejects empty project too, but this
   surfaces it without a round-trip. */
input.project-required-empty {
  border-color: var(--danger, #d63a3a) !important;
  background-color: color-mix(in srgb, var(--danger, #d63a3a) 6%, transparent);
}
input.project-required-empty::placeholder { color: var(--danger, #d63a3a); }

/* ── DGrid (Finance grid) — ported from webQCV, themed to Q-Exp vars.
   Most of the grid is inline-styled in dgrid.js; these are the few classes it
   relies on from the stylesheet. NOTE: the grid's cell/header colors are
   hardcoded light in dgrid.js, so it renders light-themed even in dark mode. */
.batch-btn {
  padding: 3px 8px; min-width: auto; border: 1px solid var(--border, #a8b5c4);
  border-radius: 6px; background: var(--card, #fff); color: var(--text, #1e293b);
  font-size: 11px; font-weight: 600; cursor: pointer; transition: all .15s;
}
.batch-btn:hover:not(:disabled) { background: var(--soft); border-color: var(--primary); color: var(--primary); }
.batch-btn:disabled { opacity: .4; cursor: default; }
.batch-btn.danger { color: #dc2626; }
.batch-btn.danger:hover:not(:disabled) { background: #fef2f2; border-color: #dc2626; }

.col-resize { position: absolute; right: 0; top: 0; bottom: 0; width: 5px; cursor: col-resize; z-index: 2; }
.col-resize:hover, .col-resize.active { background: rgba(99, 102, 241, .25); }

.draggable-th { cursor: grab; }
.draggable-th.dragging { opacity: .4; }
.draggable-th.drag-over { border-left: 2px solid var(--primary); }

.cols-menu {
  position: fixed; background: var(--card, #fff); border: 1px solid var(--border, #a8b5c4);
  border-radius: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, .1); padding: 3px 0;
  z-index: 1000; min-width: 140px; max-height: calc(100vh - 40px); overflow-y: auto;
}
.cols-menu.hidden { display: none; }
.cols-menu label {
  display: flex; align-items: center; gap: 6px; padding: 1px 12px; font-size: 12px;
  line-height: 1.3; font-weight: 500; color: var(--text, #334155); cursor: pointer; white-space: nowrap;
}
.cols-menu label input[type=checkbox] { margin: 0; width: 13px; height: 13px; }
.cols-menu label:hover { background: var(--soft); }

