/**
 * Data Table look: themes, cell spacing, stripes, thumbnails, phone layout.
 *
 * ONE stylesheet for both places a table appears, so the editor shows what
 * visitors will see:
 *   - the site:   .para--table  (paragraph--table.html.twig)
 *   - the editor: .ck-content.mvsd-table-editor  (mvsd-table-tools.js marks
 *                 the CKEditor editing root of the table_only format)
 * Settings are classes on the <table> written by the editor toolbar:
 *   mvsd-theme-{school|info|tip|important}  none = Neutral
 *   mvsd-space-{tight|wide}                 none = Normal
 *   mvsd-phone-stack                        none = scroll sideways
 *   mvsd-no-stripes, mvsd-sticky
 * "Phone" is measured on the table's own box (container query), so a table in
 * a narrow column adapts too, and the editor's Phone view triggers the same
 * rules as a real phone.
 * Loaded before the theme's paragraphs.css, so selectors carry the extra
 * class weight on purpose (they must beat .para--table td etc.).
 * 2026-11-22, Data Table editor Phase 2.
 */

/* ── Tokens: Neutral is the default for a table with no theme class ──── */
:is(.ck-content.mvsd-table-editor .table, .para--table) table {
  --tbl-pad-y: 0.75rem;
  --tbl-pad-x: 1rem;
  --tbl-line: var(--color-border, #e0e0e0);
}
.ck-content.mvsd-table-editor .table table:not([class*="mvsd-theme-"]),
.para--table:not(.para--bg--subtle-gray, .para--bg--brand-light, .para--bg--accent-light, .para--bg--sky-light, .para--bg--sand-light, .para--bg--lilac-light) table:not([class*="mvsd-theme-"]) {
  --tbl-header-bg: #e8ebef;
  --tbl-header-fg: #1f2933;
  --tbl-header-divider: rgba(0, 0, 0, 0.22);
  --tbl-stripe: #f6f7f9;
}
:is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-theme-school {
  --tbl-header-bg: color-mix(in srgb, var(--color-primary, #01491f) 12%, #ffffff);
  --tbl-header-fg: var(--color-primary-deep, var(--color-primary, #01491f));
  --tbl-header-divider: color-mix(in srgb, var(--color-primary, #01491f) 42%, transparent);
  --tbl-stripe: rgba(0, 0, 0, 0.025);
}
:is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-theme-info {
  --tbl-header-bg: #dbe7fc;
  --tbl-header-fg: #173a7a;
  --tbl-header-divider: rgba(37, 99, 235, 0.45);
  --tbl-stripe: #f4f8fe;
}
:is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-theme-tip {
  --tbl-header-bg: #d7f0df;
  --tbl-header-fg: #14532d;
  --tbl-header-divider: rgba(22, 163, 74, 0.45);
  --tbl-stripe: #f3faf5;
}
:is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-theme-important {
  --tbl-header-bg: #fbe9b7;
  --tbl-header-fg: #5f3608;
  --tbl-header-divider: rgba(202, 138, 4, 0.55);
  --tbl-stripe: #fffaeb;
}

/* ── Spacing ──────────────────────────────────────────────────────────── */
:is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-space-tight {
  --tbl-pad-y: 0.5rem;
  --tbl-pad-x: 0.75rem;
  font-size: 0.92em;
}
:is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-space-wide {
  --tbl-pad-y: 1.1rem;
  --tbl-pad-x: 1.4rem;
}

/* ── Cells ────────────────────────────────────────────────────────────── */
:is(.ck-content.mvsd-table-editor .table, .para--table) table :is(td, th) {
  padding: var(--tbl-pad-y) var(--tbl-pad-x);
}
:is(.ck-content.mvsd-table-editor .table, .para--table) table :is(thead th, tbody th) {
  background: var(--tbl-header-bg);
  color: var(--tbl-header-fg);
  font-weight: 600;
  /* Headers may wrap: a long column name no longer forces the table wider
     than the screen. */
  white-space: normal;
}
:is(.ck-content.mvsd-table-editor .table, .para--table) table thead th {
  border-bottom: 2px solid var(--tbl-header-divider);
}
:is(.ck-content.mvsd-table-editor .table, .para--table) table tbody th {
  border-right: 2px solid var(--tbl-header-divider);
}

/* Cancel the theme's older hover background (paragraphs.css "Hover row
   highlight"): it only reached the plain rows. The hover is drawn below
   instead. Site only; outweighs the theme rule but not the stripe rule. */
:is(.para--table .para-table__scroll, .para--table) table tbody tr:hover > td {
  background: transparent;
}

/* Striped rows (default) and the "Striped rows" switch turned off. */
:is(.ck-content.mvsd-table-editor .table, .para--table) table tbody tr:nth-child(even) > td {
  background: var(--tbl-stripe);
}
:is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-no-stripes tbody tr:nth-child(even) > td {
  background: transparent;
}
/* Row hover on the site only (it would flicker while editing). Drawn as an
   inset shadow so it sits ON TOP of the stripe (or tint) instead of competing
   with it: a background here loses to the heavier stripe selector above, so
   the hover only ever showed on the plain rows. The colour comes from the
   theme's header, so it reads on striped and plain rows alike. */
.para--table table tbody tr:hover > td {
  box-shadow: inset 0 0 0 100vmax color-mix(in srgb, var(--tbl-header-fg) 7%, transparent);
}
/* A row header (first column) darkens with its row, so the whole row lights
   up together and the header stays a step darker than the cells. */
.para--table table tbody tr:hover > th {
  box-shadow: inset 0 0 0 100vmax color-mix(in srgb, var(--tbl-header-fg) 13%, transparent);
}

/* Thumbnails: an image in a cell is never larger than 128 x 128. A size set
   in the content (width/height attributes, e.g. the handbook's 40px illness
   icons) is kept; only larger images shrink. No `width: auto` here: it threw
   the set size away and showed each icon at its file size. */
:is(.ck-content.mvsd-table-editor .table, .para--table) table :is(td, th) img {
  max-width: 128px;
  max-height: 128px;
  height: auto;
  object-fit: contain;
}

/* ── Phone width: one step tighter, and optional stacked cards ────────── */
.para--table .para-table__scroll,
.ck-content.mvsd-table-editor {
  container: mvsdtbl / inline-size;
}
@container mvsdtbl (max-width: 520px) {
  :is(.ck-content.mvsd-table-editor .table, .para--table) table {
    --tbl-pad-y: 0.5rem;
    --tbl-pad-x: 0.75rem;
  }
  :is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-space-tight {
    --tbl-pad-y: 0.3rem;
    --tbl-pad-x: 0.5rem;
  }
  :is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-space-wide {
    --tbl-pad-y: 0.75rem;
    --tbl-pad-x: 1rem;
  }

  /* Stack rows as cards. The site adds ARIA table roles in this mode
     (mvsd_helpers), so screen readers still hear a table. */
  :is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-phone-stack,
  :is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-phone-stack > :is(thead, tbody, tfoot),
  :is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-phone-stack tr,
  :is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-phone-stack :is(td, th) {
    display: block;
    width: auto;
    min-width: 0;
  }
  :is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-phone-stack {
    border: 0;
  }
  :is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-phone-stack tr {
    border: 1px solid var(--tbl-line);
    border-radius: 6px;
    margin: 0 0 0.75rem;
    overflow: hidden;
    background: #fff;
  }
  :is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-phone-stack :is(td, th) {
    border: 0;
    border-bottom: 1px solid var(--tbl-line);
  }
  :is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-phone-stack tr > :last-child {
    border-bottom: 0;
  }
  :is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-phone-stack tbody tr:nth-child(even) > td {
    background: transparent;
  }
  :is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-phone-stack td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 0.15rem;
    font-size: 0.75rem;
    font-weight: 700;
    /* The header colour, so each label reads as the column name it is. */
    color: var(--tbl-header-fg);
  }
  /* The header row is read from each card's labels instead (site and the
     editor's Phone view alike). It stays in the markup for screen readers,
     and is edited in Desktop view. */
  :is(.ck-content.mvsd-table-editor .table, .para--table) table.mvsd-phone-stack > thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}
@media (max-width: 600px) {
  .para--table--stack .para-table__scroll {
    border: 0;
  }
}

/* ══ Editor only ═════════════════════════════════════════════════════════ */

/* The table at full width with the site's typography, scrolling in its own
   box when it's wider than the field (instead of stretching the form). */
.ck-content.mvsd-table-editor .table {
  display: block;
  width: 100%;
  margin: 0 0 1rem;
  overflow-x: auto;
  float: none;
}
.ck-content.mvsd-table-editor .table table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--tbl-line);
  font-size: 0.875rem;
  line-height: 1.5;
}
.ck-content.mvsd-table-editor .table table :is(td, th) {
  /* Claro gives every td a fixed 4rem height; tables on the site have none. */
  height: auto;
  min-width: 4em;
  border: 0;
  border-bottom: 1px solid var(--tbl-line);
  vertical-align: top;
  text-align: left;
}
.ck-content.mvsd-table-editor .table table tbody th {
  border-right: 2px solid var(--tbl-header-divider);
}
.ck-content.mvsd-table-editor .table table thead th {
  border-bottom: 2px solid var(--tbl-header-divider);
}

/* Header cells say so while editing (never saved, never on the site). */
.ck-content.mvsd-table-editor .table table :is(thead th, tbody th)::before {
  display: block;
  width: max-content;
  margin-bottom: 3px;
  padding: 0 4px;
  border: 1px solid #a9bdf0;
  border-radius: 3px;
  background: #fff;
  color: #3b4b7a;
  font: 700 10px/1.5 system-ui, sans-serif;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.ck-content.mvsd-table-editor .table table thead th::before {
  content: "Column header";
}
.ck-content.mvsd-table-editor .table table tbody th::before {
  content: "Row header";
}

/* Phone view: the editing area at phone width inside a device frame. */
.ck-editor__main:has(> .mvsd-view-phone) {
  padding: 20px 12px;
  background: #e4e6ee;
}
.ck.ck-editor__main > .ck-editor__editable.mvsd-table-editor.mvsd-view-phone {
  max-width: 375px;
  margin-inline: auto;
  border-radius: 18px;
  outline: 8px solid #2b2c33;
  outline-offset: 0;
}

/* Toolbar: on/off switches read as checkboxes. */
.ck.ck-button.mvsd-tt-toggle::before {
  content: "";
  display: inline-block;
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  border: 1px solid #6b6c73;
  border-radius: 3px;
  background: #fff;
}
.ck.ck-button.mvsd-tt-toggle.ck-on::before {
  border-color: #003ecc;
  background: #003ecc url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 12px no-repeat;
}
.ck.ck-button.mvsd-tt-toggle.ck-on,
.ck.ck-button.mvsd-tt-view.ck-on {
  background: #dfe8ff;
  color: #102a6b;
}
.ck.ck-button.mvsd-tt-view.ck-on {
  font-weight: 600;
}
/* Theme / Spacing / On phones show their whole current value. */
.ck.ck-dropdown.mvsd-tt-dd .ck-dropdown__button .ck-button__label {
  width: auto !important;
  overflow: visible;
}
