/*
 * School Content – tables (DOM contract: AGENT_TASKS.md §2).
 *
 * Everything is scoped to .scc-table-wrap / .scc-table (no global table selectors).
 *
 * Custom properties
 *   Element settings (set inline on the wrapper, all validated server side):
 *     --scc-head-bg --scc-head-color --scc-body-bg --scc-body-color --scc-stripe-bg --scc-stripe-opacity
 *     --scc-border-color --scc-border-width --scc-border-style --scc-cell-padding --scc-radius
 *     --scc-font-size --scc-font-weight --scc-line-height --scc-highlight-bg
 *     --scc-table-width --scc-table-max-width
 *   Design presets (set by the .scc-table--<preset> classes, fallback when no element setting):
 *     --scc-preset-*
 *   Effective values (computed on .scc-table): --scc-x-*
 *
 * The presets use their own variable names on purpose: a preset class sits on the <table>, below
 * the wrapper that carries the element settings, so same-named variables would override them.
 */

/* ------------------------------------------------------------------ wrapper */
.scc-table-wrap {
  box-sizing: border-box;
  max-width: 100%;
  margin: 1.25rem 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.scc-table-wrap *,
.scc-table-wrap *::before,
.scc-table-wrap *::after {
  box-sizing: border-box;
}

.scc-table-wrap:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 2px;
}

/* Room for the drop shadow (the wrapper clips it otherwise). */
.scc-table-wrap--shadow {
  padding: 2px 6px 10px;
}

/* ------------------------------------------------------------------ table + classic defaults */
.scc-table {
  --scc-preset-head-bg: #e5e7eb;
  --scc-preset-head-color: #111827;
  --scc-preset-body-bg: #fff;
  --scc-preset-body-color: #111827;
  --scc-preset-stripe: #f3f4f6;
  --scc-preset-hover: #e0e7ff;
  --scc-preset-highlight: #fef3c7;
  --scc-preset-border: #9ca3af;
  --scc-preset-bw: 1px;
  --scc-preset-radius: 0px;
  --scc-preset-pad: 0.85rem;
  --scc-preset-fs: 1em;
  --scc-preset-lh: 1.45;
  --scc-preset-shade: rgba(0, 0, 0, 0.06);
  --scc-vline: 1;
  --scc-hline: 1;

  --scc-x-head-bg: var(--scc-head-bg, var(--scc-preset-head-bg));
  --scc-x-head-color: var(--scc-head-color, var(--scc-preset-head-color));
  --scc-x-body-bg: var(--scc-body-bg, var(--scc-preset-body-bg));
  --scc-x-body-color: var(--scc-body-color, var(--scc-preset-body-color));
  --scc-x-stripe: var(--scc-stripe-bg, var(--scc-preset-stripe));
  --scc-x-highlight: var(--scc-highlight-bg, var(--scc-preset-highlight));
  --scc-x-bc: var(--scc-border-color, var(--scc-preset-border));
  --scc-x-bs: var(--scc-border-style, solid);
  --scc-x-bw: var(--scc-border-width, var(--scc-preset-bw));
  --scc-x-pad: var(--scc-cell-padding, var(--scc-preset-pad));

  width: var(--scc-table-width, 100%);
  max-width: var(--scc-table-max-width, none);
  margin: 0;
  border-collapse: separate;
  border-spacing: 0;
  border-style: var(--scc-x-bs);
  border-color: var(--scc-x-bc);
  border-width: 0;
  border-block-start-width: calc(var(--scc-x-bw) * var(--scc-hline));
  border-inline-start-width: calc(var(--scc-x-bw) * var(--scc-vline));
  border-radius: var(--scc-radius, var(--scc-preset-radius));
  overflow: hidden;
  background-color: var(--scc-x-body-bg);
  color: var(--scc-x-body-color);
  font-size: var(--scc-font-size, var(--scc-preset-fs));
  line-height: var(--scc-line-height, var(--scc-preset-lh));
  text-align: start;
}

.scc-table caption {
  padding: 0.5rem 0.25rem;
  caption-side: top;
  color: inherit;
  font-weight: 600;
  text-align: start;
}

.scc-table--caption-bottom caption {
  caption-side: bottom;
}

.scc-table th,
.scc-table td {
  padding: calc(var(--scc-x-pad) * 0.7) var(--scc-x-pad);
  border-style: var(--scc-x-bs);
  border-color: var(--scc-x-bc);
  border-width: 0;
  border-block-end-width: calc(var(--scc-x-bw) * var(--scc-hline));
  border-inline-end-width: calc(var(--scc-x-bw) * var(--scc-vline));
  background-color: transparent;
  color: var(--scc-x-body-color);
  font-weight: var(--scc-font-weight, normal);
  text-align: start;
  vertical-align: top;
  overflow-wrap: break-word;
}

.scc-table thead th {
  background-color: var(--scc-x-head-bg);
  color: var(--scc-x-head-color);
  font-weight: var(--scc-font-weight, 600);
  vertical-align: bottom;
}

.scc-table tbody th {
  font-weight: var(--scc-font-weight, 600);
}

.scc-table thead a {
  color: inherit;
  text-decoration: underline;
}

/* Alignment of columns (physical on purpose: authors think in left / right) */
.scc-table .scc-align-left {
  text-align: left;
}

.scc-table .scc-align-center {
  text-align: center;
}

.scc-table .scc-align-right {
  text-align: right;
}

/* Shaded columns: a translucent layer works on any background */
.scc-table .scc-col--shaded {
  background-image: linear-gradient(var(--scc-preset-shade), var(--scc-preset-shade));
}

/* Table position when it is narrower than the wrapper */
.scc-table--align-center {
  margin-inline: auto;
}

.scc-table--align-right {
  margin-inline-start: auto;
}

/* ------------------------------------------------------------------ modifiers */
.scc-table--striped tbody tr:nth-child(even) > * {
  background-color: var(--scc-x-stripe);
}

@supports (color: color-mix(in srgb, red 50%, transparent)) {
  .scc-table--striped tbody tr:nth-child(even) > * {
    background-color: color-mix(in srgb, var(--scc-x-stripe) calc(var(--scc-stripe-opacity, 1) * 100%), transparent);
  }
}

.scc-table--hover tbody tr:hover > * {
  background-color: var(--scc-preset-hover);
}

.scc-table tbody tr.scc-row--highlight > * {
  background-color: var(--scc-x-highlight);
}

.scc-table--shadow {
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.28);
}

/* Borders: horizontal lines only / all lines / none */
.scc-table--horizontal {
  --scc-vline: 0;
  --scc-hline: 1;
}

.scc-table--bordered {
  --scc-vline: 1;
  --scc-hline: 1;
}

.scc-table--borderless {
  --scc-vline: 0;
  --scc-hline: 0;
}

/* ------------------------------------------------------------------ presets */
/* classic: the defaults above */

.scc-table--minimal {
  --scc-preset-head-bg: transparent;
  --scc-preset-head-color: currentcolor;
  --scc-preset-body-bg: transparent;
  --scc-preset-body-color: currentcolor;
  --scc-preset-stripe: #f3f4f6;
  --scc-preset-hover: #f3f4f6;
  --scc-preset-highlight: #fef9c3;
  --scc-preset-border: #d1d5db;
  --scc-vline: 0;
}

.scc-table--minimal thead th {
  border-block-end-width: calc(var(--scc-x-bw) * 2 * var(--scc-hline));
}

.scc-table--blue {
  --scc-preset-head-bg: #1e40af;
  --scc-preset-head-color: #fff;
  --scc-preset-stripe: #eff6ff;
  --scc-preset-hover: #dbeafe;
  --scc-preset-highlight: #fde68a;
  --scc-preset-border: #93c5fd;
}

.scc-table--modern {
  --scc-preset-head-bg: #0f766e;
  --scc-preset-head-color: #fff;
  --scc-preset-stripe: #f0fdfa;
  --scc-preset-hover: #ccfbf1;
  --scc-preset-highlight: #fef3c7;
  --scc-preset-border: #d1d5db;
  --scc-preset-radius: 10px;
  --scc-preset-pad: 1rem;
  --scc-vline: 0;
}

.scc-table--striped {
  --scc-preset-border: #d1d5db;
}

.scc-table--compact {
  --scc-preset-pad: 0.5rem;
  --scc-preset-fs: 0.875rem;
  --scc-preset-lh: 1.35;
}

.scc-table--dark {
  --scc-preset-head-bg: #374151;
  --scc-preset-head-color: #fff;
  --scc-preset-body-bg: #1f2937;
  --scc-preset-body-color: #f3f4f6;
  --scc-preset-stripe: #273244;
  --scc-preset-hover: #374151;
  --scc-preset-highlight: #854d0e;
  --scc-preset-border: #4b5563;
  --scc-preset-shade: rgba(255, 255, 255, 0.07);
}

.scc-table--dark a {
  color: #93c5fd;
}

.scc-table--dark thead a {
  color: inherit;
}

/* ------------------------------------------------------------------ footnote */
.scc-table__footnote {
  margin: 0.5rem 0.25rem 0;
  font-size: 0.875rem;
  line-height: 1.4;
}

/* ------------------------------------------------------------------ existing article tables (TableEnhancer) */
.scc-table-wrap--existing .scc-table {
  width: 100%;
  max-width: 100%;
}

.scc-table-wrap--existing .scc-table th,
.scc-table-wrap--existing .scc-table td {
  height: auto;
}

/* ------------------------------------------------------------------ small screens */
@media (max-width: 639.98px) {
  /* scroll: columns keep a readable width, the focusable wrapper scrolls */
  .scc-table-wrap--scroll .scc-table th,
  .scc-table-wrap--scroll .scc-table td {
    min-width: 6.5rem;
  }

  .scc-table-wrap--compact .scc-table th,
  .scc-table-wrap--compact .scc-table td {
    padding: 0.3rem 0.45rem;
    font-size: 0.85rem;
    line-height: 1.3;
  }

  /* stack: every row becomes a block, cells show their column heading (data-label) */
  .scc-table-wrap--stack .scc-table,
  .scc-table-wrap--stack .scc-table tbody,
  .scc-table-wrap--stack .scc-table tr,
  .scc-table-wrap--stack .scc-table td,
  .scc-table-wrap--stack .scc-table th {
    display: block;
    width: auto;
    max-width: 100%;
  }

  .scc-table-wrap--stack .scc-table {
    border-width: 0;
    border-radius: 0;
    background: transparent;
  }

  .scc-table-wrap--stack .scc-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
  }

  .scc-table-wrap--stack .scc-table tbody tr {
    margin-block-end: 0.75rem;
    border: var(--scc-x-bw) var(--scc-x-bs) var(--scc-x-bc);
    border-radius: var(--scc-radius, var(--scc-preset-radius));
    overflow: hidden;
    background-color: var(--scc-x-body-bg);
  }

  .scc-table-wrap--stack .scc-table td,
  .scc-table-wrap--stack .scc-table th {
    border-width: 0;
    border-block-end: var(--scc-x-bw) var(--scc-x-bs) var(--scc-x-bc);
    text-align: start;
  }

  .scc-table-wrap--stack .scc-table tr > :last-child {
    border-block-end-width: 0;
  }

  .scc-table-wrap--stack .scc-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-block-end: 0.15rem;
    font-size: 0.8em;
    font-weight: 700;
  }
}

@media (forced-colors: active) {
  .scc-table,
  .scc-table th,
  .scc-table td {
    border-color: CanvasText;
  }
}

@media print {
  .scc-table-wrap {
    overflow: visible;
  }
}

/* Lists inside cells (bulleted / numbered entries). Element + class selectors: article templates
   style lists too (Cassiopeia clips "ul" in articles with overflow: hidden). */
.scc-table td ul,
.scc-table td ol,
.scc-table th ul,
.scc-table th ol {
  margin: 0;
  padding-inline-start: 1.25em;
  overflow: visible;
  text-align: start;
}

.scc-table td li,
.scc-table th li {
  margin: 0;
}

.scc-table td li + li,
.scc-table th li + li,
.scc-table td li > ul,
.scc-table td li > ol {
  margin-block-start: 0.2em;
}
