/*
 * Shared PrimeFaces defaults for dark resident PWA at every viewport size.
 * :where keeps classification out of specificity; business-view colors win.
 * Only standard PF colors/states are changed, never layout or JS behavior.
 */
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) {
    --ian-pf-bg: #101012;
    --ian-pf-bg-raised: #1c1c1e;
    --ian-pf-bg-subtle: #202a32;
    --ian-pf-border: #38383a;
    --ian-pf-border-strong: #48484a;
    --ian-pf-text: #f5f5f7;
    --ian-pf-text-muted: #a1a1aa;
    --ian-pf-accent: #0a84ff;
    --ian-pf-accent-hover: #006edc;
    --ian-pf-selection: #1c2c3a;
    --ian-pf-error: #ff6961;
    --ian-pf-error-bg: #321c1a;
    --ian-pf-error-border: #7a312d;
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) {
    color-scheme: dark;
}

/* Includes input overlays and password feedback appended directly to body. */
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(
    .ui-dialog, .ui-overlaypanel, .ui-sidebar,
    .ui-selectonemenu-panel, .ui-autocomplete-panel, .ui-autocomplete-itemtip,
    .ui-datepicker, .ui-menu,
    .ui-password-panel.ui-state-highlight
) {
    border-color: var(--ian-pf-border);
    background: var(--ian-pf-bg);
    color: var(--ian-pf-text);
    text-shadow: none;
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(
    .ui-dialog-titlebar, .ui-dialog-content, .ui-dialog-buttonpane,
    .ui-overlaypanel-content, .ui-sidebar-content,
    .ui-datepicker-header, .ui-datepicker-buttonpane,
    .ui-fileupload-content, .ui-fileupload-buttonbar,
    .ui-selectonemenu-items-wrapper, .ui-selectonemenu-items,
    .ui-autocomplete-items,
    .ui-menu .ui-menu-list, .ui-menu .ui-submenu-header,
    .ui-panel, .ui-panel-content, .ui-panel-titlebar,
    .ui-panelgrid, .ui-panelgrid-content, .ui-panelgrid-cell,
    .ui-tabs, .ui-tabs-panel, .ui-tabs-nav,
    .ui-accordion-content, .ui-accordion-header,
    .ui-datatable, .ui-datatable-tablewrapper,
    .ui-paginator.ui-widget-header
) {
    border-color: var(--ian-pf-border);
    background-color: var(--ian-pf-bg);
    background-image: none;
    color: var(--ian-pf-text);
    text-shadow: none;
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) .ui-datatable :is(
    th, td, .ui-datatable-header, .ui-datatable-footer
) {
    border-color: var(--ian-pf-border);
    background: var(--ian-pf-bg);
    color: var(--ian-pf-text);
    text-shadow: none;
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) .ui-datatable tbody tr:nth-child(even) > td {
    background: var(--ian-pf-bg-raised);
}

/* Match PF's standard state classes without taking priority over view rules. */
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(
    .ui-inputfield.ui-state-default, .ui-selectonemenu.ui-state-default,
    .ui-selectonemenu .ui-selectonemenu-label,
    .ui-autocomplete .ui-autocomplete-input,
    .ui-autocomplete-multiple-container.ui-inputfield
) {
    border-color: var(--ian-pf-border-strong);
    background: #000;
    color: var(--ian-pf-text);
    box-shadow: none;
    text-shadow: none;
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) .ui-inputfield::placeholder {
    color: var(--ian-pf-text-muted);
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(
    .ui-inputfield.ui-state-focus, .ui-selectonemenu.ui-state-focus,
    .ui-inputfield:focus
) {
    border-color: var(--ian-pf-accent);
    box-shadow: 0 0 0 3px rgba(10, 132, 255, .22);
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(
    .ui-selectonemenu .ui-selectonemenu-trigger,
    .ui-autocomplete .ui-autocomplete-dropdown,
    .ui-datepicker select.ui-datepicker-month,
    .ui-datepicker select.ui-datepicker-year
) {
    border-color: var(--ian-pf-border-strong);
    background: var(--ian-pf-bg-raised);
    color: var(--ian-pf-text);
    text-shadow: none;
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(
    .ui-selectonemenu-panel .ui-selectonemenu-item,
    .ui-autocomplete-panel .ui-autocomplete-item,
    .ui-menu .ui-menuitem-link,
    .ui-datepicker-calendar td a,
    .ui-datepicker-calendar td span
) {
    border-color: transparent;
    background: var(--ian-pf-bg);
    color: var(--ian-pf-text);
    text-shadow: none;
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) .ui-autocomplete-panel .ui-autocomplete-table :is(th, td) {
    border-color: var(--ian-pf-border);
    background: inherit;
    color: inherit;
    text-shadow: none;
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(
    .ui-selectonemenu-panel .ui-selectonemenu-item,
    .ui-autocomplete-panel .ui-autocomplete-item,
    .ui-menu .ui-menuitem-link,
    .ui-datepicker-calendar td a
):where(.ui-state-hover, .ui-state-highlight, .ui-state-active, :hover, :focus) {
    border-color: var(--ian-pf-border-strong);
    background: var(--ian-pf-selection);
    color: var(--ian-pf-text);
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) .ui-autocomplete .ui-autocomplete-token {
    border-color: var(--ian-pf-border-strong);
    background: var(--ian-pf-selection);
    color: var(--ian-pf-text);
    text-shadow: none;
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(
    .ui-password-panel .ui-password-info,
    .ui-autocomplete .ui-autocomplete-token-label,
    .ui-autocomplete-panel .ui-autocomplete-emptyMessage,
    .ui-autocomplete-panel .ui-autocomplete-group
) {
    color: var(--ian-pf-text);
}

/* Neutral widgets only; resident primary/cancel/avatar styles stay stronger. */
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(
    .ui-button.ui-state-default,
    .ui-dialog-titlebar-close, .ui-panel-titlebar-icon,
    .ui-tabs-nav > li, .ui-accordion-header,
    .ui-paginator .ui-paginator-page, .ui-paginator .ui-paginator-first,
    .ui-paginator .ui-paginator-prev, .ui-paginator .ui-paginator-next,
    .ui-paginator .ui-paginator-last,
    .ui-paginator .ui-paginator-rpp-options,
    .ui-chkbox-box, .ui-radiobutton-box
) {
    border-color: var(--ian-pf-border-strong);
    background: var(--ian-pf-bg-raised);
    color: var(--ian-pf-text);
    background-image: none;
    text-shadow: none;
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(
    .ui-button.ui-state-default,
    .ui-dialog-titlebar-close, .ui-panel-titlebar-icon,
    .ui-tabs-nav > li, .ui-accordion-header,
    .ui-paginator .ui-paginator-page, .ui-paginator .ui-paginator-first,
    .ui-paginator .ui-paginator-prev, .ui-paginator .ui-paginator-next,
    .ui-paginator .ui-paginator-last
):where(.ui-state-hover, .ui-state-focus, :hover, :focus-visible):where(:not(.ui-state-disabled)) {
    border-color: var(--ian-pf-accent);
    background: var(--ian-pf-bg-subtle);
    color: var(--ian-pf-text);
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(
    .ui-button.ui-state-active,
    .ui-tabs .ui-tabs-nav > li.ui-state-active, .ui-accordion-header.ui-state-active,
    .ui-paginator .ui-paginator-page:where(.ui-state-active),
    .ui-radiobutton-box.ui-state-active
) {
    border-color: var(--ian-pf-accent);
    background: var(--ian-pf-selection);
    color: var(--ian-pf-text);
}
/* ianthemes.css forces a white checkbox with !important; override only that
   legacy property, not the generic defaults or any business control. */
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) .ui-chkbox-box {
    background-color: var(--ian-pf-bg-raised) !important;
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) .ui-chkbox-box.ui-state-active {
    background-color: var(--ian-pf-accent) !important;
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(.ui-chkbox-icon, .ui-radiobutton-icon) {
    filter: brightness(0) invert(1);
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) .ui-datepicker-calendar td a.ui-state-active {
    border-color: var(--ian-pf-accent);
    background: var(--ian-pf-accent);
    color: #fff;
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(
    .ui-inputfield.ui-state-error, .ui-selectonemenu.ui-state-error
) {
    border-color: var(--ian-pf-error-border);
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) :is(
    .ui-widget-overlay, .ui-dialog-mask, .ui-blockui
) {
    background: rgba(0, 0, 0, .78);
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) .ui-blockui-content {
    border-color: var(--ian-pf-border);
    background: var(--ian-pf-bg-raised);
    color: var(--ian-pf-text);
}
html:where([data-ian-surface^="pwa-"][data-ian-theme="dark"]) body:where(.resident-panel) .ui-state-disabled {
    opacity: .55;
}

/* Preserve the pre-existing desktop styling of other panels; this task
   expands the shared defaults only for resident PWA, never staff mobile. */
@media (display-mode: standalone) and (min-width: 761px) and (prefers-color-scheme: dark) {
html {
    --ian-pf-bg: #101012;
    --ian-pf-bg-raised: #1c1c1e;
    --ian-pf-bg-subtle: #202a32;
    --ian-pf-border: #38383a;
    --ian-pf-border-strong: #48484a;
    --ian-pf-text: #f5f5f7;
    --ian-pf-text-muted: #a1a1aa;
    --ian-pf-accent: #0a84ff;
    --ian-pf-accent-hover: #006edc;
    --ian-pf-selection: #1c2c3a;
    --ian-pf-error: #ff6961;
    --ian-pf-error-bg: #321c1a;
    --ian-pf-error-border: #7a312d;
}

/* Kontenery PrimeFaces, również te dopinane bezpośrednio do body. */
html body:where(:not(.resident-panel)) :is(
    .ui-dialog,
    .ui-overlaypanel,
    .ui-sidebar,
    .ui-selectonemenu-panel,
    .ui-autocomplete-panel,
    .ui-datepicker,
    .ui-menu
) {
    border-color: var(--ian-pf-border);
    background: var(--ian-pf-bg);
    color: var(--ian-pf-text);
    text-shadow: none;
}

html body:where(:not(.resident-panel)) :is(
    .ui-dialog-titlebar,
    .ui-dialog-content,
    .ui-dialog-buttonpane,
    .ui-overlaypanel-content,
    .ui-sidebar-content,
    .ui-datepicker-header,
    .ui-fileupload-content,
    .ui-fileupload-buttonbar
) {
    border-color: var(--ian-pf-border);
    background: var(--ian-pf-bg);
    color: var(--ian-pf-text);
}

/* Panele, zakładki, akordeony i tabele renderowane wewnątrz aplikacji. */
html body:where(:not(.resident-panel)) :is(
    .ui-panel,
    .ui-panel-content,
    .ui-panel-titlebar,
    .ui-tabs,
    .ui-tabs-panel,
    .ui-tabs-nav,
    .ui-accordion-content,
    .ui-accordion-header,
    .ui-datatable,
    .ui-datatable-tablewrapper
) {
    border-color: var(--ian-pf-border);
    background-color: var(--ian-pf-bg);
    color: var(--ian-pf-text);
    text-shadow: none;
}

html body:where(:not(.resident-panel)) .ui-datatable :is(th, td),
html body:where(:not(.resident-panel)) .ui-datatable :is(.ui-datatable-header, .ui-datatable-footer) {
    border-color: var(--ian-pf-border);
    background: var(--ian-pf-bg);
    color: var(--ian-pf-text);
    text-shadow: none;
}
html body:where(:not(.resident-panel)) .ui-datatable tbody tr:nth-child(even) > td {
    background: var(--ian-pf-bg-raised);
}

/* Pola formularzy i listy rozwijane. */
html body:where(:not(.resident-panel)) :is(
    .ui-inputfield,
    .ui-selectonemenu,
    .ui-selectonemenu-label,
    .ui-autocomplete-input,
    .ui-autocomplete-multiple-container
) {
    border-color: var(--ian-pf-border-strong);
    background: #000;
    color: var(--ian-pf-text);
    box-shadow: none;
    text-shadow: none;
}
html body:where(:not(.resident-panel)) .ui-inputfield::placeholder { color: var(--ian-pf-text-muted); }
html body:where(:not(.resident-panel)) :is(.ui-inputfield, .ui-selectonemenu).ui-state-focus,
html body:where(:not(.resident-panel)) .ui-inputfield:focus {
    border-color: var(--ian-pf-accent);
    box-shadow: 0 0 0 3px rgba(10, 132, 255, .22);
}
html body:where(:not(.resident-panel)) .ui-selectonemenu-trigger {
    border-color: var(--ian-pf-border-strong);
    background: var(--ian-pf-bg-raised);
    color: var(--ian-pf-text-muted);
}

/* Wspólne stany elementów wybieralnych. */
html body:where(:not(.resident-panel)) :is(
    .ui-selectonemenu-item,
    .ui-autocomplete-item,
    .ui-menuitem-link,
    .ui-datepicker-calendar td a
) {
    border-color: transparent;
    background: var(--ian-pf-bg);
    color: var(--ian-pf-text);
    text-shadow: none;
}
html body:where(:not(.resident-panel)) :is(
    .ui-selectonemenu-item,
    .ui-autocomplete-item,
    .ui-menuitem-link,
    .ui-datepicker-calendar td a
):is(.ui-state-hover, .ui-state-highlight, :hover, :focus) {
    border-color: var(--ian-pf-border-strong);
    background: var(--ian-pf-selection);
    color: var(--ian-pf-text);
}

/* Walidacja i powiadomienia. */
html body:where(:not(.resident-panel)) .ui-outputlabel.ui-state-error {
    border: 0;
    background: transparent;
    box-shadow: none;
    color: var(--ian-pf-text);
}
html body:where(:not(.resident-panel)) :is(.ui-message-error, .ui-messages-error) {
    border-color: var(--ian-pf-error-border);
    background: var(--ian-pf-error-bg);
    color: var(--ian-pf-error);
    text-shadow: none;
}
html body:where(:not(.resident-panel)) .ui-growl .ui-growl-item-container {
    border-color: var(--ian-pf-border);
    border-left-color: var(--notice-color);
    background: var(--ian-pf-bg-raised);
    color: #d1d1d6;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .5);
    text-shadow: none;
}
html body:where(:not(.resident-panel)) .ui-growl .ui-growl-title { color: var(--ian-pf-text); }
html body:where(:not(.resident-panel)) .ui-growl .ui-growl-icon-close { color: var(--ian-pf-text-muted); }

/* Maski, blokady i stany nieaktywne. */
html body:where(:not(.resident-panel)) :is(.ui-widget-overlay, .ui-dialog-mask, .ui-blockui) {
    background: rgba(0, 0, 0, .78);
}
html body:where(:not(.resident-panel)) .ui-blockui-content {
    border-color: var(--ian-pf-border);
    background: var(--ian-pf-bg-raised);
    color: var(--ian-pf-text);
}
html body:where(:not(.resident-panel)) .ui-state-disabled {
    opacity: .55;
}

/* Domyślne neutralne kontrolki; działania główne zachowują klasy widoków. */
html body:where(:not(.resident-panel)) :is(
    .ui-dialog-titlebar-close,
    .ui-panel-titlebar-icon,
    .ui-tabs-nav > li,
    .ui-accordion-header
) {
    border-color: var(--ian-pf-border-strong);
    background: var(--ian-pf-bg-raised);
    color: var(--ian-pf-text);
    text-shadow: none;
}
}

/* Komunikaty korzystają z motywu PWA niezależnie od rozmiaru ekranu. */
html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body .ui-growl .ui-growl-item-container {
    --notice-color: #5ac8fa;
    --notice-tint: #152b3d;
    background: #182129 !important;
    border-color: #455460;
    border-left-color: var(--notice-color);
    color: #c5ced6;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .5);
    text-shadow: none;
}
html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body .ui-growl .ui-growl-warn { --notice-color: #f0d89a; --notice-tint: #2b2517; }
html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body .ui-growl :is(.ui-growl-error, .ui-growl-fatal) { --notice-color: #ff9a93; --notice-tint: #321c1a; }
html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body .ui-growl .ui-growl-success { --notice-color: #75f29b; --notice-tint: #102719; }
html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body .ui-growl .ui-growl-title { color: #edf2f5; }
html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body .ui-growl .ui-growl-message p { color: #c5ced6; }
html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body .ui-growl .ui-growl-image { background: var(--notice-tint); color: var(--notice-color); }
html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body .ui-growl .ui-growl-icon-close { color: #a9b5be; }
html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body .ui-growl .ui-growl-icon-close:hover { color: #edf2f5; }
html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body .ui-growl .ui-growl-icon-close:focus-visible { outline: 2px solid #5ac8fa; outline-offset: -4px; border-radius: 8px; }

html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body .ui-outputlabel.ui-state-error {
    background: transparent !important;
    border: 0;
    box-shadow: none;
    color: #ff9a93;
}
html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body :is(.ui-message-error, .ui-messages-error, .ui-message-fatal, .ui-messages-fatal) {
    background: #321c1a;
    border-color: #7a312d;
    color: #ff9a93;
    text-shadow: none;
}
html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body :is(.ui-message-warn, .ui-messages-warn) { background: #2b2517; border-color: #8b6a26; color: #f0d89a; }
html[data-ian-surface^="pwa-"][data-ian-theme="dark"] body :is(.ui-message-info, .ui-messages-info) { background: #152b3d; border-color: #406580; color: #8acfff; }
