/* Shared Customisation-card finish. Explicit surface adapters, not substring
   matching: card controls, previews, modal shells and table rows stay intact.
   Important declarations in this layer beat legacy page-specific !important
   finishes. Section-heading adapters below own only heading geometry;
   feature controls, scroll rails and display/hidden states remain local. */
@layer eos-cards {
  @media screen {
    body {
      --eos-card-surface: linear-gradient(145deg, #fff, #edf8fd);
      --eos-card-ink: #183d52;
      --eos-card-edge: #c6e2ef;
      --eos-card-accent: #2a9bc438;
      --eos-card-title: #fff;
      --eos-card-shadow: 0 2px 5px #123c5409, 0 10px 26px #123c5410,
        inset 0 1px 0 #ffffffb3;
    }
    body.dev-matrix {
      --eos-card-surface: var(--theme-surface, #102633);
      --eos-card-ink: var(--theme-text, #eaf5fa);
      --eos-card-edge: var(--theme-border, #426678);
      --eos-card-title: var(--theme-raised, #173544);
      --eos-card-accent: #64b8d538;
      --eos-card-shadow: 0 2px 5px #0002, 0 10px 26px #0003,
        inset 0 1px 0 #ffffff08;
    }
    :is(
      .eos-card, .eos-section-card, .instructions, .chart-box, .card, .panel, .dashboard-card, .settings-card,
      .tech-entry-fieldset, .tech-entry-fieldset1, .tech-entry-fieldsetSS,
      .tech-entry-fieldset-ss, .instruction-item, .data-panel,
      .customer-card-panel, .customer-company-panel, .global-search-panel,
      .global-search-card, .reference-panel, .parts-panel, .manual-panel,
      .manual-card, .manual-section, .manual-admin-card, .manual-result-card,
      .result-card, .dfb-card, .edit-card, .it-call-detail-card,
      .it-calls-v2-section-card, .it-calls-v2-chargeable-card,
      .it-calls-v2-queue-card, .it-calls-v2-ai-panel, .it-log-v2-card,
      .it-log-v2-helper-card, .copiers-v2-status-panel, .copiers-v2-status-card,
      .vmv2-card, .vmv2-panel, .ac2-card, .ac2-panel,
      .ac2-request-mobile-card, .ac2-engineer-report-mobile-card,
      .ac2-it-history-card, .mu-card, .mu-health-panel, .mu-chart-panel,
      .mu-logo-review-card, .collected-review-card, .collection-machine-card,
      .machine-card, .device-card, .install-machine-card, .nf-panel,
      .quote-card, .upload-card, .photo-card, .summary-panel, .text-panel,
      .status-panel, .sync-panel, .signature-panel, .hero-status-card,
      .auth-card, .login-card, .help-contents, .perf-section, .anim-proof-card,
      .event-card, .total-card, .settings-message-card
    ):not(#appearanceCard) {
      box-sizing: border-box;
      min-width: 0;
      background: var(--eos-card-surface) !important;
      color: var(--eos-card-ink) !important;
      border: 1px solid var(--eos-card-edge) !important;
      border-left: 4px solid var(--eos-card-accent) !important;
      border-radius: 22px !important;
      box-shadow: var(--eos-card-shadow) !important;
      /* Use an existing semantic accent when a feature supplies one. */
      border-left-color: var(--card-accent, var(--eos-card-accent)) !important;
    }
    /* Appearance keeps its own surface/preview palette, but shares the finish.
       Keep the 4px geometry: the translucent edge softens nested cards without
       moving their contents or diluting semantic status colours. */
    #appearanceCard {
      border-left-color: var(--eos-card-accent) !important;
      box-shadow: var(--eos-card-shadow) !important;
    }
    .event-card.install { --card-accent: var(--ev-color, #dc2626); }
    .event-card.collection { --card-accent: var(--ev-color, #2563eb); }
    .event-card.holiday { --card-accent: var(--ev-color, #16a34a); }
    .event-card.other-event { --card-accent: var(--ev-color, #f97316); }
    .total-card.urgent { --card-accent: #ea580c; }
    .total-card.later { --card-accent: #16a34a; }
    .total-card.primary { --card-accent: #2563eb; }
    .settings-message-card.is-received { --card-accent: #10b981; }
    body:not(.dev-matrix) .it-calls-v2-opened-hint {
      color: #526e7e !important;
    }
    body.dev-matrix .parts-panel :is(.panel-kicker, .panel-subtitle) {
      color: var(--theme-muted) !important;
    }
    body.dev-matrix :is(#error-results-empty, #manuals_results_empty,
        #parts_results_empty, #manual_preview_placeholder, #diagram_placeholder) {
      background: var(--theme-raised) !important;
      color: var(--theme-muted) !important;
    }
    :is(.tech-entry-fieldset, .tech-entry-fieldset1,
        .tech-entry-fieldsetSS, .tech-entry-fieldset-ss, .eos-card) > legend {
      color: var(--eos-card-ink) !important;
      background: var(--eos-card-title) !important;
      border: 1px solid var(--eos-card-edge) !important;
      border-radius: 20px !important;
      padding: 4px 12px !important;
      max-width: 100%;
      white-space: normal;
      overflow-wrap: anywhere;
    }
    /* Settings-style section titles. Explicit families, never all headings.
       In-flow titles wrap naturally; the negative half-line lift crosses the
       border while retained bottom space keeps controls and copy clear. */
    :is(.eos-section, .mu-card, .mu-health-panel, .mu-chart-panel,
        .nf-panel, .customer-card-panel, .customer-company-panel,
        .it-log-v2-card, .it-calls-v2-section-card, .it-call-detail-card,
        .manual-section, .help-contents, .ac2-panel, .ac2-card,
        .global-search-panel, .eos-section-card, .instructions, .chart-box, .edit-card,
        .parts-panel):has(> .eos-section-title, > :is(h2,h3,h4),
          > .eos-section-head, > :is(.mu-card-head,.mu-health-panel-head,
          .mu-chart-head,.it-log-v2-card__head,.it-calls-v2-section-card__head,
          .it-call-detail-card__head,.parts-panel-head)) {
      padding-top: 0 !important;
      margin-top: 1.25rem;
      overflow: visible;
    }
    :is(.eos-section-title, .eos-section-card > :is(h2,h3),
        .global-search-panel > h2, .instructions > h2, .chart-box > h2, .edit-card > h4,
        .mu-card > h3, .mu-health-panel > h4, .mu-chart-panel > h4,
        .nf-panel > h2, .customer-card-panel > h2, .customer-company-panel > h2,
        .manual-section > :is(h2,h3), .help-contents > h2,
        .ac2-panel > :is(h3,h4), .ac2-card > :is(h3,h4),
        .mu-card-head > :is(h3,h4), .mu-card-head > div > h3,
        .mu-health-panel-head > h4, .mu-health-panel-head > div > h4,
        .mu-chart-head > h4,
        .it-log-v2-card__title, .it-calls-v2-section-card__title,
        .it-call-detail-card__head > :is(h2,h3),
        .parts-panel-head .panel-title) {
      box-sizing: border-box;
      display: block;
      position: relative;
      width: fit-content;
      min-width: 0;
      max-width: 100%;
      margin: -0.75em 0 12px !important;
      padding: 6px 14px !important;
      color: var(--eos-card-ink) !important;
      background: var(--eos-card-title) !important;
      border: 1px solid var(--eos-card-edge) !important;
      border-radius: 24px !important;
      font-weight: 900 !important;
      line-height: 1.35;
      white-space: normal;
      overflow-wrap: anywhere;
    }
    /* Header rows keep badges/actions in flow, beside or below the title. */
    :is(.eos-section-head, .mu-card-head, .mu-health-panel-head,
        .mu-chart-head, .it-log-v2-card__head,
        .it-calls-v2-section-card__head, .it-call-detail-card__head,
        .parts-panel-head) {
      min-width: 0;
      flex-wrap: wrap;
    }
    :is(.eos-section-head, .mu-card-head, .mu-health-panel-head,
        .mu-chart-head) > div { min-width: 0; max-width: 100%; }
    /* These panels have no body inset: retain the mileage spacing fix, and
       move only its title row onto the border. Rails/snap/hidden stay owned
       by the feature stylesheet. */
    .vmv2-panel.eos-section > .vmv2-panel-head {
      padding: 0 16px 0 !important;
    }
    .vmv2-panel-head > .vmv2-pill { margin-top: 8px; }
    .eos-section-card { padding-inline: 16px; }
    .it-call-detail-card > .eos-section-title {
      margin-left: 16px !important;
      max-width: calc(100% - 32px);
      font-size: 1rem;
    }
    /* Keep context copy, but place the actual heading at the card border. */
    .it-log-v2-card__head > div:has(.it-log-v2-card__eyebrow) {
      display: flex; flex-direction: column; min-width: 0;
    }
    .it-log-v2-card__head .it-log-v2-card__title { order: -1; }
  }
}
