/* GTExD UI Core 1.2.7 — shared legacy-module bridge.
 * Canonical source for the visual grammar of existing GTExD plugins.
 * IMPORTANT: scoped to GTExD screens and shells, preserving application logic,
 * native WordPress admin screens and specialty visualization widgets.
 */

/* 1. Full-bleed admin canvas: remove the white gutter outside plugin wrappers. */
body.gtexd-ui-managed #wpcontent,
body.gtexd-ui-managed #wpbody,
body.gtexd-ui-managed #wpbody-content,
body.gtexd-ui-managed #wpfooter {
  background-color: var(--gtexd-color-bg) !important;
  color: var(--gtexd-color-text);
}
body.gtexd-ui-managed #wpcontent { padding-left: 0; }
body.gtexd-ui-managed #wpbody-content { box-sizing: border-box; min-height: calc(100vh - 95px); }
body.gtexd-ui-managed #wpfooter { color: var(--gtexd-color-muted); }
body.gtexd-ui-managed #wpbody-content > .wrap:not(.gtexd-vision-admin):not(.gtexd-randomizer-admin):not(.gtexd-cat) {
  box-sizing: border-box;
  width: min(100%, var(--gtexd-content-max));
  max-width: none;
  margin: 0 auto !important;
  padding: 28px 28px 44px;
  color: var(--gtexd-color-text);
  font-family: var(--gtexd-font-body);
}
body.gtexd-ui-managed .wrap.gtexd-cat {
  box-sizing: border-box;
  width: min(100%, var(--gtexd-content-max));
  max-width: none;
  margin: 0 auto !important;
  padding: 28px 28px 48px;
  background: var(--gtexd-color-bg);
  color: var(--gtexd-color-text);
  font-family: var(--gtexd-font-body);
}
body.gtexd-ui-managed .wrap.gtexd-vision-admin { margin: 0 !important; }

/* 2. Canonical GTExD panels, surfaces and headings.
 * Calendar formerly shipped light panels while Catalog shipped unrelated dark
 * shades. Both now consume the same tokens as Vision, Home and Randomizer. */
body.gtexd-ui-managed #wpcontent :is(
  .gtexd-cat__panel, .gtexd-cat__card,
  .gtexd-event-calendar-panel, .gtexd-event-calendar-round,
  .gtexd-event-calendar-recurrence, .gtexd-event-calendar-series-settings,
  .gtexd-event-calendar-external-fields, .gtexd-event-calendar-write-result,
  .gtexd-event-calendar-series-context, .gtexd-event-calendar-recurring-warning
) {
  background: var(--gtexd-color-panel) !important;
  border-color: var(--gtexd-color-line) !important;
  border-radius: 0 !important;
  color: var(--gtexd-color-text) !important;
  box-shadow: none !important;
}
body.gtexd-ui-managed #wpcontent :is(
  .gtexd-cat__panel, .gtexd-cat__card,
  .gtexd-event-calendar-panel, .gtexd-event-calendar-round
) :is(h2,h3,strong,label) { color: var(--gtexd-color-text-strong); }
body.gtexd-ui-managed #wpcontent :is(.gtexd-cat,.gtexd-event-calendar-admin)
  :is(.description,.gtexd-cat__hint,.gtexd-event-calendar-toolbar__meta,.gtexd-event-calendar-event-excerpt,
      .gtexd-event-calendar-recurrence-summary,.gtexd-event-calendar-asset-source-stack label > span) {
  color: var(--gtexd-color-muted-strong) !important;
}
body.gtexd-ui-managed #wpcontent :is(.gtexd-cat,.gtexd-event-calendar-admin) h1,
body.gtexd-ui-managed #wpcontent :is(.gtexd-cat,.gtexd-event-calendar-admin) h2 {
  color: var(--gtexd-color-text-strong) !important;
  font-family: var(--gtexd-font-display);
  font-weight: 700;
  text-transform: uppercase;
}
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-admin__header {
  margin: 0 0 26px;
  padding: 0 0 30px;
  border: 0;
  border-bottom: 1px solid var(--gtexd-color-line);
  background: transparent !important;
  color: var(--gtexd-color-text);
}
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-admin__header h1 {
  font-size: 32px;
  line-height: 1.1;
  text-transform: uppercase;
}
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-eyebrow,
body.gtexd-ui-managed #wpcontent .gtexd-cat__eyebrow { color: var(--gtexd-color-accent); }
body.gtexd-ui-managed #wpcontent .gtexd-cat__nav {
  border-bottom: 1px solid var(--gtexd-color-line);
}
body.gtexd-ui-managed #wpcontent .gtexd-cat__nav a {
  border-radius: 0;
  color: var(--gtexd-color-muted-strong);
}
body.gtexd-ui-managed #wpcontent .gtexd-cat__nav a.is-active {
  background: var(--gtexd-color-panel-2);
  color: var(--gtexd-color-text-strong);
  border-color: var(--gtexd-color-accent);
}
body.gtexd-ui-managed #wpcontent .gtexd-cat__nav a:hover,
body.gtexd-ui-managed #wpcontent .gtexd-cat__nav a:focus-visible {
  background: var(--gtexd-color-panel-2);
  color: var(--gtexd-color-text-strong);
}

/* 3. Tables: preserve plugins' responsive/column sizing behavior. */
body.gtexd-ui-managed #wpcontent :is(
  .gtexd-cat__tablewrap, .gtexd-event-calendar-table-wrap
) { border-color: var(--gtexd-color-line); }
body.gtexd-ui-managed #wpcontent :is(
  .gtexd-cat__table, .gtexd-event-calendar-admin .widefat,
  .gtexd-event-calendar-admin .wp-list-table, .gtexd-event-calendar-table
) { background: var(--gtexd-color-panel); color: var(--gtexd-color-text); border-color: var(--gtexd-color-line); }
body.gtexd-ui-managed #wpcontent :is(
  .gtexd-cat__table, .gtexd-event-calendar-admin .widefat,
  .gtexd-event-calendar-admin .wp-list-table, .gtexd-event-calendar-table
) :is(th,td) {
  color: var(--gtexd-color-text);
  background: transparent;
  border-color: var(--gtexd-color-line);
}
body.gtexd-ui-managed #wpcontent :is(.gtexd-cat__table,.gtexd-event-calendar-admin .widefat)
  thead th { background: var(--gtexd-color-panel-2); color: var(--gtexd-color-muted-strong); }
body.gtexd-ui-managed #wpcontent :is(.gtexd-cat__table,.gtexd-event-calendar-admin .widefat)
  tbody tr:nth-child(even) { background: var(--gtexd-color-surface); }
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-event-title { color: var(--gtexd-color-text-strong); }
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-empty {
  border-color: var(--gtexd-color-line); color: var(--gtexd-color-muted);
  background: var(--gtexd-color-panel);
}

/* 4. Standard control appearance. Native input types stay functional. */
body.gtexd-ui-managed #wpcontent :is(
  input[type="text"], input[type="email"],input[type="search"],input[type="url"],
  input[type="number"],input[type="date"],input[type="time"],input[type="datetime-local"],
  input[type="password"],textarea
):not(.wp-color-picker) {
  box-sizing: border-box;
  min-height: 42px;
  max-width: 100%;
  border: 1px solid var(--gtexd-control-border) !important;
  border-radius: var(--gtexd-control-radius) !important;
  background-color: var(--gtexd-control-bg) !important;
  color: var(--gtexd-control-text) !important;
  -webkit-text-fill-color: var(--gtexd-control-text);
  box-shadow: none !important;
}
body.gtexd-ui-managed #wpcontent :is(
  input[type="text"], input[type="email"],input[type="search"],input[type="url"],
  input[type="number"],input[type="date"],input[type="time"],input[type="datetime-local"],
  input[type="password"],textarea
):not(.wp-color-picker):focus-visible {
  border-color: var(--gtexd-color-accent) !important;
  outline: 2px solid var(--gtexd-color-accent);
  outline-offset: 1px;
}
body.gtexd-ui-managed #wpcontent :is(input[type="checkbox"],input[type="radio"]) {
  box-sizing: border-box;
  accent-color: var(--gtexd-color-accent);
  vertical-align: middle;
  flex-shrink: 0;
}
body.gtexd-ui-managed #wpcontent label { color: var(--gtexd-color-text); }
body.gtexd-ui-managed #wpcontent select option { background: var(--gtexd-color-panel-2); color: var(--gtexd-color-text); }
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-form-actions {
  border-top-color: var(--gtexd-color-line);
}

/* 5. Buttons. Cover legacy Catalog buttons and WP standard buttons in GTExD
 * admin pages. Keep destructive actions visually distinct. */
body.gtexd-ui-managed #wpcontent :is(
  .gtexd-cat__button,button.button,a.button,input.button,
  button.button-primary,a.button-primary,input.button-primary
) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-height: var(--gtexd-button-height);
  height: auto;
  max-width: 100%;
  padding: 9px var(--gtexd-button-padding-x);
  border: 1px solid var(--gtexd-color-cta) !important;
  border-radius: var(--gtexd-button-radius) !important;
  background: var(--gtexd-color-cta) !important;
  color: #fff !important;
  box-shadow: none !important;
  font-family: var(--gtexd-font-display);
  font-size: var(--gtexd-button-font-size);
  font-weight: var(--gtexd-button-font-weight);
  line-height: 1.1;
  text-decoration: none;
  text-align: center;
  text-transform: uppercase;
  white-space: normal;
  cursor: pointer;
}
body.gtexd-ui-managed #wpcontent :is(
  .gtexd-cat__button,button.button,a.button,input.button,
  button.button-primary,a.button-primary,input.button-primary
):is(:hover,:focus-visible) {
  border-color: var(--gtexd-color-cta-hover) !important;
  background: var(--gtexd-color-cta-hover) !important;
  color: #fff !important;
}
body.gtexd-ui-managed #wpcontent :is(
  .gtexd-cat__button--outline,.button-secondary,.gtexd-event-calendar-delete
) {
  border-color: var(--gtexd-color-line-strong) !important;
  background: var(--gtexd-color-panel-2) !important;
  color: var(--gtexd-color-text) !important;
}
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-delete {
  color: #ff9da1 !important;
  border-color: var(--gtexd-color-danger) !important;
}
body.gtexd-ui-managed #wpcontent :is(.gtexd-cat__button,button.button,a.button,input.button):disabled {
  opacity: .6;
  cursor: not-allowed;
}

/* 6. Status pills, warning strips and supporting text. */
body.gtexd-ui-managed #wpcontent :is(
  .gtexd-event-calendar-status,.gtexd-event-calendar-chip,
  .gtexd-event-calendar-version,.gtexd-event-calendar-recurring-warning
) { border-radius: 0; }
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-status.is-ok {
  background: rgba(54,169,110,.12); color: #90e2b5; border-color: var(--gtexd-color-success);
}
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-status.is-error {
  background: rgba(227,50,56,.12); color: #ff9fa3; border-color: var(--gtexd-color-danger);
}
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-status.is-warning {
  background: rgba(208,160,44,.12); color: #f4d084; border-color: var(--gtexd-color-warning);
}
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-status.is-neutral {
  background: var(--gtexd-color-panel-2); color: var(--gtexd-color-muted-strong); border-color: var(--gtexd-color-line);
}
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-chip {
  border-color: var(--gtexd-color-line-strong); color: var(--gtexd-color-muted-strong);
}
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-chip.is-official {
  background: var(--gtexd-color-accent); color: #fff; border-color: var(--gtexd-color-accent);
}
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-chip.is-external {
  background: transparent; color: #ffb3b6; border-color: var(--gtexd-color-accent);
}
body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-chip.is-recurring {
  background: rgba(208,160,44,.12); color: #f4d084; border-color: var(--gtexd-color-warning);
}
body.gtexd-ui-managed #wpcontent :is(
  .gtexd-event-calendar-recurrence,.gtexd-event-calendar-series-settings,
  .gtexd-event-calendar-external-fields
) { border-left: 4px solid var(--gtexd-color-accent) !important; }
body.gtexd-ui-managed #wpcontent :is(
  .gtexd-event-calendar-recurring-warning,.gtexd-event-calendar-panel--warning
) { border-left: 4px solid var(--gtexd-color-warning) !important; }
body.gtexd-ui-managed #wpcontent :is(
  .gtexd-event-calendar-series-context,.gtexd-event-calendar-panel--info
) { border-left: 4px solid var(--gtexd-color-line-strong) !important; }

/* 7. Public modules inherit a single canvas/controls grammar; structural
 * themes of Home, Vision, Driver and Market remain untouched. */
:is(.gtexd-page,.gtexd-event-hub,.gtexd-driver-hub,.gtexd-gt7-market,.gtexd-gt7-market-hub,.gtexd-home) {
  --gtexd-control-bg: var(--gtexd-color-surface);
  --gtexd-control-border: var(--gtexd-color-line-strong);
  color: var(--gtexd-color-text);
  font-family: var(--gtexd-font-body);
}
:is(.gtexd-event-hub,.gtexd-driver-hub,.gtexd-gt7-market,.gtexd-gt7-market-hub) :is(input,textarea,select) {
  box-sizing: border-box;
  max-width: 100%;
}
:is(.gtexd-event-hub,.gtexd-driver-hub,.gtexd-gt7-market,.gtexd-gt7-market-hub)
  :is(input[type="checkbox"],input[type="radio"]) { accent-color: var(--gtexd-color-accent); }

@media (max-width: 782px) {
  body.gtexd-ui-managed #wpbody-content > .wrap:not(.gtexd-vision-admin):not(.gtexd-randomizer-admin):not(.gtexd-cat),
  body.gtexd-ui-managed .wrap.gtexd-cat { padding: 20px 16px 36px; }
  body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-events-table tr {
    background: var(--gtexd-color-panel) !important;
    border-color: var(--gtexd-color-line) !important;
  }
  body.gtexd-ui-managed #wpcontent .gtexd-event-calendar-events-table td::before {
    color: var(--gtexd-color-muted-strong);
  }
}

/* 8. GT7 Market Hub and other pre-existing GTExD tools use native WP tables.
 * Keep the native markup and actions while normalizing only managed pages. */
body.gtexd-ui-managed #wpbody-content > .wrap:not(.gtexd-vision-admin):not(.gtexd-randomizer-admin):not(.gtexd-cat) > :is(h1,h2,h3) {
  color: var(--gtexd-color-text-strong);
  font-family: var(--gtexd-font-display);
  font-weight: 700;
}
body.gtexd-ui-managed #wpcontent :is(.widefat,.wp-list-table,.form-table) {
  border-color: var(--gtexd-color-line);
  background: var(--gtexd-color-panel);
  color: var(--gtexd-color-text);
}
body.gtexd-ui-managed #wpcontent :is(.widefat,.wp-list-table,.form-table) :is(th,td) {
  border-color: var(--gtexd-color-line);
  color: var(--gtexd-color-text);
}
body.gtexd-ui-managed #wpcontent :is(.widefat,.wp-list-table) thead th,
body.gtexd-ui-managed #wpcontent :is(.widefat,.wp-list-table) tfoot th {
  background: var(--gtexd-color-panel-2);
  color: var(--gtexd-color-muted-strong);
}
body.gtexd-ui-managed #wpcontent :is(.widefat,.wp-list-table) tbody tr {
  background: var(--gtexd-color-panel) !important;
}
body.gtexd-ui-managed #wpcontent :is(.widefat,.wp-list-table) tbody tr:nth-child(even) {
  background: var(--gtexd-color-surface) !important;
}
body.gtexd-ui-managed #wpcontent .form-table label,
body.gtexd-ui-managed #wpcontent .form-table p,
body.gtexd-ui-managed #wpcontent .widefat p { color: var(--gtexd-color-muted-strong); }
body.gtexd-ui-managed #wpcontent :is(.widefat,.wp-list-table) a {
  color: #accbff;
}
body.gtexd-ui-managed #wpcontent :is(.widefat,.wp-list-table) a:hover {
  color: #e7f2ff;
}


/* 9. Canonical GTExD checkboxes (1.2.7).
 * Native accent-color alone is not reliable on mobile Safari and can inherit
 * blue from the browser/theme. The Core now draws the checked state explicitly.
 * Only GTExD-owned areas are affected; never modify arbitrary frontend forms.
 * Native input, label association, focus, disabled state and change handlers
 * are retained. Radio buttons are intentionally not modified.
 */
:is(
  .gtexd-check input[type="checkbox"],
  .gtexd-ui input[type="checkbox"],
  .gtexd-page input[type="checkbox"],
  .gtexd-event-hub input[type="checkbox"],
  .gtexd-driver-hub input[type="checkbox"],
  .gtexd-market-hub input[type="checkbox"],
  .gtexd-gt7-market input[type="checkbox"],
  .gtexd-gt7-market-hub input[type="checkbox"],
  .gtexd-home input[type="checkbox"],
  body.gtexd-ui-managed #wpcontent input[type="checkbox"]
) {
  -webkit-appearance: none !important;
  appearance: none !important;
  box-sizing: border-box !important;
  display: inline-block;
  width: 20px !important;
  height: 20px !important;
  min-width: 20px !important;
  min-height: 20px !important;
  max-width: 20px !important;
  max-height: 20px !important;
  padding: 0 !important;
  flex: 0 0 20px;
  border: 1px solid var(--gtexd-color-line-strong, #43505f) !important;
  border-radius: 3px !important;
  background-color: var(--gtexd-color-bg, #0d0d0f) !important;
  background-image: none !important;
  box-shadow: none !important;
  vertical-align: middle;
  cursor: pointer;
  accent-color: var(--gtexd-color-accent, #c42026);
  -webkit-tap-highlight-color: transparent;
}
:is(
  .gtexd-check input[type="checkbox"],
  .gtexd-ui input[type="checkbox"],
  .gtexd-page input[type="checkbox"],
  .gtexd-event-hub input[type="checkbox"],
  .gtexd-driver-hub input[type="checkbox"],
  .gtexd-market-hub input[type="checkbox"],
  .gtexd-gt7-market input[type="checkbox"],
  .gtexd-gt7-market-hub input[type="checkbox"],
  .gtexd-home input[type="checkbox"],
  body.gtexd-ui-managed #wpcontent input[type="checkbox"]
):checked {
  border-color: var(--gtexd-color-accent, #c42026) !important;
  background-color: var(--gtexd-color-accent, #c42026) !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M4 10.2 8.1 14.1 16 5.9' stroke='white' stroke-width='2.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
  background-position: center !important;
  background-size: 19px 19px !important;
  background-repeat: no-repeat !important;
}
/* Prevent native WordPress checkbox pseudo-checkmarks overlapping our SVG. */
:is(
  .gtexd-check input[type="checkbox"],
  .gtexd-ui input[type="checkbox"],
  .gtexd-page input[type="checkbox"],
  .gtexd-event-hub input[type="checkbox"],
  .gtexd-driver-hub input[type="checkbox"],
  .gtexd-market-hub input[type="checkbox"],
  .gtexd-gt7-market input[type="checkbox"],
  .gtexd-gt7-market-hub input[type="checkbox"],
  .gtexd-home input[type="checkbox"],
  body.gtexd-ui-managed #wpcontent input[type="checkbox"]
)::before,
:is(
  .gtexd-check input[type="checkbox"],
  .gtexd-ui input[type="checkbox"],
  .gtexd-page input[type="checkbox"],
  .gtexd-event-hub input[type="checkbox"],
  .gtexd-driver-hub input[type="checkbox"],
  .gtexd-market-hub input[type="checkbox"],
  .gtexd-gt7-market input[type="checkbox"],
  .gtexd-gt7-market-hub input[type="checkbox"],
  .gtexd-home input[type="checkbox"],
  body.gtexd-ui-managed #wpcontent input[type="checkbox"]
)::after {
  content: none !important;
  display: none !important;
}
:is(
  .gtexd-check input[type="checkbox"],
  .gtexd-ui input[type="checkbox"],
  .gtexd-page input[type="checkbox"],
  .gtexd-event-hub input[type="checkbox"],
  .gtexd-driver-hub input[type="checkbox"],
  .gtexd-market-hub input[type="checkbox"],
  .gtexd-gt7-market input[type="checkbox"],
  .gtexd-gt7-market-hub input[type="checkbox"],
  .gtexd-home input[type="checkbox"],
  body.gtexd-ui-managed #wpcontent input[type="checkbox"]
):focus-visible {
  outline: 2px solid var(--gtexd-color-accent, #c42026) !important;
  outline-offset: 2px !important;
}
:is(
  .gtexd-check input[type="checkbox"],
  .gtexd-ui input[type="checkbox"],
  .gtexd-page input[type="checkbox"],
  .gtexd-event-hub input[type="checkbox"],
  .gtexd-driver-hub input[type="checkbox"],
  .gtexd-market-hub input[type="checkbox"],
  .gtexd-gt7-market input[type="checkbox"],
  .gtexd-gt7-market-hub input[type="checkbox"],
  .gtexd-home input[type="checkbox"],
  body.gtexd-ui-managed #wpcontent input[type="checkbox"]
):disabled {
  opacity: .55;
  cursor: not-allowed;
}
/* System high-contrast modes supply their own checkmark and colors. */
@media (forced-colors: active) {
  :is(
    .gtexd-check input[type="checkbox"],
    .gtexd-ui input[type="checkbox"],
    .gtexd-page input[type="checkbox"],
    .gtexd-event-hub input[type="checkbox"],
    .gtexd-driver-hub input[type="checkbox"],
    .gtexd-market-hub input[type="checkbox"],
    .gtexd-gt7-market input[type="checkbox"],
    .gtexd-gt7-market-hub input[type="checkbox"],
    .gtexd-home input[type="checkbox"],
    body.gtexd-ui-managed #wpcontent input[type="checkbox"]
  ) {
    -webkit-appearance: auto !important;
    appearance: auto !important;
    background-image: none !important;
    background-color: Canvas !important;
    border-color: ButtonText !important;
  }
}
