/* =========================================================================
   STP CG — DARK THEME LAYER
   -------------------------------------------------------------------------
   Loaded LAST by Main::headBase(), and only when users.themePreference is
   'dark' or 'auto' (profile > Appearance). Every rule keys on
   html[data-stp-dark], which the head script sets for 'dark', and for
   'auto' while the OS is dark. Light users never download this file.

   Strategy: stpTheme.css is token-driven (~630 var(--stp*) uses), so the
   bulk of the flip is the token block below. The sections after it cover
   the few raw colours stpTheme.css paints without a token and the legacy
   stpMain.css / framework main.css surfaces that ignore the tokens.
   The rail and head bar were already dark; they are left as they are.
   ========================================================================= */

/* ---- tokens ------------------------------------------------------------- */
:root[data-stp-dark] {
	color-scheme: dark;                   /* native date pickers, selects, scrollbars */

	--stpSurface: #1e1e1c;
	--stpCanvas: #141413;
	--stpHairlineColor: rgba(255, 255, 255, .09);
	--stpHairline: 1px solid rgba(255, 255, 255, .09);
	--stpShadow: 0 1px 2px rgba(0, 0, 0, .30);
	--stpShadowModal: 0 24px 70px rgba(0, 0, 0, .55);
	--stpRowDividerColor: rgba(255, 255, 255, .06);
	--stpRowDivider: 1px solid rgba(255, 255, 255, .06);
	--stpBorder: rgba(255, 255, 255, .16);

	--stpInk: #ececea;
	--stpInkHover: #ffffff;
	--stpBody: #d4d4cf;
	--stpBodyAlt: #b8b8b1;
	--stpMuted: #96968f;
	--stpSecondary: #a3a39c;

	--stpAccent: #ef4f66;
	--stpAccentHi: #f26a7e;
	--stpAccentDeep: #f58a99;
	--stpAccentBg: #3b1c23;

	--stpGood: #3fbf76;
	--stpGoodInk: #74d79e;
	--stpGoodBg: #16301f;
	--stpInfoBg: #1b2a40;

	--stpHover: #2b2b28;
	--stpRowHover: #252523;
	--stpZebra: #222220;

	--stpHeadBarHairline: rgba(255, 255, 255, .07);
	--stpCaretIdle: #5e5e59;
	--stpBorderFocus: rgba(255, 255, 255, .34);
	--stpHeaderHairline: 1px solid rgba(255, 255, 255, .08);
	--stpHeaderHairlineColor: rgba(255, 255, 255, .08);
	--stpTableHeadBorder: rgba(255, 255, 255, .09);
	--stpPlateInk: #d6d6d0;
	--stpEmptyBody: #8f8f88;
	--stpEnfEmptyBody: #8f8f88;
	--stpRepBarIdle: #4a4a46;
	--stpScrollThumb: #3a3a37;
	--stpStepTodo: #33332f;

	/* legacy / framework names stpTheme.css maps onto the tokens */
	--bg: var(--stpCanvas);
	--bgDev: var(--stpSurface);
	--sectionbg: var(--stpSurface);
	--ultraLight: var(--stpZebra);
	--defaultTextColor: var(--stpBody);
}

/* ---- page + text -------------------------------------------------------- */
:root[data-stp-dark],
:root[data-stp-dark] body {
	background-color: var(--stpCanvas);
	color: var(--stpBody);
}

:root[data-stp-dark] :is(h1, h2, h3, h4, h5, h6) {
	color: var(--stpInk);
}

:root[data-stp-dark] a:not(.formBtn) {
	color: var(--stpInk);
}

/* ---- controls ----------------------------------------------------------- */
:root[data-stp-dark] :is(input:not([type=checkbox]):not([type=radio]):not([type=button]):not([type=submit]):not([type=range]), select, textarea) {
	background-color: var(--stpSurface);
	color: var(--stpInk);
	border-color: var(--stpBorder);
}

/* green add-record row: main.css:1908 paints its fields --lightGreen, but the rule
   above outranks it, leaving black boxes on the green row */
:root[data-stp-dark] .formRow.lightGreen > div :is(input:not([type=checkbox]):not([type=radio]):not([type=button]):not([type=submit]):not([type=range]), select, textarea) {
	background-color: var(--lightGreen);
}

/* main.css:1912 inks the add row #000 — the + action vanished on the dark green */
:root[data-stp-dark] .formRow.lightGreen > div {
	color: var(--stpInk);
}

/* table-row inputs stay transparent so alternate rows look alike (outranks the generic fill above) */
:root[data-stp-dark] .formRow > div input:where([type=text], [type=number], [type=email], [type=tel], [type=url], [type=search], [type=password]):not(:disabled):not(.excludeFormPopRow):not(.searchDependantV2) {
	background-color: transparent;
}

:root[data-stp-dark] :is(input, textarea)::placeholder {
	color: var(--stpMuted);
}

:root[data-stp-dark] :is(input, select, textarea):disabled {
	background-color: var(--stpZebra);
	color: var(--stpMuted);
}

/* ---- raw colours in stpTheme.css without a token ------------------------ */
:root[data-stp-dark] .stpBanner.is-info {
	color: #8db8f2;
}

:root[data-stp-dark] .stpBanner.is-warn {
	color: #f0c070;
	background-color: #33270f;
}

:root[data-stp-dark] .stpBanner.is-neutral {
	color: var(--stpSecondary);
	background-color: var(--stpHover);
}

:root[data-stp-dark] #searchNotice.stpPubSearch {
	background: var(--stpSurface);
}

/* ---- framework main.css surfaces painted with literal white -------------
   :where() keeps these at the framework's own specificity, so every more
   specific state (zebra, .formRow.red/.green/.blue, selected rows) still wins. */
:where(:root[data-stp-dark]) .formRow > div {
	background-color: var(--stpSurface);
}

/* ---- status pills ---------------------------------------------------------
   Pills carry their light tone as inline custom properties (Main::getStpSemanticPillColors()
   → --pcFg/--pcBg/--pcDot). Each light fill maps to a dark-tinted fill + lighter ink;
   the dot keeps its hue. Matching on the fill keeps PHP untouched. */
:root[data-stp-dark] [style*="--pcBg:#fdf1dd"] { --pcBg: #33270f !important; --pcFg: #f0c070 !important; }  /* unpaid / issued */
:root[data-stp-dark] [style*="--pcBg:#e8f0fb"] { --pcBg: #1b2a40 !important; --pcFg: #8db8f2 !important; }  /* appeal */
:root[data-stp-dark] [style*="--pcBg:#e7f5ec"] { --pcBg: #16301f !important; --pcFg: #74d79e !important; }  /* paid */
:root[data-stp-dark] [style*="--pcBg:#efefee"] { --pcBg: #2b2b28 !important; --pcFg: #b0b0a9 !important; }  /* neutral */
:root[data-stp-dark] [style*="--pcBg:#fbe9ec"] { --pcBg: #3b1c23 !important; --pcFg: #f58a99 !important; }  /* denied */

/* header sort pill (main.css:1702 #ffffff / #e1e1e1) */
:where(:root[data-stp-dark]) .formV2MenuHelp {
	background-color: var(--stpSurface);
	border-color: var(--stpBorder);
}

:where(:root[data-stp-dark]) .formV2MenuHelp .separator {
	background-color: var(--stpBorder);
}

/* zebra rows: main.css:1926 paints them #333 text (0,8,0) */
:root[data-stp-dark] .formRow.ultraLight:not(.formRow.red):not(.formRow.yellow):not(.formRow.green),
:root[data-stp-dark] .formRow.ultraLight:not(.formRow.red):not(.formRow.yellow):not(.formRow.green) > div {
	color: var(--stpBody);
}

/* ticket toolbar filter chip label inherits a legacy #333 */
:root[data-stp-dark] .stpTicketToolbar .stpFilterChip {
	color: var(--stpSecondary);
}

/* file-picker buttons are <label>s, so the muted field-label colour (stpTheme.css
   section.block…subject label) beat .formBtn.primary — illegible on the light fill */
:root[data-stp-dark] section.block.long .longBlock.formInput .subject label.formBtn.primary {
	color: var(--stpSurface);
}

/* ---- search / action dropdowns -------------------------------------------
   main.css:1481 nests `& > div{background-color:#fff}` inside a selector list
   that includes `.formRow div.actionFunctionResult`, so its rows resolve at
   (0,2,2) and beat stpTheme.css `div.searchResult > div` (0,1,2): white rows
   carrying the dark theme's light text. */
:root[data-stp-dark] :is(div.searchResult, .formRow div.actionFunctionResult, .tab-controls-group .actionFunctionResult) {
	border-color: var(--stpBorder);
}

:root[data-stp-dark] :is(div.searchResult, .formRow div.actionFunctionResult, .tab-controls-group .actionFunctionResult) > div {
	background-color: var(--stpSurface);
	color: var(--stpInk);
	border-bottom-color: var(--stpRowDividerColor);
}

:root[data-stp-dark] :is(div.searchResult, .formRow div.actionFunctionResult, .tab-controls-group .actionFunctionResult) > div:hover:not(.noLink) {
	background-color: var(--stpHover);
}

/* ---- toast (#rmsg) ---------------------------------------------------------
   main.css:2189/2228/2232 paint light tints with #000 text; on dark they glare.
   Same three states, dark tints, ink text; the ring, icon and progress bar keep
   their hues. */
:root[data-stp-dark] #rmsg.toast {
	background-color: #16301f;
	color: var(--stpInk);
	--rmsgRing: #2f7a4a;
}

:root[data-stp-dark] #rmsg.toast.red {
	background-color: var(--stpAccentBg);
	color: var(--stpInk);
	--rmsgRing: #8a3442;
}

:root[data-stp-dark] #rmsg.toast.yellow {
	background-color: #33270f;
	color: var(--stpInk);
	--rmsgRing: #806020;
}

/* dropdown and chat scrollbars follow the dark scheme (thumb token, no light track) */
:root[data-stp-dark] :is(div.searchResult, .formRow div.actionFunctionResult, .chatBox .messageBody) {
	scrollbar-color: var(--stpScrollThumb) transparent;
}

/* sticky group sub-heads (main.css:1742 #ffffff) */
:where(:root[data-stp-dark]) .formRow.subHead {
	background-color: var(--stpSurface);
}

/* ---- login / reset / client / resetcon logo --------------------------------
   stp-logo.png is black wordmark + red stripes on an opaque white box. Invert
   (black ink -> white, white box -> black), rotate the hue back so the red stays
   red, then `lighten` drops the now-black box into the card surface. */
:root[data-stp-dark] .stpLoginLogo img {
	filter: invert(1) hue-rotate(180deg);
	mix-blend-mode: lighten;
}

/* ---- public notice mark: swap to stp-logo-white.png (transparent, no blend) */
:root[data-stp-dark] .stpPubMark img {
	display: none;
}

:root[data-stp-dark] .stpPubMark .stpPubMarkDark {
	display: block;
	mix-blend-mode: normal;
}

/* ---- chat (dispute messages, ChatV1 — framework chatBox.css + utilities.css) ----
   chatBox.css drives the panel from :root variables with generic names
   (--border-color, --accent-color …), so they are re-pointed on .chatBox only,
   never page-wide. Bubbles are neutral tokens (white-card / info-tint family in
   light, surface / info-tint in dark), matching the Messages tab rules in
   stpTheme.css; the teal family is gone. */
:root[data-stp-dark] .chatBox {
	--border-color: var(--stpBorder);
	--header-bg-color: var(--stpSurface);
	--header-title-color: var(--stpInk);
	--message-tags-bg-color: var(--stpSurface);
	--message-body-bg-color: var(--stpCanvas);
	--in-msg-bg-color: var(--stpSurface);
	--out-msg-bg-color: var(--stpInfoBg);
	--sub-title-color: var(--stpSecondary);
	--footer-bg-color: var(--stpSurface);
	--comment-thread-bg-color: var(--stpSurface);
	--comment-thread-text-color: var(--stpInk);
	--comment-thread-sub-title-color: var(--stpMuted);
	--message-edit-bg-color: #232b2b;
	--message-edit-text-color: var(--stpSecondary);
	--select-option-bg-color: var(--stpSurface);
	--new-thread-bg-color: var(--stpZebra);
	--new-thread-border-color: var(--stpBorder);
	--new-thread-text-color: var(--stpSecondary);
	--thread-item-hover-bg-color: var(--stpHover);
	--thread-item-title-color: var(--stpInk);
	--thread-item-meta-color: var(--stpMuted);
}

/* composer tabs sit in a .tab-content painted #fff (utilities.css:88); let the footer show */
:root[data-stp-dark] .chatBox .tab-content {
	background: transparent;
}

/* composer card (utilities.css:675 #f5f6f8 / #e8eaed, text #1f2937) */
:root[data-stp-dark] .chatComposerCard {
	background: var(--stpZebra);
	border-color: var(--stpBorder);
}

:root[data-stp-dark] .chatComposerTextarea {
	color: var(--stpInk);
}

:root[data-stp-dark] .chatComposerTextarea::placeholder {
	color: var(--stpMuted);
}

/* send: utilities.css:873 forces #111827 !important; invert like every primary button */
:root[data-stp-dark] .chatComposerSendBtn.formBtn {
	background: var(--stpInk) !important;
	color: var(--stpSurface) !important;
}

:root[data-stp-dark] .chatComposerSendBtn.formBtn:hover {
	background: var(--stpInkHover) !important;
}

:root[data-stp-dark] .chatComposerSendBtn.formBtn :is(.labelText, i) {
	color: inherit;
}

/* ---- split-button menus (More actions …) ----------------------------------
   main.css:301 paints each option #333 on a #eee divider. :where() keeps the
   framework's (0,2,0), so stpTheme.css `.menuOption.red` (0,3,0) stays red. */
:where(:root[data-stp-dark]) .splitBtnMenu .menuOption {
	color: var(--stpInk);
	border-bottom-color: var(--stpRowDividerColor);
}

/* main.css `section.block > div{color:#333}` (0,1,2): module tiles (Fulfillment
   index), read-only settings values (Payment Fees). Same specificity, later file. */
:where(:root[data-stp-dark]) section.block > div {
	color: var(--stpBody);
}

/* ---- release notes bulletin (framework main.css:324-480, literal light colours) ----
   Release Notes page + the "Newest Updates" popup. Surface/ink from tokens; the
   #255697 accent lifts to the info blue so it reads on dark. */
:root[data-stp-dark] :is(.releaseNotesBulletin, .popUpBox.releaseNotesModal:not(.locationOptions):not(.small)) {
	background: var(--stpSurface);
	color: var(--stpBody);
}

:root[data-stp-dark] :is(.releaseNotesStageBar h1, .releaseNotesSpread h2, .releaseNotesIndex .idx, .releaseNotesIndex .index-count, .releaseNotesIndex .index-count .releaseNotesPos, .releaseNotesVersion) {
	color: var(--stpInk);
}

:root[data-stp-dark] .releaseNotesSpread .body {
	color: var(--stpBody);
}

:root[data-stp-dark] :is(.releaseNotesSpread .meta, .releaseNotesBulletinClose, .releaseNotesIndex .index-count span, .releaseNotesIndex .idx .n, .releaseNotesIndex .idx .m, .releaseNotesPage .releaseNotesStageBar h1, .releaseNotesVersionNavHead, .releaseNotesVersion .when) {
	color: var(--stpMuted);
}

:root[data-stp-dark] :is(.releaseNotesSpread .eyebrow, .releaseNotesSpread .body a, .releaseNotesVersion:hover, .releaseNotesVersion.on .ver) {
	color: #8db8f2;
}

:root[data-stp-dark] .releaseNotesSpread .frame {
	background: var(--stpZebra);
	box-shadow: none;
}

:root[data-stp-dark] :is(.releaseNotesIndex, .releaseNotesVersionNav) {
	background: var(--stpZebra);
	border-color: var(--stpBorder);
}

:root[data-stp-dark] :is(.releaseNotesIndex .index-count, .releaseNotesIndex > button) {
	background: var(--stpHover);
	border-color: var(--stpBorder);
}

:root[data-stp-dark] .releaseNotesIndex > button {
	color: #8db8f2;
}

:root[data-stp-dark] .releaseNotesIndex .idx {
	border-color: var(--stpBorder);
}

:root[data-stp-dark] .releaseNotesIndex .idx:hover {
	background: var(--stpRowHover);
}

:root[data-stp-dark] .releaseNotesIndex .idx.on {
	background: var(--stpSurface);
	box-shadow: inset 0 -3px 0 #8db8f2;
}

:root[data-stp-dark] .releaseNotesDisabled {
	background: var(--stpHover);
	color: var(--stpSecondary);
}
