/* components.css — buttons, cards, tables, forms, dialogs, toasts. */

/* ---------- Focus & a11y ---------- */
:focus-visible {
  outline: 2px solid var(--gold-1);
  outline-offset: 2px;
  border-radius: 4px;
}
:focus:not(:focus-visible) { outline: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap-min);
  padding: 0 0.95rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}

.btn:hover { background: var(--surface-2); border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--gold-grad);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-sm);
  letter-spacing: 0.01em;
}
.btn-primary:hover { filter: brightness(1.07); background: var(--gold-grad); border-color: transparent; }

/* Quiet secondary action — used where gold would dilute the primary. */
.btn-subtle {
  background: var(--surface-2);
  border-color: transparent;
  color: var(--text);
}
.btn-subtle:hover { background: var(--surface-3); border-color: transparent; }

.btn-danger {
  background: var(--due);
  border-color: transparent;
  color: #fff;
}
.btn-danger:hover { filter: brightness(1.08); background: var(--due); }

.btn-wa {
  background: #25d366;
  border-color: transparent;
  color: #06301a;
  font-weight: 600;
}
.btn-wa:hover { filter: brightness(1.05); background: #25d366; }

.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }

.btn-sm { min-height: 32px; padding: 0 0.6rem; font-size: var(--text-xs); }
.btn-icon { padding: 0; width: var(--tap-min); }

.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; filter: none; }

.btn svg { flex: none; }

/* Inline spinner for in-flight buttons */
.spinner {
  width: 13px; height: 13px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--sp-4); }

.card-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}

.card-head h2 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  line-height: var(--leading-tight);
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.card-head .search-wrap { margin-left: auto; }

.grid { display: grid; gap: var(--sp-4); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }

/* ---------- Search box ---------- */
.search-wrap { position: relative; display: flex; align-items: center; width: min(240px, 100%); }
.search-wrap .search-ico {
  position: absolute; left: 10px; color: var(--text-faint); pointer-events: none;
}
.search-wrap input {
  padding-left: 2rem;
  min-height: var(--tap-min);
}
.search-wrap input::-webkit-search-cancel-button { cursor: pointer; }

/* ---------- Stat tiles ---------- */
.stat { display: flex; flex-direction: column; gap: var(--sp-1); }
.stat .label {
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}
.stat .value {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  line-height: var(--leading-tight);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.stat .value.is-due { color: var(--due); }
.stat .value.is-paid { color: var(--paid); }
.stat .sub { font-size: var(--text-xs); color: var(--text-faint); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 calc(var(--sp-5) * -1) calc(var(--sp-5) * -1); padding: 0 var(--sp-5) var(--sp-5); }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }

th {
  text-align: left;
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

td {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr { transition: background var(--dur-fast) var(--ease); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn + .btn { margin-left: var(--sp-1); }

/* ---------- Tags ---------- */
.tag {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--surface-3);
  color: var(--text-muted);
  white-space: nowrap;
  text-transform: capitalize;
}
.tag-paid, .tag-done, .tag-confirmed, .tag-delivered, .tag-signed, .tag-won,
.tag-accepted { background: var(--paid-soft); color: var(--paid); }
.tag-unpaid, .tag-due, .tag-overdue, .tag-cancelled, .tag-lost,
.tag-declined { background: var(--due-soft); color: var(--due); }
.tag-partial, .tag-pending, .tag-open, .tag-draft, .tag-enquiry,
.tag-awaiting-selection, .tag-awaiting-approval { background: var(--warn-soft); color: var(--warn); }
.tag-in-progress, .tag-in-design, .tag-at-printer, .tag-sent,
.tag-quoted { background: var(--info-soft); color: var(--info); }
.tag-gold { background: var(--gold-soft); color: var(--gold-3); }

/* ---------- Alert rows ---------- */
.alert-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
}
.alert-row:last-child { border-bottom: 0; }
.alert-row .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-faint); }
.alert-row[data-type='shoot'] .dot { background: var(--gold-1); }
.alert-row[data-type='payment'] .dot { background: var(--due); }
.alert-row[data-type='album'] .dot { background: var(--info); }
.alert-row[data-type='lead'] .dot { background: var(--paid); }
.alert-row .alert-label { flex: 1; min-width: 0; }
.alert-row .cooldown { font-size: var(--text-xs); color: var(--text-faint); font-style: italic; }

/* ---------- Forms ---------- */
label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  margin-bottom: var(--sp-1);
  color: var(--text-muted);
}
label .req { color: var(--due); margin-left: 1px; }

input, select, textarea {
  width: 100%;
  min-height: var(--tap-min);
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-base);   /* >=16px avoids iOS zoom-on-focus at 15px+ */
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

input:hover, select:hover, textarea:hover { border-color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold-1);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

input::placeholder, textarea::placeholder { color: var(--text-faint); }
textarea { min-height: 84px; resize: vertical; line-height: var(--leading-normal); }

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236d6459' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  padding-right: 2rem;
  cursor: pointer;
}
[data-theme='dark'] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a89e8f' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

.field { margin-bottom: var(--sp-4); }
.field-hint { display: block; margin-top: var(--sp-1); font-size: var(--text-xs); color: var(--text-faint); }

.row { display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.row > * { flex: 1 1 190px; }

/* Only flag invalid fields the user has actually engaged with. */
input:user-invalid, select:user-invalid, textarea:user-invalid { border-color: var(--due); }
input:user-invalid:focus { box-shadow: 0 0 0 3px var(--due-soft); }

/* ---------- Skeletons ---------- */
.skeleton {
  display: block;
  height: 0.85em;
  width: 80%;
  border-radius: 4px;
  background: var(--skeleton);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
.skeleton-sm { width: 46px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-7);
  color: var(--text-muted);
  font-size: var(--text-sm);
}
.loading::before {
  content: '';
  width: 15px; height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--gold-1);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ---------- Empty states ---------- */
.empty-state { text-align: center; padding: var(--sp-7) var(--sp-4); color: var(--text-muted); }
.empty-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 62px; height: 62px; margin-bottom: var(--sp-4);
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-faint);
}
.empty-state h2 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--text);
  margin: 0 0 var(--sp-2);
  font-weight: 600;
}
.empty-state p { margin: 0 auto var(--sp-4); max-width: 42ch; font-size: var(--text-sm); line-height: var(--leading-normal); }
.empty-state code {
  background: var(--surface-3); padding: 0.15rem 0.4rem;
  border-radius: 4px; font-size: 0.95em;
}

/* ---------- Modal (record forms) ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(24, 22, 20, 0.5);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: var(--sp-5);
  overflow-y: auto;
  z-index: var(--z-modal);
  animation: fade var(--dur) var(--ease);
}
@keyframes fade { from { opacity: 0; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  margin: auto;
  animation: rise var(--dur) var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(0.99); } }

.modal-head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.modal-head h2 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  margin: 0; margin-right: auto; font-weight: 600;
}

.modal-body { padding: var(--sp-5); }

.modal-foot {
  display: flex; justify-content: flex-end; gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
  position: sticky; bottom: 0;
  background: var(--surface);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

@media (min-width: 640px) {
  .modal-body { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--sp-4); }
  .modal-body .field:has(textarea) { grid-column: 1 / -1; }
}

/* ---------- Confirm / alert dialogs ---------- */
.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(24, 22, 20, 0.58);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-5);
  z-index: var(--z-dialog);
  animation: fade var(--dur-fast) var(--ease);
}

.dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 400px;
  padding: var(--sp-5);
  text-align: center;
  animation: rise var(--dur) var(--ease);
}

.dialog-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; margin-bottom: var(--sp-3);
  border-radius: 50%;
}
.dialog-danger .dialog-icon { background: var(--due-soft); color: var(--due); }
.dialog-warning .dialog-icon { background: var(--warn-soft); color: var(--warn); }
.dialog-success .dialog-icon { background: var(--paid-soft); color: var(--paid); }
.dialog-info .dialog-icon { background: var(--info-soft); color: var(--info); }

.dialog-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  margin: 0 0 var(--sp-2);
  font-weight: 600;
}
.dialog-body p { margin: 0 0 var(--sp-2); font-size: var(--text-sm); color: var(--text-muted); line-height: var(--leading-normal); }
.dialog-detail { font-size: var(--text-xs) !important; color: var(--text-faint) !important; }

.dialog-actions {
  display: flex; gap: var(--sp-2); justify-content: center;
  margin-top: var(--sp-5);
}
.dialog-actions .btn { flex: 1; max-width: 170px; }

/* ---------- Toasts ---------- */
.toast-host {
  position: fixed;
  bottom: var(--sp-5); right: var(--sp-5);
  display: flex; flex-direction: column; gap: var(--sp-2);
  z-index: var(--z-toast);
  pointer-events: none;
}

.toast {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  background: var(--ink);
  color: #fff;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  line-height: 1.4;
  box-shadow: var(--shadow-lg);
  max-width: 340px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  border-left: 3px solid var(--gold-1);
}
.toast.is-in { opacity: 1; transform: translateY(0); }
.toast-icon { flex: none; margin-top: 1px; }
.toast-success { border-left-color: #7fc784; }
.toast-success .toast-icon { color: #7fc784; }
.toast-error { border-left-color: #e08a70; }
.toast-error .toast-icon { color: #e08a70; }
.toast-warn { border-left-color: #e0b467; }
.toast-warn .toast-icon { color: #e0b467; }
.toast-info .toast-icon { color: var(--gold-1); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .modal-backdrop { padding: 0; }
  .modal {
    max-width: none; min-height: 100%;
    border-radius: 0; border: 0;
    animation: slide-up var(--dur) var(--ease);
  }
  @keyframes slide-up { from { transform: translateY(16px); opacity: 0; } }

  .card { padding: var(--sp-4); border-radius: var(--radius); }
  .table-wrap { margin: 0 calc(var(--sp-4) * -1) calc(var(--sp-4) * -1); padding: 0 var(--sp-4) var(--sp-4); }

  .card-head { gap: var(--sp-2); }
  .card-head .search-wrap { order: 3; width: 100%; margin-left: 0; }
  .card-head [data-new] { margin-left: auto; }

  .toast-host { left: var(--sp-3); right: var(--sp-3); bottom: var(--sp-3); }
  .toast { max-width: none; }

  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .btn { max-width: none; width: 100%; }

  /* Full-width action buttons read better than cramped side-by-side ones. */
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
}

/* ---------- Settings page ---------- */
.section-note {
  margin: calc(var(--sp-2) * -1) 0 var(--sp-4);
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: var(--leading-normal);
  max-width: 62ch;
}
.section-note code {
  background: var(--surface-3);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.9em;
}

.check-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--text);
  font-weight: 450;
  cursor: pointer;
  min-height: var(--tap-min);
  margin-bottom: 0;
}
.check-row input[type='checkbox'] {
  width: 17px; height: 17px;
  min-height: 0;
  accent-color: var(--gold-2);
  cursor: pointer;
  flex: none;
}

.form-actions {
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
  margin-top: var(--sp-5);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
}

input[type='file'] {
  padding: 0.42rem 0.5rem;
  font-size: var(--text-sm);
  cursor: pointer;
}
input[type='file']::file-selector-button {
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 500;
  margin-right: var(--sp-3);
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
input[type='file']::file-selector-button:hover { background: var(--surface-3); }

@media (max-width: 640px) {
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }
}

/* ---------- Message preview ---------- */
.preview-backdrop {
  position: fixed; inset: 0;
  background: rgba(43, 39, 36, 0.55);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-5);
  z-index: var(--z-dialog);
  overflow-y: auto;
  animation: fade var(--dur-fast) var(--ease);
}

.preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 500px;
  padding: var(--sp-5);
  margin: auto;
  animation: rise var(--dur) var(--ease);
}

.preview-head { display: flex; align-items: flex-start; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.preview-head h2 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  margin: 0 0 2px;
  font-weight: 600;
}
.preview-head > div:first-child { flex: 1; min-width: 0; }
.preview-to { margin: 0; font-size: var(--text-sm); color: var(--text-muted); }
.preview-num {
  display: inline-block;
  margin-left: var(--sp-2);
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

.preview-note {
  border-radius: var(--radius-sm);
  padding: var(--sp-3);
  font-size: var(--text-sm);
  line-height: 1.5;
  margin-bottom: var(--sp-4);
}
.preview-note ul { margin: var(--sp-1) 0 0; padding-left: 1.1rem; }
.preview-note li { margin-bottom: 2px; }
.preview-note-warn { background: var(--warn-soft); color: var(--warn); }
.preview-note-error { background: var(--due-soft); color: var(--due); }

.preview-label {
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: var(--sp-2);
}

/* Reads like a chat bubble so the studio can see what the client will see. */
.preview-text {
  width: 100%;
  min-height: 150px;
  padding: var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: 1.55;
  resize: vertical;
  white-space: pre-wrap;
}

.preview-actions {
  display: flex; gap: var(--sp-2);
  justify-content: flex-end;
  margin-top: var(--sp-4);
}
.preview-actions [data-preview-copy] { margin-right: auto; }

/* ---------- Contact action row ---------- */
.contact-actions { display: inline-flex; gap: var(--sp-1); }
.contact-actions .btn { padding: 0 0.5rem; }

@media (max-width: 640px) {
  .preview-backdrop { padding: 0; }
  .preview { max-width: none; min-height: 100%; border-radius: 0; border: 0; }
  .preview-actions { flex-wrap: wrap; }
  .preview-actions [data-preview-copy] { margin-right: 0; }
  .preview-actions .btn { flex: 1 1 auto; }
  .preview-actions [data-preview-send] { flex-basis: 100%; order: -1; }
}

/* ---------- Searchable reference picker ---------- */
.ref-field { position: relative; }
.ref-control { position: relative; display: flex; align-items: center; }
.ref-search { padding-right: 2.2rem; }

.ref-clear {
  position: absolute;
  right: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
}
.ref-clear:hover { background: var(--border-strong); color: var(--text); }

.ref-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  margin: 0;
  padding: var(--sp-1);
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  max-height: 268px;
  overflow-y: auto;
  z-index: 30;
}
.ref-results[hidden] { display: none; }

.ref-results li {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  line-height: 1.35;
}
.ref-results li:hover,
.ref-results li.is-active { background: var(--surface-2); }

.ref-name { display: block; font-weight: 500; color: var(--text); }
/* Phone and ID on their own line so similar names are never confused. */
.ref-meta {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
}

.ref-empty { color: var(--text-muted); cursor: default !important; font-style: italic; }
.ref-empty:hover { background: transparent !important; }

.ref-more {
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-xs) !important;
  border-top: 1px solid var(--border);
  margin-top: var(--sp-1);
}

.ref-add {
  color: var(--gold-3);
  font-weight: 600;
  border-top: 1px solid var(--border);
  margin-top: var(--sp-1);
}
[data-theme='dark'] .ref-add { color: var(--gold-1); }

/* Two-column modal grids must let the dropdown escape its cell. */
.modal-body:has(.ref-results:not([hidden])) { overflow: visible; }

/* ---------- Quick-add client ---------- */
.quick-client { max-width: 400px; text-align: left; }
.quick-client .dialog-title { text-align: left; }
.quick-client .dialog-body { text-align: left; margin-bottom: var(--sp-4); }
.quick-client-form .field:last-of-type { margin-bottom: 0; }
.quick-client .dialog-actions { justify-content: flex-end; }
.quick-client .dialog-actions .btn { flex: 0 1 auto; }

/* ---------- Template editor ---------- */
.tpl-grid {
  display: grid;
  gap: var(--sp-4);
  /* min(300px, 100%) so a 320px screen gets one full-width column instead of
     forcing a 300px track plus padding and overflowing. */
  grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
}

.tpl-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  background: var(--surface);
}

.tpl-head { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.tpl-head h3 {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  margin: 0;
  margin-right: auto;
  color: var(--text);
}

.tpl-card textarea { font-size: var(--text-sm); min-height: 92px; }

.tpl-preview {
  margin-top: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border-left: 3px solid var(--gold-1);
}
.tpl-preview-label {
  display: block;
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 600;
  margin-bottom: var(--sp-1);
}
.tpl-preview p {
  margin: 0;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-muted);
  white-space: pre-wrap;
}
