/* ================================================================
   DataHints DS — Table Component
   Requires: tokens.css
   ================================================================ */

  /* Delta chip */
  .delta {
    display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
    border-radius: var(--r-pill); padding: 3px 8px;
    font-family: var(--font-mono); font-size: 0.6875rem; line-height: 1;
    color: var(--mint); background: var(--mint-sub);
    border: 1px solid color-mix(in srgb, var(--mint) 30%, transparent);
  }
  .delta svg { width: 11px; height: 11px; flex-shrink: 0; }
  .delta.is-down  { color: var(--micro-coral-text); background: var(--micro-coral-sub); border-color: color-mix(in srgb, var(--micro-coral) 30%, transparent); }
  .delta.is-flat  { color: var(--fg-3); background: var(--bg-elevated); border-color: var(--border-s); }
  .delta.is-warn  { color: var(--micro-amber-text); background: var(--micro-amber-sub); border-color: color-mix(in srgb, var(--micro-amber) 30%, transparent); }


  /* ============================================================
     TABLE CORE
  ============================================================ */

  .dh-table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border-s);
    border-radius: var(--r-md);
    overflow: hidden;
    box-shadow: var(--shadow-card);
  }

  /* Title bar */
  .table-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border-s);
    gap: var(--sp-4);
  }
  .table-header-left { display: flex; flex-direction: column; gap: 2px; }
  .table-title {
    font-family: var(--font-sans); font-weight: 600; font-size: 0.9375rem; color: var(--fg);
  }
  .table-meta {
    font-family: var(--font-mono); font-size: 0.75rem; color: var(--fg-3);
  }
  .table-period {
    font-family: var(--font-mono); font-size: 0.6875rem; color: var(--fg-3);
    background: var(--bg-elevated); border: 1px solid var(--border-s);
    border-radius: var(--r-xs); padding: 4px 10px; white-space: nowrap; flex-shrink: 0;
  }

  /* Scroll container */
  .dh-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border-s) transparent;
  }
  .dh-table-scroll::-webkit-scrollbar { height: 6px; }
  .dh-table-scroll::-webkit-scrollbar-track { background: transparent; }
  .dh-table-scroll::-webkit-scrollbar-thumb { background: var(--border-s); border-radius: 3px; }

  /* Table base */
  .dh-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    min-width: 640px;
  }

  /* ── THEAD ─────────────────────────────────────────────────── */
  .dh-table thead tr {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-s);
  }
  .dh-table th {
    padding: var(--sp-3) var(--sp-4);
    text-align: left;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.10em;
    color: var(--fg-3);
    white-space: nowrap;
    user-select: none;
  }
  .dh-table th.num { text-align: right; }

  /* ── STICKY HEADER ─────────────────────────────────────────── */
  .has-sticky-header .dh-table-scroll {
    overflow-y: auto;
  }
  .has-sticky-header .dh-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .has-sticky-header .dh-table thead tr {
    box-shadow: 0 2px 8px color-mix(in srgb, var(--bg) 60%, transparent);
  }

  /* ── SORT ──────────────────────────────────────────────────── */
  .th-sort {
    cursor: pointer;
    display: inline-flex; align-items: center; gap: 4px;
    transition: color var(--ease-fast);
    border-radius: var(--r-xs);
  }
  .th-sort:hover { color: var(--fg-2); }
  .th-sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .th-sort.is-active { color: var(--accent-text); }

  .th-sort-icon {
    width: 12px; height: 12px;
    opacity: 0.4;
    transition: opacity var(--ease-fast), transform var(--ease-fast);
    flex-shrink: 0;
  }
  .th-sort.is-active .th-sort-icon { opacity: 1; }
  .th-sort.is-active.is-asc  .th-sort-icon { transform: rotate(180deg); }
  .th-sort.is-active.is-desc .th-sort-icon { transform: rotate(0deg); }

  /* ── TBODY ─────────────────────────────────────────────────── */
  .dh-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--ease-fast);
  }
  .dh-table tbody tr:last-child { border-bottom: none; }
  .dh-table tbody tr:hover { background: var(--bg-card-h); }

  .dh-table td {
    padding: var(--sp-3) var(--sp-4);
    color: var(--fg-2);
    vertical-align: middle;
  }

  /* ── CELLS ─────────────────────────────────────────────────── */
  .dh-table td.num, .dh-table th.num {
    text-align: right;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--fg);
    font-variant-numeric: tabular-nums;
  }
  .dh-table td.num.is-up   { color: var(--mint); }
  .dh-table td.num.is-down { color: var(--micro-coral-text); }
  .dh-table td.num.is-muted { color: var(--fg-3); }

  .dh-table td.row-label {
    font-weight: 500; color: var(--fg);
    white-space: nowrap;
  }
  .row-dot {
    display: inline-block; width: 8px; height: 8px;
    border-radius: 50%; margin-right: var(--sp-2); flex-shrink: 0;
    vertical-align: middle; margin-top: -1px;
  }

  /* Pinned first column */
  .col-pin {
    position: sticky; left: 0; z-index: 1;
    background: var(--bg-card);
  }
  .dh-table tbody tr:hover .col-pin { background: var(--bg-card-h); }

  /* ── ROW HIGHLIGHTS ────────────────────────────────────────── */
  .dh-table tbody tr.is-top {
    background: var(--accent-sub);
  }
  .dh-table tbody tr.is-top:hover {
    background: var(--bg-card-h); /* fallback */
    background: color-mix(in srgb, var(--accent-sub) 80%, var(--bg-card-h));
  }
  .dh-table tbody tr.is-top .col-pin { background: var(--accent-sub); }
  .dh-table tbody tr.is-top:hover .col-pin {
    background: var(--bg-card-h); /* fallback */
    background: color-mix(in srgb, var(--accent-sub) 80%, var(--bg-card-h));
  }

  .dh-table tbody tr.is-success {
    background: var(--mint-sub); /* fallback */
    background: color-mix(in srgb, var(--mint) 10%, transparent);
  }
  .dh-table tbody tr.is-success:hover {
    background: var(--mint-sub); /* fallback */
    background: color-mix(in srgb, var(--mint) 15%, var(--bg-card-h));
  }

  .dh-table tbody tr.is-warn {
    background: var(--micro-amber-sub); /* fallback */
    background: color-mix(in srgb, var(--micro-amber) 10%, transparent);
  }
  .dh-table tbody tr.is-warn:hover {
    background: var(--micro-amber-sub); /* fallback */
    background: color-mix(in srgb, var(--micro-amber) 15%, var(--bg-card-h));
  }

  .dh-table tbody tr.is-alert {
    background: var(--micro-coral-sub); /* fallback */
    background: color-mix(in srgb, var(--micro-coral) 10%, transparent);
  }
  .dh-table tbody tr.is-alert:hover {
    background: var(--micro-coral-sub); /* fallback */
    background: color-mix(in srgb, var(--micro-coral) 15%, var(--bg-card-h));
  }

  .dh-table tbody tr.is-muted { opacity: 0.5; }
  .dh-table tbody tr.is-muted:hover { opacity: 0.75; }

  .dh-table tbody tr.is-new {
    background: var(--fx-sub);
    box-shadow: inset 3px 0 0 var(--fx);
  }
  .dh-table tbody tr.is-new:hover {
    background: color-mix(in srgb, var(--fx-sub) 80%, var(--bg-card-h));
  }

  /* ── TFOOT ─────────────────────────────────────────────────── */
  .dh-table tfoot tr {
    background: var(--bg-elevated);
    border-top: 1px solid var(--border-s);
  }
  .dh-table tfoot td,
  .dh-table tfoot th {
    padding: var(--sp-3) var(--sp-4);
    font-family: var(--font-mono); font-size: 0.875rem;
    font-weight: 600; color: var(--fg);
  }
  .dh-table tfoot td.num { text-align: right; color: var(--fg); }

  /* ── INLINE SHARE BAR ──────────────────────────────────────── */
  .share-bar-wrap {
    display: flex; align-items: center; gap: var(--sp-3);
  }
  .share-bar-track {
    flex: 1; height: 4px; background: var(--bg-elevated);
    border-radius: 2px; overflow: hidden; min-width: 60px;
  }
  .share-bar-fill {
    height: 100%; border-radius: 2px;
    background: var(--accent-fill);
    transition: width 0.4s ease;
  }
  .share-pct {
    font-family: var(--font-mono); font-size: 0.6875rem; color: var(--fg-3);
    width: 3.5em; text-align: right; flex-shrink: 0;
  }

  /* ── CELL BADGE ────────────────────────────────────────────── */
  .cell-badge {
    display: inline-flex; align-items: center;
    border-radius: var(--r-pill); padding: 2px 8px;
    font-family: var(--font-mono); font-size: 0.6875rem; font-weight: 500;
    line-height: 1.4; white-space: nowrap;
    background: var(--bg-elevated); color: var(--fg-3);
    border: 1px solid var(--border-s);
  }
  .cell-badge.is-success { background: var(--mint-sub); color: var(--mint); border-color: color-mix(in srgb, var(--mint) 30%, transparent); }
  .cell-badge.is-warn    { background: var(--micro-amber-sub); color: var(--micro-amber-text); border-color: color-mix(in srgb, var(--micro-amber) 30%, transparent); }
  .cell-badge.is-alert   { background: var(--micro-coral-sub); color: var(--micro-coral-text); border-color: color-mix(in srgb, var(--micro-coral) 30%, transparent); }
  .cell-badge.is-accent  { background: var(--accent-sub); color: var(--accent-text); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }

  /* ── ROW ACTIONS ───────────────────────────────────────────── */
  .cell-actions {
    width: 40px; text-align: right;
    opacity: 0;
    transition: opacity var(--ease-fast);
  }
  .dh-table tbody tr:hover .cell-actions { opacity: 1; }
  .row-action {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: var(--r-sm);
    color: var(--fg-3); cursor: pointer;
    transition: color var(--ease-fast), background var(--ease-fast);
    text-decoration: none;
  }
  .row-action:hover { color: var(--fg); background: var(--bg-elevated); }
  .row-action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .row-action svg { width: 14px; height: 14px; }

  /* ── VARIANTS ──────────────────────────────────────────────── */
  /* Dense */
  .dh-table.is-dense td,
  .dh-table.is-dense th {
    padding: var(--sp-2) var(--sp-3);
  }

  /* Bordered (column dividers) */
  .dh-table.is-bordered td:not(:last-child),
  .dh-table.is-bordered th:not(:last-child) {
    border-right: 1px solid var(--border);
  }

  /* Striped */
  .dh-table.is-striped tbody tr:nth-child(even) {
    background: var(--bg-subtle);
  }
  .dh-table.is-striped tbody tr:nth-child(even):hover {
    background: var(--bg-card-h);
  }

  /* Live region for sort announcements */
  .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;
  }
