/* ============================================================
   COMPONENTS.CSS — buttons, cards, badges, modals, tables,
                    toasts, forms, empty states
   ============================================================ */

/* ---- Buttons -------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius);
  transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
  white-space: nowrap;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-icon { padding: 8px; }

.btn-primary {
  background: var(--primary);
  color: var(--text-inv);
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-secondary {
  background: var(--card);
  color: var(--text-1);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg); }

.btn-danger {
  background: var(--danger);
  color: var(--text-inv);
  border-color: var(--danger);
}
.btn-danger:hover { background: #dc2626; border-color: #dc2626; }

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

.btn-warning {
  background: var(--warning);
  color: var(--text-inv);
  border-color: var(--warning);
}
.btn-warning:hover { background: #d97706; }

/* ---- Cards ---------------------------------------------- */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
}
.card-body { padding: 20px; }

/* ---- Badges --------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 999px;
  line-height: 1.6;
}
.badge-success  { background: var(--success-bg);  color: #065F46; }
.badge-warning  { background: var(--warning-bg);  color: #92400E; }
.badge-danger   { background: var(--danger-bg);   color: #991B1B; }
.badge-info     { background: var(--info-bg);     color: #1E40AF; }
.badge-neutral  { background: var(--neutral-bg);  color: var(--neutral); }
.badge-primary  { background: #DBEAFE;            color: #1D4ED8; }

/* ---- Tables --------------------------------------------- */
.table-wrapper {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .5px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAFAFA; }
.td-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---- Forms ---------------------------------------------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 16px;
}
.form-group:last-child { margin-bottom: 0; }
.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
}
.form-label.required::after {
  content: ' *';
  color: var(--danger);
}
.form-control {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--text-1);
  background: var(--card);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(17,68,134,.12);
}
.form-control:disabled {
  background: var(--bg);
  color: var(--text-2);
  cursor: not-allowed;
}
.form-control.error { border-color: var(--danger); }

/* A field that is fixed because the record it belongs to has left the building.
   readOnly rather than disabled where the value should stay readable and
   selectable - a sent proposal's amount is the thing the reader came for. */
.is-locked {
  background: var(--bg);
  color: var(--text-2);
  cursor: not-allowed;
}
/* A sentence explaining why a form is doing what it is doing, above the fields
   it explains. */
.form-note {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-2);
  background: var(--bg);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius);
  padding: 9px 11px;
  margin: 0 0 14px;
}
.form-hint {
  font-size: 12px;
  color: var(--text-2);
}
.form-error {
  font-size: 12px;
  color: var(--danger);
}
.form-row {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr 1fr;
}
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ---- Modals --------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-lg { max-width: 720px; }
.modal-header {
  display: flex;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}
.modal-close {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 20px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  line-height: 1;
}
.modal-close:hover { background: var(--bg); color: var(--text-1); }
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
}

/* ---- Toasts --------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 13.5px;
  line-height: 1.4;
  animation: toast-in 200ms ease;
}
.toast.removing { animation: toast-out 200ms ease forwards; }
.toast-success { background: #022c22; color: #6EE7B7; }
.toast-error   { background: #450a0a; color: #FCA5A5; }
.toast-warning { background: #431407; color: #FCD34D; }
.toast-info    { background: #172554; color: #93C5FD; }
.toast-icon { flex-shrink: 0; margin-top: 1px; }
@keyframes toast-in  { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toast-out { from { transform: translateX(0); opacity: 1; } to { transform: translateX(110%); opacity: 0; } }

/* ---- Page header ---------------------------------------- */
.page-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}
.page-header h2 {
  font-size: 20px;
  font-weight: 700;
  flex: 1;
}
.page-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---- Empty state ---------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 52px 20px;
  color: var(--text-2);
  text-align: center;
  gap: 10px;
}
.empty-state-icon {
  font-size: 36px;
  opacity: .5;
  margin-bottom: 4px;
}
.empty-state h3 { font-size: 15px; color: var(--text-1); }
.empty-state p  { font-size: 13px; max-width: 320px; }

/* Was two inline styles in leads.js and proposals.js, which had the same
   filter bar as everyone else and sized it differently. */
.filter-compact {
  max-width: 200px;
  font-size: 13px;
}

/* ---- Cross-module link ----------------------------------
   The control that carries you to a record on another screen. Styled as a
   link rather than a button because it navigates and changes nothing. */
.cross-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.cross-link:hover { text-decoration: underline; }
.cross-link::after { content: '→'; margin-left: 1px; }
.cross-link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 10px 0 2px;
}

/* ---- Slide-over detail panel ----------------------------
   Used by 14 page modules. It was defined in css/pages/clients.css at 380px
   AND in css/pages/employees.css at 400px, and employees.css loads later - so
   every page including Clients rendered at 400 and the 380 was dead CSS that
   read as if it were in effect. CSS has no import graph: the last file loaded
   wins, silently. One definition, at the width that was actually in force. */
.slide-panel {
  width: 0;
  min-width: 0;
  overflow: hidden;
  transition: width 200ms ease, min-width 200ms ease;
  background: var(--card);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.slide-panel.open {
  width: 400px;
  min-width: 400px;
  border-left: 1px solid var(--border);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}
.slide-panel-inner {
  width: 400px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* ---- Record Payment modal -------------------------------
   Shared by the Invoices and Payments screens (js/utils/payment-modal.js).
   These lived in css/pages/payments.css while the modal did; a component used
   from two pages should not be styled by one of them. */
.rate-hint {
  font-size: 11.5px;
  color: var(--text-2);
  margin-top: 4px;
}
.payment-invoice-summary {
  font-size: 12.5px;
  color: var(--text-2);
  margin-bottom: 14px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.payment-status-note {
  font-size: 12px;
  color: var(--text-2);
  margin: -4px 0 14px;
}
.lkr-computed-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-top: 4px;
}
.lkr-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 3px 0;
}
.lkr-row:last-child { font-weight: 700; }
.lkr-label { color: var(--text-2); }
.lkr-val   { color: var(--text-1); font-family: monospace; }

/* ---- A control that is working --------------------------
   Applied by guarded() in js/utils/busy.js for the life of a handler, and
   removed in its finally. The cursor matters more than the opacity: a
   disabled button that still shows a pointer reads as unresponsive rather
   than as busy, and unresponsive is what makes people click again. */
.is-busy {
  opacity: 0.7;
  cursor: progress;
}

/* ---- Loading skeleton ----------------------------------- */
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, #f3f4f6 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-pulse { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.route-skeleton {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 0;
}
.skeleton-bar { height: 34px; width: 260px; }
.skeleton-row { width: 100%; }
.loading-rows td { padding: 0 14px; }
.skeleton-line { height: 14px; border-radius: var(--radius-sm); }

/* ---- KPI cards ------------------------------------------ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-1);
  line-height: 1.2;
}
.kpi-sub {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 4px;
}

/* ---- Color swatch (for status editors) ------------------- */
.color-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,.12);
}

/* ---- Divider -------------------------------------------- */
.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ---- Alert banner --------------------------------------- */
.alert-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  margin-bottom: 16px;
}
.alert-banner-warning {
  background: var(--warning-bg);
  color: #92400E;
  border: 1px solid #FCD34D;
}
.alert-banner-danger {
  background: var(--danger-bg);
  color: #991B1B;
  border: 1px solid #FCA5A5;
}
.alert-banner-info {
  background: var(--info-bg);
  color: #1E40AF;
  border: 1px solid #93C5FD;
}

/* ---- Page loading state --------------------------------- */
.page-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  color: var(--text-2);
  font-size: 14px;
}

/* ---- Activity feed in a detail panel ----------------------
   Nine modules — commlog, documents, expenses, invoices, payments, payroll,
   settings, subscriptions, timelog — build an activity list with
   .activity-row / .activity-desc / .activity-meta, and only .activity-desc had
   ever been written, in clients.css, for a fourth class name that page uses
   instead. So every one of those nine panels rendered its audit trail as
   unstyled stacked text.

   Found by check-css-classes.mjs on the day it was written. Nothing in the gate
   had ever read a stylesheet, so the whole of css/ was unchecked. */
.activity-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.activity-row:last-child { border-bottom: none; }
.activity-meta { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }

/* A narrower modal, for a dialog with three fields rather than ten. */
.modal-sm { max-width: 420px; }

/* An empty list explaining itself, inside a panel or a card. */
.empty-hint {
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.5;
  margin: 0;
  padding: 10px 0;
}

/* A select acting as a filter rather than a form field: narrower, and it does
   not stretch to the width of its container. */
.filter-select { max-width: 220px; }

/* ---- List pager (audit G28) -------------------------------
   PostgREST caps at 1,000 rows and returns no error, so an unpaged list drops
   its oldest records silently. The pager is the visible half of the fix; the
   invisible half is that every paged read now knows the true total. */
.list-pager {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 4px 4px;
}
.list-pager-status {
  font-size: 12.5px;
  color: var(--text-2);
  flex: 1;
  min-width: 120px;
}
.list-pager-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}
.list-pager-page {
  font-size: 12.5px;
  color: var(--text-2);
  padding: 0 6px;
  white-space: nowrap;
}
