/* IMS Universal – Light / Dark / Auto theme (JS/Theme.js sets html[data-theme]).
   Dark mode re-maps every page at once (all page colours flip, hue kept), photos/logos/charts are flipped back,
   so no page needs its own dark stylesheet. Printing always uses the light colours. */
html { background: #fff; }
@media screen {
    html[data-theme="dark"] { filter: invert(.9) hue-rotate(180deg); color-scheme: light; }
    html[data-theme="dark"] img, html[data-theme="dark"] video, html[data-theme="dark"] canvas, html[data-theme="dark"] iframe,
    html[data-theme="dark"] picture, html[data-theme="dark"] .th-keep, html[data-theme="dark"] aside.side, html[data-theme="dark"] .mbar, html[data-theme="dark"] [style*="background-image"] { filter: invert(1) hue-rotate(180deg); }
    html[data-theme="dark"] aside.side img, html[data-theme="dark"] aside.side canvas, html[data-theme="dark"] aside.side .th-keep { filter: none; }   /* already flipped back with the menu */
    html[data-theme="dark"] ::-webkit-scrollbar { background: #e8e8e8; }
}
/* the circular reveal when switching (browsers with View Transitions) */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) { animation: th-reveal .55s cubic-bezier(.4, 0, .2, 1); }
@keyframes th-reveal { from { clip-path: circle(0 at var(--th-x, 50%) var(--th-y, 0)); } to { clip-path: circle(var(--th-r, 150vmax) at var(--th-x, 50%) var(--th-y, 0)); } }
@media (prefers-reduced-motion: reduce) { ::view-transition-new(root) { animation: none; } }

/* the switch button (beside the bell, or floating bottom-right on pages without a top bar) */
.th-btn { position: relative; width: 40px; height: 40px; border-radius: 12px; border: 1px solid #E1E8F3; background: #fff; color: #0F1E3D;
    display: inline-grid; place-items: center; cursor: pointer; overflow: hidden; flex: none; }
.th-btn:hover { border-color: #BFD3FA; } .th-btn:focus-visible { outline: 2px solid #2468E6; outline-offset: 2px; }
.th-btn.float { position: fixed; right: 18px; bottom: 18px; z-index: 55; box-shadow: 0 10px 26px -10px rgba(15,30,61,.45); border-radius: 50%; }
.th-btn svg { position: absolute; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
    transition: transform .45s cubic-bezier(.3,1.4,.6,1), opacity .25s; }
.th-btn .sun { transform: none; } .th-btn .moon, .th-btn .auto { transform: translateY(26px) rotate(-90deg); opacity: 0; }
.th-btn[data-mode="dark"] .sun, .th-btn[data-mode="auto"] .sun { transform: translateY(-26px) rotate(90deg); opacity: 0; }
.th-btn[data-mode="dark"] .moon { transform: none; opacity: 1; }
.th-btn[data-mode="auto"] .auto { transform: none; opacity: 1; }
.th-tip { position: fixed; z-index: 90; background: #0F1E3D; color: #fff; font: 600 12px/1 system-ui, sans-serif; padding: 7px 10px; border-radius: 8px;
    pointer-events: none; opacity: 0; transition: opacity .2s; }
.th-tip.show { opacity: 1; }
/* "Install app" pill (shown only when the browser can install the site as an app) */
.th-install { display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 14px; border-radius: 12px; border: 0; cursor: pointer; flex: none;
    background: linear-gradient(135deg, #2468E6, #22A06B); color: #fff; font: 700 13px system-ui, sans-serif; box-shadow: 0 8px 20px -10px rgba(36,104,230,.8);
    animation: th-pop .5s cubic-bezier(.3,1.4,.6,1); }
.th-install svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.th-install.float { position: fixed; right: 68px; bottom: 18px; z-index: 55; border-radius: 20px; }
@keyframes th-pop { from { transform: scale(.6); opacity: 0; } }
@media (display-mode: standalone) { .th-install { display: none !important; } }
/* "Software updated – restart" bar (screens without the bell) */
.th-upd { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 95; display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px);
    background: #0F1E3D; color: #fff; padding: 8px 8px 8px 16px; border-radius: 14px; font: 500 13.5px system-ui, sans-serif; box-shadow: 0 14px 34px -10px rgba(15,30,61,.55);
    animation: th-drop .4s cubic-bezier(.3,1.4,.6,1); }
.th-upd button { border: 0; border-radius: 10px; padding: 8px 14px; background: linear-gradient(135deg, #2468E6, #22A06B); color: #fff; font: 700 13px system-ui; cursor: pointer; flex: none; }
.th-upd button.x { background: transparent; font-size: 20px; padding: 4px 8px; opacity: .7; }
@keyframes th-drop { from { transform: translate(-50%, -30px); opacity: 0; } }
@media print { .th-upd, .th-install, .th-btn, .th-tip { display: none !important; } }

/* ---------- phone fixes (all screens) ---------- */
.mbar .th-btn { border-radius: 12px; }
@media (max-width: 760px) {
    .mbar b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .mbar .ib:last-child { margin-left: 0; }
    .mbar { gap: 8px; }
    .mbar .ib { width: 40px !important; height: 40px !important; flex: none; }
    /* grids and form fields never wider than the screen */
    .card, .form-card, section, .f, .in, [class*="grid"] > *, [class*="layout"] > * { min-width: 0; }
    .cm-layout, [class*="-layout"] { grid-template-columns: minmax(0, 1fr) !important; }
    .flt-grid, .ac-flt { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    input, select, textarea { max-width: 100%; min-width: 0; }
    /* tab strips scroll sideways instead of pushing the page */
    .sec-tabs, .tabs, [role="tablist"] { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .sec-tabs::-webkit-scrollbar, .tabs::-webkit-scrollbar, [role="tablist"]::-webkit-scrollbar { display: none; }
    .sec-tabs > *, .tabs > *, [role="tablist"] > * { flex: none; }
    /* wide tables scroll inside their card */
    .th-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
    img, svg, canvas { max-width: 100%; }
}
