/* Shared IQ paint in the dark interface. This layer changes paint only;
   neutral surfaces, emerald/status colours, geometry and handlers stay local. */
html:not([data-theme="light"]) {
  --iq-top: #8a29fa;
  --iq-upper: #6726e1;
  --iq-lower: #471ac0;
  --iq-bottom: #330a9e;
  --iq-gradient: linear-gradient(180deg, var(--iq-top) 0%, var(--iq-upper) 35%, var(--iq-lower) 70%, var(--iq-bottom) 100%);
  --iq-tint: linear-gradient(180deg, rgb(138 41 250 / .15) 0%, rgb(103 38 225 / .15) 35%, rgb(71 26 192 / .15) 70%, rgb(51 10 158 / .15) 100%);
  --accent: var(--iq-top);
  --home-iq-button-fill: var(--iq-gradient);
  --brand-action-fill: var(--iq-gradient);
  --brand-action-shadow: 0 12px 30px rgba(116, 88, 255, .4);
  --danger-bg: var(--iq-gradient);
  --danger-bg-hover: var(--iq-gradient);
  --danger-bg-active: var(--iq-gradient);
  --danger-border: rgb(138 41 250 / .55);
  --danger-shadow: 0 0 18px rgb(138 41 250 / .18), 0 6px 18px rgb(51 10 158 / .2);
  --danger-outline-text: #b993ff;
  --danger-outline-border: rgb(138 41 250 / .45);
  --danger-outline-hover: var(--iq-tint);
}

/* Opaque violet actions, selected navigation and small solid indicators. */
html:not([data-theme="light"]) body :is(#app, #sheetRoot, .tabbar) :is(
  .primary:not(.ui-button):not(.article395-submit), #addMain, .home-attach, .send-question,
  .chat-send, .assistant-send, .avatar, .profile-avatar:not(:has(img)),
  .auth-brand > span, .about-app-card > span,
  .audio-hero button, .undo-toast button, .case-action.archive,
  .upload-center-summary > span, .upload-progress i, .bulk-bar b,
  .case-material-context > span, .timeline-item > i, .case-timeline-item::before,
  .steps .active i, .onboarding-progress i.active,
  .calendar-ai-followup button, .case-edit-save,
  .ios-reference-event-form .calendar-event-form-head button:last-child,
  .chips .filter-token.active, .document-filter-chips .chip.active,
  .case-tabs button.active, .case-section-option.active,
  .timeline-switch button[aria-selected="true"], .timeline-filters button.active,
  .calendar-view-popover button.active, .calendar-year-grid button.active,
  .calendar .days button.today, .calendar-week-strip button.today,
  .text-size-options button.active, .profile-choice-list button.active,
  .upload-case-dropdown button.active, .auth-tabs button.active,
  .notification-setting-row input:checked + span,
  .toggle-row input:checked + span,
  .scanner-filters button.active, .doc-icon::before, .search-result-icon.doc::before
):not(.profile-choice-list > button) {
  background-image: var(--iq-gradient) !important;
}
html:not([data-theme="light"]) body :is(#app, #sheetRoot, .tabbar) :is(
  .primary:not(.ui-button):not(.article395-submit), .home-attach, .send-question, .chat-send, .assistant-send,
  .case-edit-save, .chips .filter-token.active, .document-filter-chips .chip.active,
  .case-tabs button.active, .case-section-option.active,
  .timeline-switch button[aria-selected="true"], .timeline-filters button.active,
  .calendar-view-popover button.active, .calendar-year-grid button.active,
  .calendar .days button.today, .calendar-week-strip button.today,
  .text-size-options button.active, .profile-choice-list button.active,
  .upload-case-dropdown button.active, .auth-tabs button.active, .scanner-filters button.active
) { color: #fff !important; }

/* First-variant buttons use the same clean, borderless edge as the cases plus.
   Keep semantic danger and the scanner's yellow review action separate. */
html:not([data-theme="light"]) body :is(#app, #sheetRoot) :is(
  button.primary:not(.danger):not(.ui-button):not(.article395-submit),
  button.case-edit-save
) {
  border: 0 !important;
  border-image: none !important;
  box-shadow: var(--creation-button-shadow, 0 8px 20px rgba(116, 88, 255, .2)) !important;
}
html:not([data-theme="light"]) body .document-scanner-screen .scanner-review .scanner-crop-actions .primary {
  border: 1px solid #ffd65a !important;
}

/* All creation actions already share this semantic selector layer. */
html:not([data-theme="light"]) body :is(#app, #sheetRoot) :is(
  [data-plan-action="add"], [data-timeline-add], [data-add-calendar-event],
  [data-case-task-new], [data-action="new-task"], [data-action="task-added"],
  [data-add-existing-case], [data-home-layout], [data-bulk-add], [data-bulk-start],
  [data-action="upload-next-volume"], [data-case-photo-confirm], #startUpload,
  [data-chat-document-confirm], [data-scanner-add-case],
  .rich-empty [data-route="case-type"], .rich-empty [data-route="document-case"],
  #caseForm button[type="submit"], #noteForm button[type="submit"],
  #filterForm button[type="submit"], #documentBuilderForm button[type="submit"],
  #audioMaterialForm button[type="submit"],
  #calendarEventForm:not([data-edit-event-id]) button[type="submit"],
  .cases-add-button, .case-material-trigger, [data-add-filter],
  [data-new-assistant-chat], .upload-file-picker
):not([hidden]) { background-image: var(--iq-gradient) !important; }

/* Quiet accent panels use the same stops at lower opacity, so content stays
   readable and a selected control still differs from its surroundings. */
html:not([data-theme="light"]) body :is(#app, #sheetRoot) :is(
  .ai-card:not([data-home-card]), .notice, .upload-zone, .calendar-ai-case-choices button,
  .filter-token.holding, .filter-placeholder, .home-card-placeholder,
  .preference-row.active, .note-case-hint, .note-selected-case,
  .case-section-badges span, .case-tab-placeholder,
  .document-upload-settings > div, .processing-material-type,
  .global-search-entry, .notification-detail-case, .upload-center-summary,
  .pdf-page-badge, .pdf-preview-sheet > p, .calendar-voice-examples button,
  .document-builder-intro, .document-builder-ready,
  .case-discussion-preview, .case-discussion-state,
  .assistant-followups button, .audit-source, .answer-page-link,
  .timeline-origin, .case-analysis-confidence:not(.low),
  button.secondary:not(.danger):not([data-close-sheet]),
  .document-action:not(.retry):not(.quiet), .system-notification-card button,
  .summary-edit, .chips .chip.filter-add
) { background-image: var(--iq-tint) !important; }

/* Violet icon tiles get the full IQ paint with white glyphs. Signal variants
   retain their emerald/red/yellow roles. Brain artwork remains an image. */
html:not([data-theme="light"]) body :is(#app, #sheetRoot) :is(
  .quick i, .camera-symbol, .upload-zone > span,
  .sheet > button > span, .profile-tool-icon, .preference-row > span,
  .storage-type:not(.photo):not(.audio), .storage-row div > i, .note-case-result > span,
  .profile-photo-pick, .case-type-option > span, .case-type-current > span,
  .document-case-option > span, .upload-case-current > span,
  .upload-case-dropdown button > span, .case-sections-head > span,
  .unified-case-result > span, .search-result-icon, .rich-empty > span,
  .upload-job-head > span, .interface-hints-reset > span,
  .case-sections-arrow, .analysis-icon:not(.alert),
  .new-case-choice .new-case-avatar, .case-discussion-orb,
  .profile-unified-icon:not(.profile-unified-privacy), .assistant-attachment > span, .scanner-recovery > span,
  .first-case-steps b, .document-builder-brain, .document-builder-ready > span,
  .case-preview-avatar:not(.has-type-art)
) { background-image: var(--iq-gradient) !important; color: #fff !important; }

/* Accent text has a lightened version of the SAME stops. The opaque button
   gradient is too dark at its lower edge for small text on a dark surface. */
html:not([data-theme="light"]) body :is(#app, #sheetRoot, .tabbar) :is(
  .section-title button, .text-btn,
  .document-index-action.resume, .security-note:not(.profile-security-note), .audio-wave, .transcript time,
  .auth-card header p, .auth-switch, .case-insight-sources,
  .case-field-proposal > small:first-child, .calendar-ai-preview header button,
  .note-selected-case small, .notification-detail-sheet > header button,
  .calendar-search-sheet > header button, .calendar-search-date time,
  .task-editor-sheet header button, .state-duty-reset,
  .calendar-event-form-head button:not(:last-child),
  .case-discussion-preview > b, .case-discussion-state > b,
  .deadline-empty-state button, .onboarding-kicker, .doc-category,
  .summary-add-client, .scanner-page-actions button:not([data-scanner-delete-page]), .audio-time,
  .split-tools .link-button, .document-parts summary,
  .timeline-hidden .link-button,
  .answer-audit-link
) {
  background-image: linear-gradient(180deg,
    color-mix(in srgb, var(--iq-top) 45%, #fff) 0%,
    color-mix(in srgb, var(--iq-upper) 45%, #fff) 35%,
    color-mix(in srgb, var(--iq-lower) 45%, #fff) 70%,
    color-mix(in srgb, var(--iq-bottom) 45%, #fff) 100%) !important;
  background-clip: text;
  -webkit-background-clip: text;
  color: #b993ff;
  -webkit-text-fill-color: transparent;
}

/* SVG paint server uses the exact four stops rather than clipping icon boxes. */
html:not([data-theme="light"]) body :is(#app, #sheetRoot, .tabbar) :is(
  .tab.active, .home-ai-spark, .doc-icon, .analysis-card > span,
  .notice > span, .menu-row > span, .case-card-pin-mark,
  .app-icon-option b
) svg.ui-icon { stroke: url(#iq-violet-paint); }
html:not([data-theme="light"]) body :is(#app, #sheetRoot) :is(
  .ui-icon-button, .document-action, .summary-edit, .chips .chip.filter-add
):not(.primary):not(.danger):not(.retry):not(.quiet) { color: #b993ff; }

/* No extra animation is introduced. Focus remains visible; forced colours
   use the platform's text paint rather than transparent clipped labels. */
@media (forced-colors: active) {
  html:not([data-theme="light"]) body :is(#app, #sheetRoot, .tabbar) * {
    -webkit-text-fill-color: currentColor !important;
  }
  html:not([data-theme="light"]) body svg.ui-icon { stroke: currentColor !important; }
}

/* Final screen-specific paints; drawn glyphs stay white on opaque tiles. */
html:not([data-theme="light"]) body #app :is(
  .case-brain-fab, .message.user, .chat-intro > span:not(.assistant-intro-brain),
  .rag-index-progress > i > u, .case-card-pin-mark
) { background-image: var(--iq-gradient) !important; }
/* Dark case medallion matches the light theme's clean circular outline, using
   the IQ accent and the same glow family as the navigation plus. */
html:not([data-theme="light"]) body.case-route #app .assistant-fab.case-brain-fab {
  background-image: none !important;
  border: 3px solid var(--iq-top) !important;
  box-shadow: 0 0 0 3px rgb(138 41 250 / .42), 0 8px 22px rgb(70 30 160 / .52), 0 0 22px rgb(138 41 250 / .38) !important;
}
html:not([data-theme="light"]) body #app :is(
  .profile-unified-icon:not(.profile-unified-privacy), .analysis-icon:not(.alert),
  .case-type-option > span, .document-case-option > span,
  .upload-zone > span, .rich-empty > span
) svg { stroke: #fff !important; }
html:not([data-theme="light"]) body #app :is(.home-ai-spark, .doc-icon) svg.ui-icon,
html:not([data-theme="light"]) body #app .summary-edit svg.ui-icon {
  stroke: url(#iq-violet-paint);
}
/* Filled violet actions use a white glyph for clear contrast. */
html:not([data-theme="light"]) body #app :is(.cases-add-button, .case-material-trigger, .summary-edit, .chips .chip.filter-add) {
  color: #fff !important;
  -webkit-text-fill-color: #fff !important;
}
html:not([data-theme="light"]) body #app :is(.cases-add-button, .case-material-trigger, .summary-edit, .chips .chip.filter-add) :is(svg.ui-icon, span) {
  color: #fff !important;
  stroke: #fff !important;
  -webkit-text-fill-color: #fff !important;
}
html:not([data-theme="light"]) body #app :is(
  .case-tabs button.active, .timeline-filters button.active,
  .chips .filter-token.active, .case-section-option.active,
  .profile-hero-card, .summary-field,
  .app-icon-option.active, .theme-option.active, .text-size-options button.active,
  .assistant-followups button, .assistant-attachment, .home-ai-search,
  .answer-page-link, .audit-source, .upload-zone, .case-material-context
) { border-color: rgb(138 41 250 / .4) !important; }

/* Selected case tabs and Plan filters keep the IQ fill without a coloured rim or inset edge.
   The browser's keyboard focus outline remains available. */
html:not([data-theme="light"]) body.case-route #app .case-tabs button.active,
html:not([data-theme="light"]) body #app .plan-filters .filter-token.active {
  border-color: transparent !important;
  border-image: none !important;
  box-shadow: none !important;
}

/* Active navigation labels use exactly the SVG/button stops, no white mix. */
html:not([data-theme="light"]) body .tabbar .tab.active small {
  background-image: var(--iq-gradient) !important;
  background-clip: text;
  -webkit-background-clip: text;
  color: var(--iq-top);
  -webkit-text-fill-color: transparent;
}
/* Back and compact reset actions match the central plus in dark mode. */
html:not([data-theme="light"]) body :is(#app, .document-viewer-layer, .document-text-layer) :is(button[data-back], .scanner-head button[data-scanner-back], .state-duty-reset, .document-viewer-close.button-variant-2, [data-close-document-text]) {
  background-color: transparent !important;
  background-image: var(--brand-action-fill) !important;
  background-clip: border-box !important;
  -webkit-background-clip: border-box !important;
  border-color: transparent !important;
  color: #fff !important;
  -webkit-text-fill-color: #fff !important;
  box-shadow: var(--brand-action-shadow) !important;
}
html:not([data-theme="light"]) body :is(#app, .document-viewer-layer, .document-text-layer) :is(button[data-back], .scanner-head button[data-scanner-back], [data-close-document-text]) svg.ui-icon {
  color: #fff !important;
  stroke: #fff !important;
  fill: none !important;
}
html:not([data-theme="light"]) body #app .state-duty-reset { border-radius: 14px; }
/* Remove the coloured rim without changing the icon tile's footprint. */
html:not([data-theme="light"]) body #app .profile-unified-icon:not(.profile-unified-privacy) {
  border-color: transparent !important;
  background-origin: border-box;
  background-repeat: no-repeat;
  box-shadow: none !important;
}
