/* Tharsol Connect (one app, Connect:TicketsInApp): the ticket screens inside Connect's own pages.

   The portal's stylesheets (t/css/*.css, loaded by App.razor with the switch on) were written for their own page:
   <body class="tms">, a fixed rail on the left, a fixed top bar, and the document scrolling. Inside Connect the body is
   Connect's, so the screens get their own root (Tms.Client Layout/InConnectRoot.razor):

     .tms.tms-inapp.tms-inapp-scroll   what body.tms was, and the box that scrolls (tms-interop.js reads the page's
                                       scroll position from .tms-inapp-scroll);
     .tms-inapp-chrome                 staff: inside Connect's work area, under Connect's title bar and beside its
                                       rail; the portal draws only its crumb bar (sticky) and canvas;
     .tms-inapp-own                    clients: over the whole window, the portal's own rail and top bar as on the
                                       WebAssembly page.

   Only the shell is placed here; every page keeps the portal's own styles. */

/* ---- the root: what body.tms gave the WebAssembly page --------------------------------------------------------- */
.tms-inapp {
    background: var(--tms-bg);
    color: var(--tms-text);
    font-family: var(--tms-font);
    font-size: var(--tms-fs-body);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: auto;
    overscroll-behavior: contain;
    /* Distance from the window's top and bottom to this box, for the portal's few "rest of the window" heights. */
    --tms-inapp-top: 0px;
    --tms-inapp-bottom: 0px;
}

/* ---- clients: the portal's own chrome over the whole window ---------------------------------------------------- */
.tms-inapp-own {
    position: fixed;
    inset: 0;
}

/* The workspace tab strip's height, for the fixed and "rest of the window" sizes below (none on phones: no strip). */
body:has([data-ws-strip]) {
    --ws-strip-h: 42px;
}

/* ---- staff: inside Connect's chrome --------------------------------------------------------------------------- */
.tms-inapp-chrome {
    /* No portal rail here: everything the portal offsets by its rail's width starts at the box's edge. */
    --tms-rail-w: 0px;
    /* Connect's title bar and, when shown, the workspace tab strip above (WorkspaceStrip.razor.css: 42px); the work
       area's bottom padding below (MainLayout.razor.css). Without the strip's height the condensed ticket header was
       placed behind the strip and the crumb bar, so it never showed. */
    --tms-inapp-top: calc(50px + var(--ws-strip-h, 0px));
    --tms-inapp-bottom: 10px;
    flex: 1;
    min-height: 0;
    position: relative;
    border-radius: 10px;
    border: 1px solid var(--tms-border);
}

    /* The crumb bar heads the box and stays while the page scrolls under it. */
    .tms-inapp-chrome .tms-topbar {
        position: sticky;
        top: 0;
        left: auto;
        right: auto;
    }

    .tms-inapp-chrome .tms-canvas {
        margin-left: 0;
        padding-top: 0;
    }

    /* The ticket's condensed header strip is fixed to the window: under Connect's title bar and the crumb bar, beside
       Connect's rail (56px). */
    .tms-inapp-chrome .tms-t-stuck {
        top: calc(var(--tms-inapp-top) + var(--tms-topbar-h));
        left: calc(56px + 20px);
        right: 30px;
    }

/* ---- heights that were "the rest of the window" ---------------------------------------------------------------- */
.tms-inapp .tms-chat {
    height: calc(100dvh - var(--tms-inapp-top) - var(--tms-inapp-bottom) - var(--tms-topbar-h) - 2px);
}

@media (min-width: 1081px) {
    .tms-inapp .tms-props {
        max-height: calc(100vh - var(--tms-inapp-top) - var(--tms-inapp-bottom) - var(--tms-topbar-h) - 32px);
    }
}

/* ---- phone: Connect has no title bar or rail there, but its bottom tabs (MainLayout.razor.css, max-width 767px) */
@media (max-width: 767px) {
    .tms-inapp-chrome {
        --tms-inapp-top: 0px;
        /* Connect's bottom tabs (66px measured, a 1px border, 4px + 6px padding) and the iOS home indicator. */
        --tms-inapp-bottom: calc(67px + env(safe-area-inset-bottom, 0px));
        border: 0;
        border-radius: 0;
    }

        .tms-inapp-chrome .tms-t-stuck {
            left: 10px;
            right: 10px;
        }
}

@media (max-width: 720px) {
    /* The portal's rail bar isn't there with Connect's chrome: nothing to clear at the bottom. */
    .tms-inapp-chrome .tms-canvas {
        padding-bottom: 0;
    }

    .tms-inapp-chrome .tms-chat,
    .tms-inapp-chrome .tms-chat.has-side,
    .tms-inapp-chrome .tms-chat.no-list.has-side {
        height: calc(100dvh - var(--tms-inapp-bottom) - var(--tms-topbar-h));
    }

    .tms-inapp-own .tms-chat,
    .tms-inapp-own .tms-chat.has-side,
    .tms-inapp-own .tms-chat.no-list.has-side {
        height: calc(100dvh - var(--tms-topbar-h) - var(--tms-railbar-h) - env(safe-area-inset-bottom, 0px));
    }
}

/* ---- backgrounds (Settings -> Appearance -> Backgrounds; the TMS portal's backgrounds, header ribbon by default) ----
   With a background on, the screens' root lets it through (MainLayout's layer: css/textures.css), the crumb bar is
   frosted as on the portal's own page, and with "Show the background through cards and panels" cards and panels follow
   Panel opacity and Card blur, as the portal's did (t/css/tms-backgrounds.css). Modals, menus, inputs and buttons stay
   solid; the frost is a layer behind each card (its ::after), never a backdrop-filter on the card, so the menus and
   dialogs inside open where they should. */
html[data-texture] .tms-inapp {
    background: transparent;
}

    html[data-texture] .tms-inapp .tms-topbar {
        background: color-mix(in srgb, var(--tms-surface) 76%, transparent);
        -webkit-backdrop-filter: blur(12px) saturate(1.2);
        backdrop-filter: blur(12px) saturate(1.2);
    }

html[data-panels] .tms-inapp .tms-canvas :is(.tms-card, .tms-kpi, .tms-grid-scroll, .tms-props,
    .tms-rmd-band, .tms-perf-stat, .tms-bd-box) {
    background: color-mix(in srgb, var(--tms-surface) var(--panel-alpha), transparent);
}

html[data-panels] .tms-inapp .tms-canvas :is(.tms-cf, .tms-msg-body, .tms-tile, .tms-card-row) {
    background: color-mix(in srgb, var(--tms-surface) calc(var(--panel-alpha) + (100% - var(--panel-alpha)) * .35), transparent);
}

html[data-panels] .tms-inapp .tms-canvas .tms-grid-table thead th {
    background: color-mix(in srgb, var(--tms-surface) 94%, transparent);
}

/* Card blur (0-100: 0-20px). Only drawn above 0, and never on the repeated small items (messages, tiles, rows). */
:where(html[data-panels][data-panel-blur] .tms-inapp .tms-canvas) :where(.tms-card, .tms-kpi, .tms-grid-scroll, .tms-props,
    .tms-rmd-band, .tms-perf-stat, .tms-bd-box, .tms-cf) {
    position: relative;
}

html[data-panels][data-panel-blur] .tms-inapp .tms-canvas :is(.tms-card, .tms-kpi, .tms-grid-scroll, .tms-props,
    .tms-rmd-band, .tms-perf-stat, .tms-bd-box, .tms-cf)::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    pointer-events: none;
    -webkit-backdrop-filter: blur(calc(var(--panel-blur) * .2px));
    backdrop-filter: blur(calc(var(--panel-blur) * .2px));
}

@media (prefers-reduced-transparency: reduce) {
    html[data-panels] .tms-inapp .tms-canvas :is(.tms-card, .tms-kpi, .tms-grid-scroll, .tms-props, .tms-rmd-band,
        .tms-perf-stat, .tms-bd-box, .tms-cf, .tms-msg-body, .tms-tile, .tms-card-row),
    html[data-texture] .tms-inapp .tms-topbar {
        background: var(--tms-surface);
    }

    html[data-panels][data-panel-blur] .tms-inapp .tms-canvas :is(.tms-card, .tms-kpi, .tms-grid-scroll, .tms-props,
        .tms-rmd-band, .tms-perf-stat, .tms-bd-box, .tms-cf)::after {
        display: none;
    }
}

/* Overlays stay solid: a dialog or sheet (on a phone the filter and other dialogs are bottom sheets) and the chat's
   side drawer are laid over the page, so the see-through and frosted card rules above stop at them; only cards that
   sit on the page itself show the background through. */
html[data-panels] .tms-inapp .tms-chat-side,
html[data-panels] .tms-inapp :is(.tms-modal-backdrop, .tms-chat-side) :is(.tms-card, .tms-kpi, .tms-grid-scroll, .tms-props,
    .tms-rmd-band, .tms-perf-stat, .tms-bd-box, .tms-cf, .tms-msg-body, .tms-tile, .tms-card-row) {
    background: var(--tms-surface);
}

html[data-panels][data-panel-blur] .tms-inapp :is(.tms-modal-backdrop, .tms-chat-side) :is(.tms-card, .tms-kpi, .tms-grid-scroll,
    .tms-props, .tms-rmd-band, .tms-perf-stat, .tms-bd-box, .tms-cf)::after {
    display: none;
}

/* ---- the ticket screens' settings embedded in Connect's Settings page (Components/Settings/TicketsSettingsHost) ---- */
.tms.tms-embed {
    background: transparent;
    color: inherit;
    font-family: var(--tms-font);
    font-size: var(--tms-fs-body);
    line-height: 1.5;
}

    .tms.tms-embed > .tms-card:first-child,
    .tms.tms-embed > section.tms-card:first-child {
        margin-top: 0 !important;
    }

/* A ticket page that failed (TicketScreens' ErrorBoundary): a tinted notice in place of the page. */
.tickets-failed {
    margin: 24px;
    padding: 16px 18px;
    border-radius: 12px;
    background: color-mix(in srgb, var(--warn, #c88a12) 12%, transparent);
    color: var(--text);
    border: 1px solid color-mix(in srgb, var(--warn, #c88a12) 40%, transparent);
}

    .tickets-failed p {
        margin: 0 0 8px;
    }

    .tickets-failed button {
        margin-top: 4px;
        padding: 6px 14px;
        border-radius: 8px;
        border: 1px solid var(--border);
        background: var(--surface);
        color: var(--text);
        cursor: pointer;
    }
