.table-demo {
  --td-blue: #075de8;
  --td-green: #16805f;
  --td-amber: #b46a00;
  --td-red: #c5374f;
  --td-ink: var(--text, #10233c);
  --td-muted: var(--text-muted, #68778b);
  --td-line: var(--border, #d8e1ec);
  --td-soft: var(--surface-subtle, #f4f7fb);
  --td-surface: var(--surface, #fff);
  position: relative;
  display: grid;
  width: 100%;
  min-width: 0;
  gap: 7px;
  color: var(--td-ink);
  font-size: 9px;
}

.table-demo * { box-sizing: border-box; }

.td-toolbar {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.td-toolbar > span {
  min-width: 0;
  overflow: hidden;
  color: var(--td-muted);
  font-weight: 800;
  letter-spacing: .055em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.table-demo button,
.table-demo input,
.table-demo select {
  font: inherit;
}

.table-demo button {
  border: 1px solid var(--td-line);
  border-radius: 4px;
  background: var(--td-surface);
  color: var(--td-blue);
  cursor: pointer;
  font-weight: 800;
  padding: 4px 6px;
}

.table-demo button.primary {
  border-color: var(--td-blue);
  background: var(--td-blue);
  color: #fff;
}

.table-demo button:focus-visible,
.table-demo input:focus-visible,
.table-demo select:focus-visible,
.table-demo [tabindex="0"]:focus-visible,
.table-demo [contenteditable="true"]:focus-visible,
.table-demo a:focus-visible {
  outline: 2px solid var(--td-blue);
  outline-offset: 2px;
}

.table-demo input,
.table-demo select {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--td-line);
  border-radius: 3px;
  background: var(--td-surface);
  color: var(--td-ink);
  padding: 4px;
}

.table-demo input[type="checkbox"],
.table-demo input[type="radio"] {
  width: 13px;
  height: 13px;
  accent-color: var(--td-blue);
}

.td-scroll {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--td-line);
  border-radius: 6px;
  background: var(--td-surface);
  scrollbar-width: thin;
}

.table-demo table {
  width: 100%;
  border-collapse: collapse;
  color: inherit;
  font: inherit;
  text-align: left;
}

.table-demo caption {
  padding: 7px;
  color: var(--td-ink);
  font-weight: 800;
  text-align: left;
}

.table-demo th,
.table-demo td {
  min-width: 42px;
  border-bottom: 1px solid var(--td-line);
  padding: 6px 7px;
  text-align: left;
  vertical-align: middle;
}

.table-demo thead th {
  background: var(--td-soft);
  color: var(--td-muted);
  font-weight: 800;
}

.table-demo tbody th { font-weight: 750; }
.table-demo tbody tr:last-child > * { border-bottom: 0; }
.table-demo tbody tr:hover > * { background: color-mix(in srgb, var(--td-blue) 5%, var(--td-surface)); }
.table-demo tfoot > * > * { border-top: 2px solid var(--td-ink); border-bottom: 0; font-weight: 900; }
.table-demo > small { color: var(--td-muted); font-size: 8px; }

.td-grouped-cols thead tr:first-child th:not(:first-child) { border-left: 2px solid var(--td-line); color: var(--td-blue); text-align: center; }
.td-numeric td:not(:first-child), .td-numeric th:not(:first-child) { font-variant-numeric: tabular-nums; text-align: right; }
.td-striped tbody tr:nth-child(even) > * { background: var(--td-soft); }
.td-borderless, .td-borderless > * { border: 0; }
.td-borderless th, .td-borderless td { border: 0; border-bottom: 1px solid var(--td-line); padding-block: 8px; }
.td-compact th, .td-compact td { padding-block: 3px; }

.table-demo-sortable-data-table thead button {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
}

.td-sort-chips,
.td-filterbar,
.td-column-order,
.td-range,
.td-live,
.td-batch {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
}

.td-sort-chips span,
.td-filterbar span,
.td-column-order span,
.td-range {
  flex: none;
  border-radius: 999px;
  background: color-mix(in srgb, var(--td-blue) 9%, var(--td-surface));
  color: var(--td-blue);
  padding: 3px 6px;
}

.td-search {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--td-line);
  border-radius: 5px;
  padding-inline-start: 6px;
}

.td-search input { border: 0; }
.td-filter-row input, .td-filter-row select { font-size: 7px; padding: 2px; }
.table-demo.is-filtered tbody tr:last-child { display: none; }

.td-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.td-pager span { margin-right: auto; color: var(--td-muted); }
.td-pager button { padding: 3px 7px; }

.td-full-toolbar {
  display: flex;
  align-items: center;
  gap: 3px;
  overflow-x: auto;
}

.td-full-toolbar label { display: flex; min-width: 75px; align-items: center; border: 1px solid var(--td-line); border-radius: 4px; padding-left: 4px; }
.td-full-toolbar label input { border: 0; }
.td-full-toolbar button { flex: none; }

.td-batch {
  border-radius: 5px;
  background: var(--td-blue);
  color: #fff;
  padding: 4px;
}

.td-batch b { margin-right: auto; padding-left: 3px; }
.td-batch button { border-color: rgba(255,255,255,.5); background: transparent; color: #fff; }
.td-actions td:last-child { white-space: nowrap; }
.td-actions td:last-child button { padding: 2px 4px; }
.td-linked tbody th a { color: var(--td-blue); text-decoration-thickness: 1px; text-underline-offset: 2px; }

.td-menu {
  position: absolute;
  z-index: 3;
  top: 35px;
  right: 5px;
  display: grid;
  width: 88px;
  border: 1px solid var(--td-line);
  border-radius: 5px;
  background: var(--td-surface);
  box-shadow: 0 10px 24px rgba(16,35,60,.16);
  padding: 3px;
}

.td-menu[hidden] { display: none; }
.td-menu button { border: 0; color: var(--td-ink); text-align: left; }

.td-editable input[hidden],
.td-row-edit input,
.td-row-edit .save { display: none; }
.td-row-edit.is-editing span { display: none; }
.td-row-edit.is-editing input,
.td-row-edit.is-editing .save { display: inline-block; }
.td-row-edit.is-editing td:last-child > button:first-child { display: none; }

.td-grid,
.td-treegrid {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--td-line);
  border-radius: 6px;
}

.td-grid [role="row"],
.td-treegrid [role="row"] {
  display: grid;
  grid-template-columns: 1.2fr 1fr .8fr;
}

.td-grid [role="row"] > *,
.td-treegrid [role="row"] > * {
  min-width: 0;
  overflow: hidden;
  border-bottom: 1px solid var(--td-line);
  padding: 6px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.td-grid [role="row"]:first-child,
.td-treegrid [role="row"]:first-child { background: var(--td-soft); color: var(--td-muted); }
.td-grid [role="gridcell"]:focus { outline: 2px solid var(--td-blue); outline-offset: -2px; background: color-mix(in srgb, var(--td-blue) 8%, var(--td-surface)); }
.td-grid [contenteditable="true"] { cursor: text; }
.td-treegrid [aria-level="2"] [role="gridcell"]:first-child { padding-left: 18px; }
.td-treegrid button { border: 0; padding: 0 3px; }

.td-error-summary {
  display: grid;
  border-left: 3px solid var(--td-red);
  background: color-mix(in srgb, var(--td-red) 8%, var(--td-surface));
  padding: 6px;
}

.td-error-summary span, .td-invalid small { color: var(--td-red); }
.td-invalid input { border-color: var(--td-red); }
.td-selected-range tbody tr:nth-child(-n+2) > *:nth-child(-n+2) { background: color-mix(in srgb, var(--td-blue) 13%, var(--td-surface)); box-shadow: inset 0 0 0 1px var(--td-blue); }
.td-detail-row td { background: var(--td-soft); padding: 9px 12px; }
.td-group-row > * { background: color-mix(in srgb, var(--td-blue) 9%, var(--td-surface)); color: var(--td-blue); }
.td-subtotal > * { border-top: 2px solid var(--td-line); font-weight: 900; }

.td-master-detail {
  display: grid;
  grid-template-columns: 1.3fr .8fr;
  gap: 6px;
}

.td-master-detail aside {
  display: grid;
  align-content: start;
  gap: 5px;
  border: 1px solid var(--td-line);
  border-radius: 6px;
  padding: 7px;
}

.td-master-detail aside small { color: var(--td-blue); font-size: 7px; font-weight: 900; }
.td-master-detail aside span { color: var(--td-muted); }
.td-comparison td, .td-comparison th:not(:first-child), .td-pricing td, .td-pricing th:not(:first-child), .td-permissions td { text-align: center; }
.td-pricing .recommended { background: color-mix(in srgb, var(--td-blue) 14%, var(--td-surface)); color: var(--td-blue); }

.td-wide table { min-width: 430px; }
.td-tall { max-height: 122px; }
.td-sticky thead { position: sticky; z-index: 2; top: 0; }
.td-frozen th:first-child, .td-frozen td:first-child { position: sticky; left: 0; z-index: 1; background: var(--td-surface); box-shadow: 4px 0 7px rgba(16,35,60,.08); }
.td-frozen thead th:first-child { z-index: 2; background: var(--td-soft); }
.td-resizable th { position: relative; }
.td-resizable th i { position: absolute; top: 3px; right: 0; bottom: 3px; width: 3px; border-radius: 3px; background: var(--td-blue); cursor: col-resize; }
.hide-optional-column .td-column-toggle :is(th,td):nth-child(2) { display: none; }

.preview-stacked .td-stackable,
.preview-stacked .td-stackable tbody,
.preview-stacked .td-stackable tr,
.preview-stacked .td-stackable th,
.preview-stacked .td-stackable td { display: block; width: 100%; }
.preview-stacked .td-stackable thead { display: none; }
.preview-stacked .td-stackable tr { margin-bottom: 5px; border: 1px solid var(--td-line); border-radius: 4px; }
.preview-stacked .td-stackable th, .preview-stacked .td-stackable td { border: 0; padding: 3px 6px; }
.preview-stacked .td-stackable td::before { display: inline-block; width: 42px; color: var(--td-muted); font-weight: 800; }
.preview-stacked .td-stackable td:nth-child(2)::before { content: "Owner"; }
.preview-stacked .td-stackable td:nth-child(3)::before { content: "Status"; }

.td-skeleton i {
  display: block;
  height: 7px;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--td-line), var(--td-soft), var(--td-line));
  background-size: 200% 100%;
  animation: td-shimmer 1.3s linear infinite;
}

.td-state {
  display: grid;
  justify-items: center;
  gap: 5px;
  border: 1px solid var(--td-line);
  border-radius: 6px;
  background: var(--td-soft);
  padding: 15px 8px;
  text-align: center;
}

.td-state > i {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--td-blue) 12%, var(--td-surface));
  color: var(--td-blue);
  font-style: normal;
  font-weight: 900;
}

.td-state span { color: var(--td-muted); }
.td-error > i { background: color-mix(in srgb, var(--td-red) 12%, var(--td-surface)); color: var(--td-red); }
.td-live { justify-content: space-between; }
.td-live span { display: flex; align-items: center; gap: 4px; color: var(--td-green); font-weight: 800; }
.td-live span i { width: 7px; height: 7px; border-radius: 50%; background: var(--td-green); }
.td-live button[aria-pressed="true"] + * { opacity: .65; }

.td-virtual { position: relative; display: grid; gap: 4px; padding-right: 5px; }
.td-virtual > span { color: var(--td-muted); }
.td-virtual-thumb { position: absolute; top: 35px; right: 0; width: 3px; height: 38px; border-radius: 3px; background: var(--td-blue); }
.td-financial tbody tr:last-child > * { border-top: 2px solid var(--td-ink); font-weight: 900; }
.td-ledger td:nth-child(n+3) { white-space: nowrap; }
.td-timetable td { min-width: 55px; height: 30px; }
.td-timetable .event { border-left: 3px solid var(--td-blue); background: color-mix(in srgb, var(--td-blue) 11%, var(--td-surface)); color: var(--td-blue); font-weight: 800; }

.concept-card-preview .table-demo { font-size: 7px; }
.concept-card-preview .table-demo th,
.concept-card-preview .table-demo td { min-width: 30px; padding: 4px; }
.concept-card-preview .table-demo button { padding: 3px 4px; }
.concept-card-preview .td-master-detail { grid-template-columns: 1fr; }
.concept-card-preview .td-master-detail aside { display: none; }
.concept-card-preview .td-full-toolbar button:nth-of-type(2),
.concept-card-preview .td-full-toolbar button:nth-of-type(3) { display: none; }

[data-theme="dark"] .table-demo { --td-green: #55d5a8; --td-amber: #f0ad4e; --td-red: #ff7c8c; }

@keyframes td-shimmer { to { background-position: -200% 0; } }

@media (max-width: 480px) {
  .table-demo { font-size: 10px; }
  .table-demo th, .table-demo td { min-width: 56px; }
  .td-master-detail { grid-template-columns: 1fr; }
  .td-master-detail aside { border-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .td-skeleton i { animation: none; }
  .table-demo * { transition: none !important; }
}

@media (forced-colors: active) {
  .td-scroll,
  .td-grid,
  .td-treegrid,
  .td-state,
  .table-demo button,
  .table-demo input,
  .table-demo select { border: 1px solid CanvasText; }
  .td-batch,
  .td-timetable .event,
  .td-state > i { forced-color-adjust: none; background: Highlight; color: HighlightText; }
}
