/*
 * Skeleton-loader primitives for the books SPA.
 *
 * Used by controller.js (loadX functions) and the dashboard panels to
 * render shimmer placeholders BEFORE the network response arrives. Every
 * loader replaces .skel-* elements with real markup once data is in.
 *
 * Sizing is data-attribute driven so the same shimmer block can stand in
 * for a number, a money string, a row, a chart, etc. without per-callsite
 * CSS.
 */

@keyframes ll-shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skel {
  display: inline-block;
  background: linear-gradient(90deg, #E5E7EB 0%, #F3F4F6 50%, #E5E7EB 100%);
  background-size: 200% 100%;
  animation: ll-shimmer 1.5s ease-in-out infinite;
  border-radius: 6px;
  color: transparent;
  vertical-align: middle;
  user-select: none;
}

.skel-line {
  height: 14px;
  width: 100%;
}

.skel-text  { height: 14px; width: 6em; }
.skel-text-sm { height: 12px; width: 4em; }
.skel-text-lg { height: 22px; width: 8em; }
.skel-money { height: 22px; width: 7em; }
.skel-money-lg { height: 28px; width: 10em; }
.skel-pill { height: 22px; width: 70px; border-radius: 999px; }
.skel-circle { height: 32px; width: 32px; border-radius: 50%; }
.skel-block { display: block; height: 100%; width: 100%; min-height: 24px; }

/*
 * Table row skeleton: drop in as the only <tr> in a <tbody> while loading.
 * The loader's renderListInto() replaces the whole tbody with real rows.
 */
.skel-row td {
  padding: 14px 12px;
}
.skel-row td > .skel {
  display: block;
  height: 14px;
  width: min(80%, 220px);
}

/* Chart canvas placeholder — replaces the canvas while data is being fetched. */
.skel-chart {
  display: block;
  width: 100%;
  height: 260px;
  border-radius: 12px;
}

/* Dashboard panel list (Recent Invoices etc.) skeleton row */
.skel-panel-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border, #E5E7EB);
}
.skel-panel-row:last-child { border-bottom: none; }
.skel-panel-row .skel-grow { flex: 1; }
.skel-panel-row .skel-line + .skel-line { margin-top: 6px; }

/* Accessibility: honour reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .skel { animation: none; }
}

/*
 * Modal-form (LL.openCreateForm) styles.
 *
 * The form is dropped into the existing #modal .modal-box overlay so we
 * inherit the modal chrome (centred card, backdrop). These rules just
 * style the dynamically-built fields, buttons, banner, and line-items
 * repeater.
 */
.mf-form { display: flex; flex-direction: column; gap: 12px; }
.mf-body { display: flex; flex-direction: column; gap: 14px; padding: 16px 20px; }

/*
 * Elaborate-layout extensions for the invoice / expense / journal forms.
 * `mf-body-with-sidebar` is a 2-column grid: form on the left, sticky
 * live-totals aside on the right. `mf-section` carries a small header
 * row so multi-section forms read naturally (Customer / Lines / Notes).
 */
.modal-box-wide { width: min(1100px, 96vw) !important; }
.mf-body-with-sidebar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 24px;
  align-items: start;
  padding: 16px 20px;
}
.mf-fields-col { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.mf-section { display: flex; flex-direction: column; gap: 12px; }
.mf-section-head {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #475569;
  padding-bottom: 6px;
  border-bottom: 1px solid #E5E7EB;
}
.mf-sidebar {
  position: sticky;
  top: 0;
  background: #F8FAFC;
  border: 1px solid #E5E7EB;
  border-radius: 10px;
  padding: 16px;
  font-size: 13px;
  color: #334155;
}
.mf-sidebar h4 {
  margin: 0 0 12px 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748B;
}
.mf-sidebar-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 6px 0;
  font-variant-numeric: tabular-nums;
}
.mf-sidebar-row.total {
  border-top: 1px solid #CBD5E1;
  margin-top: 8px; padding-top: 10px;
  font-weight: 700; color: #0F172A; font-size: 15px;
}
.mf-sidebar-row.muted { color: #94A3B8; font-size: 12px; }
@media (max-width: 720px) {
  .mf-body-with-sidebar { grid-template-columns: 1fr; padding: 16px; }
  .mf-sidebar { position: static; }
}

.mf-field { display: flex; flex-direction: column; gap: 6px; }
.mf-label { font-size: 12px; font-weight: 600; color: #475569; }
.mf-req { color: #DC2626; }
.mf-field input, .mf-field select, .mf-field textarea,
.mf-line-col, .mf-line-combo {
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  background: #fff;
  color: #0F172A;
  width: 100%;
}
.mf-field input:focus, .mf-field select:focus, .mf-field textarea:focus,
.mf-line-col:focus, .mf-line-combo:focus {
  outline: 2px solid #10B981;
  outline-offset: 1px;
  border-color: #10B981;
}
.mf-help { color: #64748B; font-size: 11px; }
/* Inline checkbox field (e.g. "Make this primary") — row layout, not the
   default stacked column, and a fixed-size box (not the 100%-wide text input). */
.mf-field-check { flex-direction: row; align-items: center; }
.mf-check-label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: #475569; cursor: pointer; }
.mf-field-check input[type="checkbox"] { width: 16px; height: 16px; padding: 0; margin: 0; accent-color: #10B981; cursor: pointer; }
/* Tag-chip input (Report by Tag dimension tags). */
.mf-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid #E5E7EB; border-radius: 8px; padding: 6px 8px; background: #fff; }
.mf-tags:focus-within { outline: 2px solid #10B981; outline-offset: 1px; border-color: #10B981; }
.mf-tag-chip { display: inline-flex; align-items: center; gap: 5px; background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; border-radius: 999px; padding: 2px 6px 2px 10px; font-size: 12px; font-weight: 600; }
.mf-tag-x { border: none; background: transparent; color: #047857; font-size: 15px; line-height: 1; cursor: pointer; padding: 0 2px; }
.mf-tag-x:hover { color: #DC2626; }
.mf-tags-input { flex: 1; min-width: 120px; border: none; outline: none; padding: 3px 2px; font-size: 14px; background: transparent; color: #0F172A; }
.mf-tags-input:focus { outline: none; }
/* Multi-file attachment picker (bills, etc.) */
.mf-uploads { display: flex; flex-direction: column; gap: 6px; }
.mf-uploads-input { font-size: 13px; }
.mf-uploads-existing { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.mf-uploads-existing li { font-size: 12.5px; color: #0F172A; }
.mf-uploads-status { color: #64748B; font-size: 11px; }

.mf-banner {
  margin: 12px 20px 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid transparent;
}
.mf-banner-err { background: #FEF2F2; border-color: #FECACA; color: #B91C1C; }
.mf-banner-ok  { background: #ECFDF5; border-color: #A7F3D0; color: #047857; }
/* "Your unsaved entry was restored" — informational, not a success/failure. */
.mf-banner-info { background: #EFF6FF; border-color: #BFDBFE; color: #1D4ED8; }

/* Line-items repeater */
.mf-lines { border: 1px dashed #E5E7EB; border-radius: 10px; padding: 10px; }
.mf-lines-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.mf-lines-add { font-size: 12px; padding: 4px 10px; }
.mf-lines-body { display: flex; flex-direction: column; gap: 8px; }
.mf-line-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)) 28px;
  gap: 8px;
  align-items: end;
}
.mf-line-cell { display: flex; flex-direction: column; gap: 2px; }
.mf-line-label { font-size: 10px; color: #94A3B8; text-transform: uppercase; letter-spacing: 0.04em; }
.mf-line-rm {
  border: 1px solid #FECACA;
  background: #FEF2F2;
  color: #B91C1C;
  border-radius: 6px;
  width: 28px; height: 28px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.mf-line-rm:hover { background: #FEE2E2; }

/* Disabled "+ New X" button (entity not yet wired) */
.btn-em[disabled], .btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  filter: grayscale(0.4);
}
.btn-em[disabled]:hover, .btn[disabled]:hover { filter: grayscale(0.4); }

/*
 * Per-row Edit / Destroy buttons in list tables. Rendered by
 * `rowActions()` in controller.js into the trailing "Actions" column.
 * Event delegation in controller.js picks them up via
 * `[data-row-action]`.
 */
.row-actions {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
  white-space: normal;
  max-width: 28rem;
  justify-content: flex-end;
}
.row-actions .row-action {
  border: 1px solid var(--border, #E2E8F0);
  background: transparent;
  color: var(--text-2, #475569);
  border-radius: var(--r-xs, 4px);
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.4;
  transition: all var(--transition, 0.22s ease);
}
.row-actions .row-action:hover {
  background: var(--emerald-lt, #E6F9F3);
  color: var(--emerald, #00B87C);
  border-color: var(--emerald, #00B87C);
}
.row-actions .row-action-destroy {
  border-color: var(--rose, #F43F5E);
  color: var(--rose, #F43F5E);
}
.row-actions .row-action-destroy:hover {
  background: var(--rose-lt, #FFF1F2);
  color: var(--rose, #F43F5E);
  border-color: var(--rose, #F43F5E);
}

/* More than two table-row actions collapse behind a vertical-ellipsis button. */
.row-actions.has-row-action-menu,
.td-actions.has-row-action-menu {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 0;
  width: auto;
  max-width: none;
  overflow: visible;
}
.table-row-actions-toggle {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: var(--r-sm, 8px);
  background: var(--surface, #fff);
  color: var(--text-2, #475569);
  cursor: pointer;
  transition: all var(--transition, 0.22s ease);
}
.table-row-actions-toggle:hover,
.table-row-actions-toggle:focus-visible {
  border-color: var(--emerald, #00B87C);
  background: var(--emerald-lt, #E6F9F3);
  color: var(--emerald, #00B87C);
  outline: none;
}
.table-row-actions-menu {
  position: fixed;
  z-index: 9000;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  min-width: 176px;
  max-width: min(264px, calc(100vw - 16px));
  max-height: calc(100vh - 16px);
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: var(--r-md, 12px);
  background: var(--surface, #fff);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
}
.table-row-actions-menu[hidden] { display: none !important; }
.table-row-actions-menu > .row-action,
.table-row-actions-menu > .tbl-action-btn {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: 34px;
  margin: 0;
  padding: 7px 10px;
  border-radius: var(--r-xs, 4px);
  font-size: 12px;
  line-height: 1.35;
  text-align: left;
  white-space: normal;
}

/* Shared modal / confirmation action row */
.modal-box .modal-foot {
  box-sizing: border-box;
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  width: 100%;
  margin-top: 0;
  padding: 14px 20px;
  border-top: 1px solid var(--border, #E2E8F0);
  background: var(--surface, #fff);
}
.modal-box .modal-foot > .btn {
  box-sizing: border-box;
  flex: 0 1 auto;
  min-width: 112px;
  max-width: 100%;
  min-height: 40px;
  height: auto;
  padding: 9px 14px;
  justify-content: center;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
}
.modal-box .modal-foot > .mf-destroy-confirm { min-width: 140px; }

@media (max-width: 520px) {
  .modal-box .modal-foot {
    gap: 8px;
    padding: 12px 16px;
  }
  .modal-box .modal-foot > .btn {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
  }
}
@media (max-width: 360px) {
  .modal-box .modal-foot > .btn { flex-basis: 100%; }
}

/* Destructive confirm dialog (LL.confirmDestroy) */
.mf-destroy-body { padding: 18px 20px; }
.mf-destroy-msg {
  margin: 0;
  color: #475569;
  font-size: 14px;
  line-height: 1.5;
}
.mf-cascade-details {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid #FECACA;
  border-radius: 8px;
  background: #FFF7F7;
  color: #7F1D1D;
  max-height: 260px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.45;
}
.mf-cascade-details:empty { display: none; }
.mf-cascade-heading { margin: 0 0 6px; font-weight: 700; }
.mf-cascade-root { margin: 4px 0 8px; font-weight: 600; }
.mf-cascade-list { margin: 4px 0 10px; padding-left: 20px; }
.mf-cascade-list li { margin: 2px 0; overflow-wrap: anywhere; }
.mf-cascade-effects { color: #78350F; }
.mf-cascade-empty { margin: 4px 0 8px; color: #64748B; }
.mf-cascade-warning {
  padding: 10px 12px;
  border-radius: 6px;
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  color: #92400E;
}
.mf-destroy-confirm {
  background: #DC2626;
  color: #fff;
  border: 1px solid #DC2626;
}
.mf-destroy-confirm:hover { background: #B91C1C; }
.mf-destroy-confirm[disabled] { opacity: 0.6; cursor: not-allowed; }
