@layer components {
  .cx-table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--cx-border);
    border-radius: var(--cx-radius-lg);
    background: var(--cx-surface);
  }

  .cx-table th,
  .cx-table td {
    padding: .85rem 1rem;
    border-block-end: 1px solid var(--cx-border);
    text-align: start;
    white-space: nowrap;
  }

  .cx-table th { background: var(--cx-surface-strong); font-weight: 900; }
  .cx-table tr:last-child td { border-block-end: 0; }
}

@layer components {
  .cx-table { width:100%; border-collapse:collapse; }
  .cx-table-dense th, .cx-table-dense td { padding:.55rem .7rem; }
  .cx-table-caption { padding:.85rem 1rem; border-block-end:1px solid var(--cx-border); color:var(--cx-muted); font-weight:800; }
  .cx-table-key-value th:first-child, .cx-table-key-value td:first-child { color:var(--cx-muted); font-weight:900; }
  .cx-pagination { display:flex; align-items:center; justify-content:flex-end; gap:.75rem; flex-wrap:wrap; padding:1rem 0; }
  .cx-pagination-size { grid-template-columns:auto minmax(88px,120px); align-items:center; }
  .cx-pagination-size .cx-label { font-size:.8rem; color:var(--cx-muted); }
}

@layer components {
  .cx-table-wrap { overflow:auto; scrollbar-gutter:stable both-edges; }
  .cx-table thead th { position:sticky; top:0; z-index:1; box-shadow:0 1px 0 var(--cx-border); }
  .cx-table tbody tr { transition:background var(--cx-transition), color var(--cx-transition), box-shadow var(--cx-transition), transform var(--cx-transition); }
  .cx-table tbody tr:hover { background:var(--cx-row-hover-bg); box-shadow:inset 4px 0 0 var(--cx-row-hover-border); }
  .cx-table tbody tr:hover td { color:var(--cx-text); }
  .cx-table tbody tr:hover td strong, .cx-table tbody tr:hover .cx-number, .cx-table tbody tr:hover .cx-money { color:inherit; font-weight:950; }
  .cx-table tbody tr[aria-selected="true"], .cx-table tbody tr.is-selected { background:var(--cx-row-selected-bg); box-shadow:inset 5px 0 0 var(--cx-row-selected-border); }
  .cx-table tbody tr[data-clickable="true"], .cx-table tbody tr.cx-row-clickable { cursor:pointer; }
  .cx-table-actions { display:inline-flex; align-items:center; gap:.4rem; opacity:.78; transition:opacity var(--cx-transition), transform var(--cx-transition); }
  .cx-table tr:hover .cx-table-actions, .cx-table tr.is-selected .cx-table-actions, .cx-table tr[aria-selected="true"] .cx-table-actions { opacity:1; transform:translateY(-1px); }
  .cx-table .cx-num, .cx-table .cx-money, .cx-table .cx-number { font-variant-numeric:tabular-nums; font-weight:850; }
  .cx-table .cx-cell-muted { color:var(--cx-muted); }
  .cx-table [data-semantic="revenue"] { color:var(--cx-sem-revenue); }
  .cx-table [data-semantic="profit"] { color:var(--cx-sem-profit); }
  .cx-table [data-semantic="loss"], .cx-table [data-semantic="danger"] { color:var(--cx-sem-loss); }
  .cx-table [data-semantic="cost"] { color:var(--cx-sem-cost); }
  .cx-table [data-semantic="expense"] { color:var(--cx-sem-expense); }
  .cx-table [data-semantic="inventory"] { color:var(--cx-sem-inventory); }
  .cx-table [data-semantic="production"] { color:var(--cx-sem-production); }
  .cx-table [data-semantic="forecast"] { color:var(--cx-sem-forecast); }
  .cx-table [data-semantic="settlement"] { color:var(--cx-sem-settlement); }
  .cx-table [data-semantic="pending"] { color:var(--cx-sem-pending); }
  .cx-table tr[data-row-semantic="revenue"]:hover { background:var(--cx-sem-revenue-soft); box-shadow:inset 4px 0 0 var(--cx-sem-revenue); }
  .cx-table tr[data-row-semantic="profit"]:hover { background:var(--cx-sem-profit-soft); box-shadow:inset 4px 0 0 var(--cx-sem-profit); }
  .cx-table tr[data-row-semantic="loss"]:hover, .cx-table tr[data-row-semantic="danger"]:hover { background:var(--cx-sem-loss-soft); box-shadow:inset 4px 0 0 var(--cx-sem-loss); }
  .cx-table tr[data-row-semantic="cost"]:hover { background:var(--cx-sem-cost-soft); box-shadow:inset 4px 0 0 var(--cx-sem-cost); }
  .cx-table tr[data-row-semantic="expense"]:hover { background:var(--cx-sem-expense-soft); box-shadow:inset 4px 0 0 var(--cx-sem-expense); }
  .cx-table tr[data-row-semantic="inventory"]:hover { background:var(--cx-sem-inventory-soft); box-shadow:inset 4px 0 0 var(--cx-sem-inventory); }
  .cx-table tr[data-row-semantic="production"]:hover { background:var(--cx-sem-production-soft); box-shadow:inset 4px 0 0 var(--cx-sem-production); }
  .cx-table tr[data-row-semantic="forecast"]:hover { background:var(--cx-sem-forecast-soft); box-shadow:inset 4px 0 0 var(--cx-sem-forecast); }
  .cx-table tr[data-row-semantic="settlement"]:hover { background:var(--cx-sem-settlement-soft); box-shadow:inset 4px 0 0 var(--cx-sem-settlement); }
  .cx-table tr[data-row-semantic="pending"]:hover { background:var(--cx-sem-pending-soft); box-shadow:inset 4px 0 0 var(--cx-sem-pending); }
  .cx-table-empty, .cx-table-error, .cx-table-loading { padding:var(--cx-space-6); text-align:center; color:var(--cx-muted); font-weight:850; }
  .cx-pagination { border-block-start:1px solid var(--cx-border); padding:var(--cx-space-4); background:rgba(255,255,255,.65); }
  .cx-pagination-info { color:var(--cx-muted); font-weight:850; margin-inline-end:auto; }
  .cx-density-comfortable .cx-table th, .cx-density-comfortable .cx-table td { padding:1rem 1.1rem; }
  .cx-density-compact .cx-table th, .cx-density-compact .cx-table td { padding:.48rem .62rem; font-size:.88rem; }
  @media (max-width:720px) {
    .cx-table-wrap { border-radius:var(--cx-radius-md); }
    .cx-table th, .cx-table td { padding:.7rem .75rem; }
    .cx-pagination { justify-content:center; }
    .cx-pagination-info { width:100%; text-align:center; margin:0; }
  }
}


/* Phase43B — Global Table Contract Enforcement
   Single enforced owner for Smart Table alignment, totals, note buttons, and dark/light readability. */
@layer components {
  .cx-smart-table {
    min-inline-size: 860px;
  }

  .cx-smart-table th,
  .cx-smart-table td {
    box-sizing: border-box;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
    background-clip: padding-box;
    line-height: 1.45;
  }

  .cx-smart-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
  }

  .cx-smart-table col.cx-col-w-time { width: 12.5rem; }
  .cx-smart-table col.cx-col-w-notes { width: 11rem; }
  .cx-smart-table col.cx-col-w-risk-main { width: 13.5rem; }
  .cx-smart-table col.cx-col-w-timeline-main { width: 15rem; }
  .cx-smart-table col.cx-col-w-statement-label { width: 16rem; }
  .cx-smart-table col.cx-col-w-statement { width: 10.5rem; }

  .cx-table-preset-risk .cx-smart-table,
  .cx-table.cx-table-preset-risk { min-inline-size: 980px; }
  .cx-table-preset-financial .cx-smart-table,
  .cx-table.cx-table-preset-financial { min-inline-size: 980px; }
  .cx-table-preset-statement .cx-smart-table,
  .cx-table.cx-table-preset-statement { min-inline-size: 900px; }
  .cx-table-preset-timeline .cx-smart-table,
  .cx-table.cx-table-preset-timeline { min-inline-size: 980px; }

  .cx-smart-table th[data-col-type="money"],
  .cx-smart-table th[data-col-type="number"],
  .cx-smart-table th[data-col-type="qty"],
  .cx-smart-table th[data-col-type="percent"],
  .cx-smart-table td[data-col-type="money"],
  .cx-smart-table td[data-col-type="number"],
  .cx-smart-table td[data-col-type="qty"],
  .cx-smart-table td[data-col-type="percent"] {
    text-align: end;
    direction: rtl;
  }

  .cx-smart-table th[data-col-type="main"],
  .cx-smart-table td[data-col-type="main"],
  .cx-smart-table th[data-col-type="time"],
  .cx-smart-table td[data-col-type="time"],
  .cx-smart-table th[data-col-type="note"],
  .cx-smart-table td[data-col-type="note"] {
    text-align: start;
    direction: rtl;
  }

  .cx-smart-table th[data-col-type="status"],
  .cx-smart-table td[data-col-type="status"],
  .cx-smart-table th[data-col-type="risk"],
  .cx-smart-table td[data-col-type="risk"] {
    text-align: center;
  }

  .cx-smart-table .cx-money,
  .cx-smart-table .cx-percent,
  .cx-smart-table .cx-number {
    display: inline-block;
    inline-size: 100%;
    direction: ltr;
    unicode-bidi: isolate;
    text-align: end;
    font-weight: 1000;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  .cx-smart-table .cx-time-cell {
    display: inline-block;
    inline-size: 100%;
    text-align: start;
    white-space: nowrap;
    font-weight: 950;
  }

  .cx-smart-table .cx-cell-main {
    display: grid;
    gap: .12rem;
    min-width: 0;
  }
  .cx-smart-table .cx-cell-main strong,
  .cx-smart-table .cx-cell-main small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .cx-smart-table .cx-cell-main strong { color: var(--cx-text); font-weight: 1000; }
  .cx-smart-table .cx-cell-main small { color: var(--cx-muted); font-weight: 800; }

  .cx-cell-missing {
    display:inline-flex;
    padding:.18rem .5rem;
    border-radius:999px;
    background: color-mix(in srgb, var(--cx-muted) 10%, var(--cx-surface));
    color:var(--cx-muted);
    border:1px solid var(--cx-border);
    font-weight:900;
    font-size:.78rem;
    white-space: nowrap;
  }

  /* Row stripe/hover backgrounds are owned by the modern table polish block below. */
  .cx-smart-table .cx-status-pill { white-space: nowrap; }

  .cx-smart-table tfoot td,
  .cx-smart-table .cx-total-row td {
    position: sticky;
    bottom: 0;
    z-index: 1;
    background: linear-gradient(90deg,
      color-mix(in srgb, var(--cx-brand-soft) 76%, var(--cx-surface-strong)),
      color-mix(in srgb, var(--cx-surface-strong) 86%, var(--cx-brand-soft))) !important;
    border-block-start: 2px solid color-mix(in srgb, var(--cx-brand) 52%, var(--cx-border));
    border-block-end: 1px solid color-mix(in srgb, var(--cx-brand) 20%, var(--cx-border));
    color: var(--cx-text);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.32), 0 -6px 18px rgba(44,31,74,.06);
    font-weight: 1000;
  }
  .cx-smart-table .cx-total-row td:first-child strong {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .3rem .76rem;
    border-radius: 999px;
    color: var(--cx-brand-strong);
    background: color-mix(in srgb, var(--cx-brand-soft) 72%, var(--cx-surface));
    border: 1px solid color-mix(in srgb, var(--cx-brand) 25%, var(--cx-border));
  }

  .cx-smart-table td[data-col-type="note"] { white-space: normal; }
  .cx-note-button {
    max-inline-size: 100%;
    border: 1px solid color-mix(in srgb, var(--cx-brand) 22%, var(--cx-border));
    border-radius: 999px;
    background: color-mix(in srgb, var(--cx-brand-soft) 50%, var(--cx-surface));
    color: var(--cx-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .32rem .68rem;
    cursor: pointer;
    font-weight: 900;
  }
  .cx-note-button:hover,
  .cx-note-button:focus-visible {
    border-color: color-mix(in srgb, var(--cx-brand) 48%, var(--cx-border));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--cx-brand-soft) 55%, transparent);
    outline: 0;
  }
  .cx-note-button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-inline-size: 0; }
  .cx-note-button strong { color: var(--cx-brand-strong); background: var(--cx-surface); border-radius: 999px; padding: .14rem .42rem; white-space: nowrap; }

  .cx-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: .75rem;
    margin-block: .25rem 1rem;
  }
  .cx-detail-line {
    border: 1px solid var(--cx-border);
    border-radius: var(--cx-radius-lg);
    padding: .75rem .85rem;
    background: color-mix(in srgb, var(--cx-surface) 88%, var(--cx-brand-soft));
    display: grid;
    gap: .25rem;
  }
  .cx-detail-line span { color: var(--cx-muted); font-weight: 850; font-size: .82rem; }
  .cx-detail-line strong { color: var(--cx-text); font-weight: 1000; overflow: hidden; text-overflow: ellipsis; }

  /* Dark Smart Table wrapper background is owned by the modern polish block below. */
  [data-theme="dark"] .cx-smart-table thead th,
  .theme-dark .cx-smart-table thead th,
  html[data-theme="dark"] .cx-smart-table thead th {
    background: linear-gradient(180deg,
      color-mix(in srgb, var(--cx-brand-soft) 25%, var(--cx-surface-strong)),
      color-mix(in srgb, var(--cx-surface-strong) 92%, #080512));
  }
  /* Dark striped rows are owned by the modern polish block below. */
  [data-theme="dark"] .cx-smart-table tfoot td,
  [data-theme="dark"] .cx-smart-table .cx-total-row td,
  .theme-dark .cx-smart-table tfoot td,
  .theme-dark .cx-smart-table .cx-total-row td,
  html[data-theme="dark"] .cx-smart-table tfoot td,
  html[data-theme="dark"] .cx-smart-table .cx-total-row td {
    background: linear-gradient(90deg,
      color-mix(in srgb, var(--cx-brand-soft) 30%, var(--cx-surface-strong)),
      color-mix(in srgb, var(--cx-surface-strong) 86%, var(--cx-brand-soft))) !important;
    border-block-start-color: color-mix(in srgb, var(--cx-brand) 58%, var(--cx-border));
    box-shadow: inset 0 1px 0 rgba(255,255,255,.07), 0 -8px 22px rgba(0,0,0,.22);
  }
  [data-theme="dark"] .cx-note-button,
  .theme-dark .cx-note-button,
  html[data-theme="dark"] .cx-note-button {
    background: color-mix(in srgb, var(--cx-brand-soft) 18%, var(--cx-surface-strong));
    border-color: color-mix(in srgb, var(--cx-brand) 30%, var(--cx-border));
  }
}


/* Phase47H — Global table modern polish and readable zero/empty contract
   Owner: Global Smart Table. No page-level table fork. */
@layer components {
  .cx-smart-table-wrap {
    border: 1px solid color-mix(in srgb, var(--cx-brand) 14%, var(--cx-border));
    border-radius: clamp(18px, 1.6vw, 26px);
    background:
      linear-gradient(180deg, color-mix(in srgb, var(--cx-surface) 94%, var(--cx-brand-soft)), var(--cx-surface));
    box-shadow: 0 18px 42px rgba(44, 31, 74, .08);
    overflow: auto;
    scrollbar-gutter: stable both-edges;
  }

  .cx-smart-table {
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    inline-size: 100%;
  }

  .cx-smart-table-wrap.cx-table-many-columns .cx-smart-table { min-inline-size: 1280px; }
  .cx-smart-table-wrap.cx-table-balanced-columns .cx-smart-table { min-inline-size: 1040px; }
  .cx-smart-table-wrap.cx-table-few-columns .cx-smart-table { min-inline-size: 760px; }

  .cx-smart-table thead th {
    min-height: 44px;
    padding: .8rem .9rem;
    background:
      linear-gradient(180deg,
        color-mix(in srgb, var(--cx-brand-soft) 82%, var(--cx-surface-strong)),
        color-mix(in srgb, var(--cx-surface-strong) 92%, var(--cx-brand-soft)));
    color: color-mix(in srgb, var(--cx-text) 92%, var(--cx-brand-strong));
    border-block-end: 1px solid color-mix(in srgb, var(--cx-brand) 24%, var(--cx-border));
    border-inline-end: 1px solid color-mix(in srgb, var(--cx-brand) 8%, var(--cx-border));
    font-size: .78rem;
    line-height: 1.35;
    white-space: normal;
  }

  .cx-smart-table tbody td {
    padding: .82rem .9rem;
    border-block-end: 1px solid color-mix(in srgb, var(--cx-border) 78%, transparent);
    border-inline-end: 1px solid color-mix(in srgb, var(--cx-border) 40%, transparent);
    background: color-mix(in srgb, var(--cx-surface) 96%, transparent);
    color: var(--cx-text);
  }

  .cx-smart-table tbody tr:nth-child(even) td {
    background: color-mix(in srgb, var(--cx-brand-soft) 7%, var(--cx-surface));
  }

  .cx-smart-table tbody tr:hover td,
  .cx-smart-table tbody tr[aria-selected="true"] td {
    background: color-mix(in srgb, var(--cx-brand-soft) 28%, var(--cx-surface));
  }

  .cx-smart-table tbody tr:hover,
  .cx-smart-table tbody tr[aria-selected="true"] {
    box-shadow: inset 5px 0 0 color-mix(in srgb, var(--cx-brand) 72%, var(--cx-row-hover-border));
  }

  .cx-smart-table td[data-col-type="main"] { white-space: normal; }
  .cx-smart-table td:not([data-col-type="money"]):not([data-col-type="number"]):not([data-col-type="qty"]):not([data-col-type="percent"]):not([data-col-type="status"]):not([data-col-type="risk"]) {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .cx-smart-table .cx-money,
  .cx-smart-table .cx-percent,
  .cx-smart-table .cx-number {
    min-height: 1.7rem;
    padding: .08rem .1rem;
    font-size: .94rem;
    letter-spacing: .005em;
  }

  .cx-smart-table .cx-cell-main { gap: .18rem; }
  .cx-smart-table .cx-cell-main strong {
    font-size: .92rem;
    white-space: normal;
    line-height: 1.45;
  }
  .cx-smart-table .cx-cell-main small {
    white-space: normal;
    line-height: 1.35;
  }

  .cx-cell-dash {
    display: inline-flex;
    inline-size: 100%;
    align-items: center;
    justify-content: flex-end;
    color: color-mix(in srgb, var(--cx-muted) 74%, transparent);
    font-weight: 1000;
    font-size: 1rem;
  }

  .cx-smart-table .cx-status-pill {
    min-inline-size: 4.9rem;
    justify-content: center;
    box-shadow: inset 0 -1px 0 rgba(255,255,255,.25);
  }

  .cx-smart-table col.cx-col-w-xwide { width: 22rem; }
  .cx-smart-table col.cx-col-w-long { width: 18rem; }
  .cx-smart-table col.cx-col-w-action { width: 16rem; }
  .cx-smart-table col.cx-col-w-wide { width: 18rem; }
  .cx-smart-table col.cx-col-w-medium { width: 12.75rem; }
  .cx-smart-table col.cx-col-w-money { width: 12rem; }
  .cx-smart-table col.cx-col-w-percent { width: 9.75rem; }
  .cx-smart-table col.cx-col-w-small { width: 8.25rem; }
  .cx-smart-table col.cx-col-w-status { width: 10rem; }

  .cx-table-empty,
  .cx-table-error,
  .cx-table-loading {
    min-height: 132px;
    display: grid;
    place-items: center;
    padding: var(--cx-space-6);
    border-radius: var(--cx-radius-xl);
    color: var(--cx-muted);
    background: color-mix(in srgb, var(--cx-brand-soft) 10%, var(--cx-surface));
  }

  [data-theme="dark"] .cx-smart-table-wrap,
  .theme-dark .cx-smart-table-wrap,
  html[data-theme="dark"] .cx-smart-table-wrap {
    background: linear-gradient(180deg,
      color-mix(in srgb, var(--cx-surface) 88%, #161029),
      color-mix(in srgb, var(--cx-surface) 80%, #0d0917));
    box-shadow: 0 22px 54px rgba(0,0,0,.32);
  }

  [data-theme="dark"] .cx-smart-table tbody td,
  .theme-dark .cx-smart-table tbody td,
  html[data-theme="dark"] .cx-smart-table tbody td {
    background: color-mix(in srgb, var(--cx-surface) 88%, #0d0917);
    border-color: rgba(255,255,255,.055);
  }

  [data-theme="dark"] .cx-smart-table tbody tr:nth-child(even) td,
  .theme-dark .cx-smart-table tbody tr:nth-child(even) td,
  html[data-theme="dark"] .cx-smart-table tbody tr:nth-child(even) td {
    background: color-mix(in srgb, var(--cx-surface) 82%, #181026);
  }

  [data-theme="dark"] .cx-smart-table tbody tr:hover td,
  .theme-dark .cx-smart-table tbody tr:hover td,
  html[data-theme="dark"] .cx-smart-table tbody tr:hover td {
    background: color-mix(in srgb, var(--cx-brand-soft) 16%, var(--cx-surface));
  }
}

/* Phase47I — Strong financial table header and modal table contract */
@layer components {
  .cx-smart-table thead th,
  .cx-table thead th {
    font-size: .92rem;
    font-weight: 1000;
    color: var(--cx-text);
    letter-spacing: -.01em;
    line-height: 1.35;
    vertical-align: bottom;
    padding-block: .95rem .82rem;
    background:
      linear-gradient(180deg,
        color-mix(in srgb, var(--cx-brand-soft) 48%, var(--cx-surface)),
        color-mix(in srgb, var(--cx-surface-strong) 88%, var(--cx-brand-soft)));
  }

  .cx-smart-table thead th .cx-th-label,
  .cx-table thead th .cx-th-label {
    display: block;
    font-weight: 1000;
    color: var(--cx-text);
    white-space: nowrap;
  }

  .cx-smart-table thead th .cx-th-hint,
  .cx-table thead th .cx-th-hint {
    display: block;
    margin-block-start: .18rem;
    color: var(--cx-muted);
    font-size: .72rem;
    font-weight: 850;
    white-space: normal;
  }

  .cx-table-preset-modal-financial {
    --cx-table-modal-head: color-mix(in srgb, var(--cx-brand-soft) 54%, var(--cx-surface));
  }

  .cx-table-preset-modal-financial.cx-table-wrap {
    border-radius: var(--cx-radius-xl);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.32);
  }

  .cx-table-preset-modal-financial thead th {
    font-size: .95rem;
    padding-block: .95rem;
    background: var(--cx-table-modal-head);
  }

  .cx-table-preset-modal-financial tbody td {
    padding-block: .82rem;
  }

  .cx-table tbody tr[aria-selected="true"] td,
  .cx-table tbody tr.is-selected td {
    background: var(--cx-row-selected-bg);
  }
}

/* Phase47J — Centered table headers, human-readable financial tables */
@layer components {
  .cx-smart-table thead th,
  .cx-table thead th {
    text-align: center !important;
    vertical-align: middle !important;
  }

  .cx-smart-table thead th .cx-th-label,
  .cx-table thead th .cx-th-label,
  .cx-smart-table thead th .cx-th-hint,
  .cx-table thead th .cx-th-hint {
    text-align: center;
    margin-inline: auto;
  }

  .cx-smart-table th[data-col-type="money"],
  .cx-smart-table th[data-col-type="number"],
  .cx-smart-table th[data-col-type="qty"],
  .cx-smart-table th[data-col-type="percent"] {
    text-align: center !important;
  }
}
