/* ===========================================================================
   Sugarcane — Table system
   The data-table surface that the admin/operations portal lives on:
   a base list table with default / striped / lined variants and comfortable →
   compact density, rich cell types, sortable headers, row selection + bulk bar,
   hover row actions, a toolbar + filter bar, pagination (Pager + footer), and
   loading / empty states. Built entirely on the semantic tokens so light + dark
   theme for free. Imported by styles.css.
   =========================================================================== */

/* ---- Wrapper ----------------------------------------------------------- */
/* A bordered, rounded surface that clips the table corners and provides the
   horizontal scroll boundary on narrow viewports. */
.sc-table-wrap {
  position: relative;
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}
.sc-table-scroll { width: 100%; overflow-x: auto; }

/* ---- Base table -------------------------------------------------------- */
.sc-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  color: var(--text);
  text-align: left;
}
.sc-table caption { caption-side: top; text-align: left; padding: var(--space-3) var(--space-4); }

/* Header */
.sc-table thead th {
  position: relative;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  font-weight: var(--fw-semibold);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  letter-spacing: var(--ls-snug);
  white-space: nowrap;
  vertical-align: middle;
  border-bottom: var(--border-width) solid var(--border-strong);
}
/* Latin column-code style header (uppercase mono micro-label) */
.sc-th--code { font-family: var(--font-mono); font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: var(--ls-caps); }

/* Body */
.sc-table tbody td {
  padding: var(--space-3) var(--space-4);
  vertical-align: middle;
  color: var(--text);
  border-bottom: var(--border-width) solid var(--border-subtle);
}
.sc-table tbody tr:last-child td { border-bottom: none; }

/* Footer cells inside the table (rare; summary rows) */
.sc-table tfoot td {
  padding: var(--space-3) var(--space-4);
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
  border-top: var(--border-width-strong) solid var(--border-strong);
  background: var(--surface-2);
}

/* ---- Density ----------------------------------------------------------- */
/* Default = comfortable. compact for dense back-office grids; relaxed for
   marketing / low-row-count tables. */
.sc-table--compact thead th,
.sc-table--compact tbody td { padding: var(--space-2) var(--space-3); }
.sc-table--relaxed thead th,
.sc-table--relaxed tbody td { padding: var(--space-4) var(--space-5); }

/* ---- Row separation variants ------------------------------------------ */
/* default  : hairline rule under each row (subtle) — set on the base.
   striped  : zebra fill, no row rules.
   lined    : full-strength horizontal rules. */
.sc-table--striped tbody td { border-bottom: none; }
.sc-table--striped tbody tr:nth-child(even) td { background: var(--surface-2); }
.sc-table--lined tbody td { border-bottom: var(--border-width) solid var(--border); }

/* ---- Hover & clickable rows ------------------------------------------- */
.sc-table--hover tbody tr { transition: background var(--dur-fast) var(--ease-standard); }
.sc-table--hover tbody tr:hover td { background: var(--surface-2); }
.sc-table--striped.sc-table--hover tbody tr:hover td { background: var(--surface-3); }
.sc-table--clickable tbody tr { cursor: pointer; }
.sc-table--clickable tbody tr:focus-visible { outline: none; }
.sc-table--clickable tbody tr:focus-visible td:first-child { box-shadow: inset 3px 0 0 var(--primary); }

/* ---- Selection --------------------------------------------------------- */
.sc-table__sel { width: 1%; padding-right: 0 !important; white-space: nowrap; }
.sc-table__sel .sc-check { gap: 0; }
.sc-table tbody tr[aria-selected="true"] td,
.sc-tr--selected td { background: var(--primary-soft) !important; }
.sc-table tbody tr[aria-selected="true"]:hover td,
.sc-tr--selected:hover td { background: var(--primary-soft-hover) !important; }
.sc-table tbody tr[aria-selected="true"] td:first-child { box-shadow: inset 3px 0 0 var(--primary); }

/* ---- Sortable headers -------------------------------------------------- */
.sc-th--sortable { padding: 0 !important; }
.sc-th__btn {
  display: inline-flex; align-items: center; gap: 6px;
  width: 100%; height: 100%;
  padding: var(--space-3) var(--space-4);
  font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit;
  background: none; border: none; cursor: pointer; text-align: inherit;
  transition: color var(--dur-fast) var(--ease-standard), background var(--dur-fast) var(--ease-standard);
}
.sc-table--compact .sc-th__btn { padding: var(--space-2) var(--space-3); }
.sc-th--num .sc-th__btn { justify-content: flex-end; }
.sc-th__btn:hover { color: var(--text-strong); background: var(--surface-3); }
.sc-th__btn:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--focus-ring); }
/* sort glyph — two stacked chevrons, dimmed until active */
.sc-sort { display: inline-flex; flex-direction: column; line-height: 0; color: var(--text-subtle); flex: none; }
.sc-sort svg { width: 12px; height: 12px; display: block; }
.sc-sort__up { margin-bottom: -4px; }
.sc-th[aria-sort] .sc-th__btn,
.sc-th--sorted .sc-th__btn { color: var(--text-strong); }
/* active direction lights the matching chevron in the accent gold */
.sc-th[aria-sort="ascending"] .sc-sort__up,
.sc-th--sort-asc .sc-sort__up { color: var(--accent); }
.sc-th[aria-sort="descending"] .sc-sort__down,
.sc-th--sort-desc .sc-sort__down { color: var(--accent); }
.sc-th[aria-sort] .sc-sort,
.sc-th--sorted .sc-sort { color: var(--text-subtle); }

/* ---- Numeric & alignment helpers -------------------------------------- */
.sc-td--num, .sc-th--num { text-align: right; }
.sc-td--center, .sc-th--center { text-align: center; }
.sc-num {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums lining-nums;
  font-size: var(--fs-sm); color: var(--text-strong); white-space: nowrap;
}
.sc-num--muted { color: var(--text-muted); font-weight: var(--fw-regular); }

/* ---- Rich cell types --------------------------------------------------- */
.sc-cell__id { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }
.sc-cell__title { color: var(--text-strong); font-weight: var(--fw-medium); }
.sc-cell__sub { color: var(--text-muted); font-size: var(--fs-xs); margin-top: 1px; }

/* entity cell: avatar / icon tile + two-line text */
.sc-cell-entity { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.sc-cell-entity__text { min-width: 0; }
.sc-cell-entity__text .sc-cell__title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* icon tile used as a lightweight avatar for plots / trucks / mills */
.sc-celltile {
  width: 34px; height: 34px; flex: none; border-radius: var(--radius-md);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--primary);
}
.sc-celltile .lucide { width: 18px; height: 18px; }
.sc-celltile--gold { background: var(--accent-soft); color: var(--gold-600); }
.sc-celltile--info { background: var(--info-soft); color: var(--info); }
.sc-celltile--neutral { background: var(--surface-3); color: var(--text-muted); }

/* progress / quota cell (mini inline meter + value) */
.sc-cell-meter { display: flex; align-items: center; gap: var(--space-3); min-width: 132px; }
.sc-cell-meter .sc-progress { flex: 1; height: 6px; }
.sc-cell-meter__val { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; min-width: 34px; text-align: right; }

/* trend delta (used beside numeric cells) */
.sc-delta { font-family: var(--font-mono); font-size: var(--fs-xs); display: inline-flex; align-items: center; gap: 2px; }
.sc-delta--up { color: var(--success); }
.sc-delta--down { color: var(--danger); }
.sc-delta--flat { color: var(--text-subtle); }
.sc-delta .lucide { width: 13px; height: 13px; }

/* ---- Row actions (hover-revealed) ------------------------------------- */
.sc-cell-actions { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-1); }
.sc-table--hover tbody tr .sc-cell-actions { opacity: 0; transition: opacity var(--dur-fast) var(--ease-standard); }
.sc-table--hover tbody tr:hover .sc-cell-actions,
.sc-table--hover tbody tr:focus-within .sc-cell-actions { opacity: 1; }
@media (hover: none) { .sc-table--hover tbody tr .sc-cell-actions { opacity: 1; } }

/* ---- Toolbar (search + selects + count) ------------------------------- */
.sc-table-toolbar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-3); }
.sc-table-toolbar__search { position: relative; flex: 1 1 240px; min-width: 200px; max-width: 360px; }
.sc-table-toolbar__search .sc-inputwrap__icon { position: absolute; left: var(--space-3); top: 50%; transform: translateY(-50%); color: var(--text-subtle); display: inline-flex; pointer-events: none; z-index: 1; }
.sc-table-toolbar__search .sc-inputwrap__icon .lucide { width: 16px; height: 16px; }
.sc-table-toolbar__spacer { flex: 1 1 auto; }
.sc-table-toolbar__filters { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.sc-table-toolbar .sc-selectwrap,
.sc-table-toolbar .sc-select { min-width: 150px; }

/* result count */
.sc-table-count { font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
.sc-table-count b { color: var(--text-strong); font-weight: var(--fw-semibold); font-family: var(--font-mono); }

/* ---- Filter bar (removable applied-filter tags) ----------------------- */
.sc-filterbar { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-3); }
.sc-filterbar__label { font-family: var(--font-mono); font-size: var(--fs-2xs); letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--text-subtle); }
/* applied-filter chip — built on .sc-tag, with a key:value face */
.sc-filtertag { background: var(--surface-2); color: var(--text); border-color: var(--border); height: 26px; }
.sc-filtertag .k { color: var(--text-subtle); font-size: var(--fs-2xs); }
.sc-filterbar__clear {
  font-family: var(--font-sans); font-size: var(--fs-xs); color: var(--text-muted);
  background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: var(--radius-sm);
  text-decoration: underline; text-underline-offset: 2px;
}
.sc-filterbar__clear:hover { color: var(--danger); }

/* ---- Bulk-action bar (selection) --------------------------------------
   Theme-native: extends the selected-row primary tint so it reads
   correctly on BOTH light and dark canvases (no inverse flash). */
.sc-bulkbar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--primary-soft); color: var(--text-strong);
  border: var(--border-width) solid var(--primary-border);
  border-radius: var(--radius-md); margin-bottom: var(--space-3);
  box-shadow: var(--shadow-sm);
  animation: sc-bulk-in var(--dur-base) var(--ease-emphasis);
}
@keyframes sc-bulk-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .sc-bulkbar { animation: none; } }
.sc-bulkbar__count { font-size: var(--fs-sm); font-weight: var(--fw-semibold); display: inline-flex; align-items: center; gap: var(--space-2); }
.sc-bulkbar__count .n { font-family: var(--font-mono); }
.sc-bulkbar__count .lucide { color: var(--primary); }
.sc-bulkbar__sep { width: 1px; align-self: stretch; background: var(--primary-border); }
.sc-bulkbar__spacer { flex: 1 1 auto; }
.sc-bulkbar__actions { display: flex; align-items: center; gap: var(--space-1); }
/* ghost buttons that read on the tinted bar */
.sc-bulkbar__btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 var(--space-3);
  font-family: var(--font-sans); font-size: var(--fs-sm); font-weight: var(--fw-medium);
  color: var(--text-strong); background: transparent;
  border: var(--border-width) solid color-mix(in srgb, var(--primary) 40%, transparent);
  border-radius: var(--radius-md); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard), border-color var(--dur-fast) var(--ease-standard);
}
.sc-bulkbar__btn .lucide { width: 15px; height: 15px; }
.sc-bulkbar__btn:hover { background: color-mix(in srgb, var(--primary) 14%, transparent); border-color: var(--primary); }
.sc-bulkbar__btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.sc-bulkbar__btn--danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); border-color: var(--danger); }
.sc-bulkbar__close {
  display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
  color: var(--text-muted); background: transparent; border: none; border-radius: var(--radius-md); cursor: pointer;
}
.sc-bulkbar__close:hover { color: var(--text-strong); background: color-mix(in srgb, var(--primary) 14%, transparent); }

/* ---- Footer: row count · rows-per-page · pager ------------------------ */
.sc-table-foot {
  display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap;
  padding: var(--space-3) var(--space-4);
  border-top: var(--border-width) solid var(--border);
  background: var(--surface-2);
}
.sc-table-foot--bare { background: none; border-top: none; padding: var(--space-3) 0 0; }
.sc-table-foot__info { font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
.sc-table-foot__info b { color: var(--text-strong); font-weight: var(--fw-semibold); font-family: var(--font-mono); }
.sc-table-foot__spacer { flex: 1 1 auto; }
.sc-rpp { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
.sc-rpp .sc-selectwrap { min-width: 0; }
.sc-rpp .sc-select { min-width: 0; }
.sc-rpp select.sc-input { height: 32px; font-size: var(--fs-sm); width: auto; padding-left: var(--space-2); padding-right: calc(var(--space-2) + 18px); }
.sc-rpp .sc-select__trigger { height: 32px; min-height: 32px; font-size: var(--fs-sm); width: auto; padding-left: var(--space-2); padding-right: calc(var(--space-2) + 18px); }

/* ---- Pager ------------------------------------------------------------- */
.sc-pager { display: inline-flex; align-items: center; gap: var(--space-1); }
.sc-pager__btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 var(--space-2);
  font-family: var(--font-mono); font-size: var(--fs-sm); font-variant-numeric: tabular-nums;
  color: var(--text); background: var(--surface);
  border: var(--border-width) solid var(--border); border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard), border-color var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.sc-pager__btn .lucide { width: 16px; height: 16px; }
.sc-pager__btn:hover:not(:disabled):not(.sc-pager__btn--active) { background: var(--surface-3); border-color: var(--border-strong); }
.sc-pager__btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.sc-pager__btn--active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: var(--fw-semibold); cursor: default; }
.sc-pager__btn:disabled { opacity: .45; cursor: not-allowed; }
.sc-pager__ellipsis { display: inline-flex; align-items: flex-end; justify-content: center; min-width: 22px; height: 32px; color: var(--text-subtle); padding-bottom: 4px; }

/* ---- Skeleton / loading (shimmer) ------------------------------------- */
.sc-skel {
  display: block; border-radius: var(--radius-sm);
  background: var(--surface-3);
  background-image: linear-gradient(90deg, transparent 0%, color-mix(in srgb, var(--surface) 70%, transparent) 50%, transparent 100%);
  background-size: 200% 100%; background-repeat: no-repeat;
  animation: sc-shimmer 1.3s ease-in-out infinite;
}
@keyframes sc-shimmer { 0% { background-position: 180% 0; } 100% { background-position: -80% 0; } }
@media (prefers-reduced-motion: reduce) { .sc-skel { animation: none; } }
.sc-skel--text { height: 11px; }
.sc-skel--circle { border-radius: 50%; }
.sc-skel-cell { display: flex; align-items: center; gap: var(--space-3); }
.sc-skel-lines { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }

/* ---- In-table empty state --------------------------------------------- */
.sc-table-empty > td { padding: 0 !important; background: var(--surface) !important; }
.sc-table-empty .sc-empty { padding: var(--space-12) var(--space-6); }
.sc-table-empty--filtered .sc-empty__art { background: var(--surface-3); color: var(--text-muted); }
