/* ============================================================
   Base elements
   ============================================================ */

html {
  -webkit-tap-highlight-color: color-mix(in srgb, var(--ink) 16%, transparent);
}

a, button, [role="button"], input, select, textarea, summary, label {
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 400;
  line-height: 20px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

html,
.app-main {
  scroll-behavior: smooth;
}

.theme-animating,
.theme-animating * {
  transition: background-color 0.18s var(--ease),
              border-color 0.18s var(--ease),
              color 0.18s var(--ease) !important;
}

@media (prefers-reduced-motion: reduce) {
  html,
  .app-main {
    scroll-behavior: auto;
  }

  .theme-animating,
  .theme-animating * {
    transition: none !important;
  }
}

/* ---------- Typography ---------- */

h1, h2, h3, h4, h5, h6, [id] {
  scroll-margin-top: calc(var(--header-height) + var(--geist-space-4x));
}

h1,
h2,
h4,
h5,
h6 {
  color: var(--ink);
  font-family: var(--font-sans);
  font-weight: 600;
  text-wrap: balance;
}

h1 {
  font-size: 24px;
  line-height: 32px;
  letter-spacing: -0.96px;
}

h2 {
  font-size: 20px;
  line-height: 26px;
  letter-spacing: -0.4px;
}

h3 {
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 600;
  line-height: 24px;
  letter-spacing: -0.32px;
  text-wrap: balance;
}

h4 {
  font-size: 14px;
  line-height: 20px;
  letter-spacing: -0.28px;
}

h5,
h6 {
  font-size: 14px;
  line-height: 20px;
  letter-spacing: -0.28px;
}

p {
  text-wrap: pretty;
}

small {
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 18px;
}

strong,
b {
  font-weight: 600;
}

code,
kbd,
samp,
pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
}

code {
  padding: 1px var(--geist-space-2x);
  background: var(--surface-muted);
  border-radius: var(--radius-xs);
  box-shadow: var(--ring);
}

pre {
  overflow-x: auto;
  white-space: pre;
}

.mono,
.data {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--ink-subtle);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

/* ---------- Links ---------- */

a {
  color: var(--ds-blue-700);
  text-decoration-line: underline;
  text-decoration-color: var(--hairline-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--duration) var(--ease),
              text-decoration-color var(--duration) var(--ease);
}

a:hover {
  color: var(--ds-blue-700);
  text-decoration-color: currentColor;
}

/* ---------- Selection / focus / scrollbars ---------- */

::selection {
  background: var(--ds-blue-100);
}

:focus-visible {
  outline: none;
  box-shadow: var(--ds-focus-ring);
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--ds-gray-500);
  border: 2px solid transparent;
  border-radius: var(--radius-full);
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--ds-gray-600);
  background-clip: padding-box;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--ds-gray-500) transparent;
}

/* ---------- Tables ---------- */

table {
  width: 100%;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 20px;
}

.table th,
.table td {
  padding: 10px var(--geist-space-2x);
  text-align: left;
  vertical-align: middle;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 400;
  line-height: 20px;
}

.table thead th {
  background: var(--ds-gray-alpha-200); /* one step darker than the zebra stripe */
  color: var(--ink-muted);
  height: 36px;
  padding-block: var(--geist-space-2x);
  font-weight: 500;
  white-space: nowrap;
  box-shadow: inset 0 -1px var(--hairline);
}

.table tbody th {
  background: transparent;
  color: inherit;
  font-weight: 500;
}

.table td {
  color: var(--ink);
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.table tbody tr {
  content-visibility: auto;
  contain-intrinsic-size: auto 40px;
  transition: background-color var(--duration) var(--ease);
}

.table td a {
  color: var(--ds-blue-700);
  font-weight: 500;
  text-decoration: none;
}

.table td a:hover {
  color: var(--ds-blue-700);
  text-decoration: underline;
  text-decoration-color: currentColor;
  text-underline-offset: 3px;
}

.sort-link {
  display: inline-flex;
  align-items: center;
  gap: var(--geist-space);
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}

.sort-link:hover,
.sort-link.is-sorted {
  color: var(--ink);
  text-decoration: none;
}

.sort-link.is-sorted {
  font-weight: 600;
}

.sort-indicator {
  color: var(--ink-subtle);
  font-size: var(--text-xs);
}

.table tbody tr:hover td,
.table tbody tr:hover th {
  background: var(--ds-gray-alpha-200);
}

.table-compact th,
.table-compact td {
  padding: var(--geist-space-2x) var(--geist-space-3x);
}

/* Global zebra: every table. Critical even-rows skip 200; 100 vs 200 is invisible. */
table tbody tr:nth-child(even):not(.report-subtotal):not(.is-past-due):not(.is-critical):not(.is-selected) > td,
table tbody tr:nth-child(even):not(.report-subtotal):not(.is-past-due):not(.is-critical):not(.is-selected) > th {
  background: var(--ds-gray-alpha-100);
}

table tbody tr:nth-child(even):hover:not(.report-subtotal):not(.is-past-due):not(.is-critical):not(.is-selected) > td,
table tbody tr:nth-child(even):hover:not(.report-subtotal):not(.is-past-due):not(.is-critical):not(.is-selected) > th {
  background: var(--ds-gray-alpha-200);
}

.table-striped {
}

.table-flush tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr.is-selected td {
  background: var(--surface-active);
}

.text-right {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 400;
  line-height: 20px;
  font-variant-numeric: tabular-nums;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--geist-space-2x);
}

.row-actions .icon-link,
a.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--ds-gray-700);
  font-weight: 400;
  text-decoration: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color var(--duration) var(--ease),
              color var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease);
}

.icon-link svg {
  width: 16px;
  height: 16px;
}

.row-actions .icon-link:hover,
a.icon-link:hover {
  color: var(--ink);
  background: var(--surface-hover);
  box-shadow: var(--ring);
}

.row-actions .icon-link-danger,
a.icon-link-danger {
  color: var(--error);
}

.row-actions .icon-link-danger:hover,
a.icon-link-danger:hover {
  color: var(--ds-red-700);
  background: var(--error-soft);
}

.row-actions form.button_to,
.row-actions .button_to {
  display: inline-flex;
  margin: 0;
}

.row-actions button.icon-link {
  background: transparent;
}

.row-actions button.icon-link:hover {
  background: var(--surface-hover);
}

.row-actions button.icon-link-danger:hover {
  background: var(--error-soft);
}

th.text-right,
td.text-right {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.table-container {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--ds-shadow-border);
}

/* ── Dashboard-style table roles ────────────────────────────────────────────
   Cell semantics shared by every data table: medium-weight key cell, mono
   numerals, nowrap dates. Pair with the `dash-table` class for the stacked
   label/value card layout on narrow screens. */
.dash-cell-key {
  font-weight: var(--font-weight-medium);
  color: var(--ink);
  text-align: left;
  white-space: nowrap;
}

.dash-cell-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.dash-cell-due { white-space: nowrap; }

.dash-cell-link {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--hairline-strong);
  text-underline-offset: 3px;
}

.dash-cell-link:hover { color: var(--info); text-decoration-color: currentColor; }

.dash-unknown { color: var(--ink-muted); font-style: normal; }

.dash-table td.is-warning { color: var(--warning); }
.dash-table td.is-critical { color: var(--error); }

@media (max-width: 560px) {
  .dash-table,
  .dash-table tbody,
  .dash-table tr { display: block; width: 100%; }

  .dash-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .dash-table tbody tr {
    padding-block: var(--space-2);
    box-shadow: inset 0 -1px var(--hairline);
  }

  .dash-table tbody td[data-label],
  .dash-table tbody th[data-label] {
    display: grid;
    grid-template-columns: minmax(7.5rem, 40%) minmax(0, 1fr);
    align-items: baseline;
    gap: var(--space-3);
    width: 100%;
    min-height: 36px;
    padding-block: var(--space-2);
    text-align: left;
    white-space: normal;
  }

  .dash-table tbody td[data-label]::before,
  .dash-table tbody th[data-label]::before {
    content: attr(data-label);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: var(--font-weight-semibold);
    line-height: 16px;
    color: var(--ink-muted);
  }

  .dash-table .empty-state { display: block; width: 100%; }
}

/* Coarse pointers get a 44px row and link target on the shop floor. */
@media (pointer: coarse) {
  .dash-table td,
  .dash-table th { padding-block: var(--space-3); }

  .dash-table tbody th,
  .dash-table tbody td { height: 44px; }

  .dash-cell-link,
  .dash-cell-key a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
}

.table-container .table th,
.table-container .table td {
  white-space: nowrap;
}

.table-container .table .cell-grow {
  width: 100%;
  max-width: 18rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-card {
  overflow: hidden;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--ds-shadow-border);
}

.table tbody tr.is-past-due td,
.table tbody tr.is-past-due th,
.table tbody tr.is-critical td,
.table tbody tr.is-critical th {
  background: var(--ds-red-100);
  color: var(--ds-red-700);
}

.table tbody tr.is-past-due:nth-child(even) td,
.table tbody tr.is-past-due:nth-child(even) th,
.table tbody tr.is-critical:nth-child(even) td,
.table tbody tr.is-critical:nth-child(even) th {
  background: var(--ds-red-300);
}

.table tbody tr.is-past-due:hover td,
.table tbody tr.is-past-due:hover th,
.table tbody tr.is-critical:hover td,
.table tbody tr.is-critical:hover th {
  background: var(--ds-red-400);
}
