/* Dialogs: center relative to main content (accounting for sidebar) */
.mud-dialog-container,
.mud-overlay-dialog {
    padding-left: var(--sidebar-width);
    box-sizing: border-box;
}

/* Dialogs: consistent padding for actions with content */
.mud-dialog-actions {
    padding: 16px 24px !important;
}

/* ========================================================================== */
/* APP GLOBALLY                                                        */
/* ========================================================================== */

:root {
    --topnav-height: 100px;
    --page-gutter: 24px;
    --font-base: 'Outfit', sans-serif;
    --nav-font-weight-regular: 400;
    --nav-font-weight-medium: 500;
    --nav-font-weight-strong: 600;
    --sidebar-width: 72px;

    /* M3 Shape Tokens */
    --m3-shape-none: 0px;
    --m3-shape-xs: 4px;
    --m3-shape-s: 8px;
    --m3-shape-m: 12px;
    --m3-shape-l: 16px;
    --m3-shape-l-inc: 20px;
    --m3-shape-xl: 28px;
    --m3-shape-xl-inc: 32px;
    --m3-shape-xxl: 48px;
    --m3-shape-full: 9999px;
    --m3-motion-duration: 200ms;
    --m3-motion-easing: cubic-bezier(0.2, 0, 0, 1);
}

@media (max-width: 599.98px) {
    :root {
        --topnav-height: 64px;
        --page-gutter: 16px;
        --sidebar-width: 0px;
    }

    .mud-appbar {
        min-height: var(--topnav-height) !important;
    }

    .header-dropdown-menu {
        right: 8px !important;
        top: 50% !important;
        bottom: auto !important;
        transform: translateY(-50%) !important;
    }
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
    height: 100%;
    scrollbar-gutter: stable;
}

body {
    overflow-x: hidden;
}

html:has(body.scroll-locked) {
    overflow-y: hidden;
}

body.scroll-locked,
body.scroll-locked .mud-layout .mud-appbar,
body.scroll-locked .mud-layout .mud-main-content .mud-scroll-to-top {
    padding-right: 0 !important;
}

/* ========================================================================== */
/* SCROLLBAR - thin, theme-aware via MudBlazor palette vars                   */
/* ========================================================================== */

* {
    scrollbar-width: thin;
    scrollbar-color: var(--mud-palette-primary) transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-button {
    display: none;
    width: 0;
    height: 0;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: var(--mud-palette-primary);
    border-radius: 10px;
    border: 3px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--mud-palette-primary-darken);
}

/* ========================================================================== */
/* BUTTON DEFAULTS - lock in consistent text rendering, let MudBlazor handle  */
/* hover/active states natively (background-color overlay + ripple)           */
/* ========================================================================== */

.mud-button-root {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========================================================================== */
/* ADMIN ACTION BUTTONS                                                       */
/* ========================================================================== */

.admin-action-button.mud-button-root {
    border-radius: 8px;
    font-weight: 700;
    text-transform: none;
    box-shadow: none !important;
    border: none !important;
}

.admin-action-button.mud-button-filled {
    box-shadow: none !important;
    border: none !important;
}

.admin-action-button.mud-button-root:hover,
.admin-action-button.mud-button-root:focus-visible,
.admin-action-button.mud-button-root:active {
    box-shadow: none !important;
}

.admin-action-neutral.mud-button-filled {
    background-color: var(--mud-palette-action-disabled-background) !important;
}
.admin-action-neutral.mud-button-filled:hover {
    background-color: var(--mud-palette-action-disabled) !important;
}

.admin-action-button.admin-action-compact {
    min-height: 32px;
}

.admin-action-button.admin-action-icon-only {
    min-width: 32px;
    padding: 4px !important;
}

.admin-action-button.admin-action-icon-only .mud-button-icon-start {
    margin: 0 !important;
    margin-inline-end: 0 !important;
}

/* Let MudBlazor handle button colors via palette */

.home-stat-value {
    white-space: nowrap;
    line-height: 1;
}

/* ========================================================================== */

/* Flat design - remove borders and shadows from containers */
.mud-paper {
    border: none !important;
    box-shadow: none !important;
}

/* Remove all elevation shadows across MudBlazor (drawers, cards, tables, etc.) */
[class*="mud-elevation-"] {
    box-shadow: none !important;
}

/* Dialogs - use BackgroundGray + subtle border to stand out from page background */
.mud-dialog {
    border: 1px solid var(--mud-palette-lines-default) !important;
    box-shadow: none !important;
    background: var(--mud-palette-background-gray);
}

/* Popovers - dropdown menus, selects, autocomplete, date/time pickers */
.mud-popover {
    border: none !important;
    box-shadow: none !important;
    background: var(--mud-palette-background-gray) !important;
}

/* Tooltips */
.mud-tooltip {
    border: 1px solid var(--mud-palette-lines-default) !important;
    box-shadow: none !important;
    background: var(--mud-palette-table-hover) !important;
    color: var(--mud-palette-text-primary) !important;
}

/* Drawer overlay */
.mud-drawer-overlay {
    border: 1px solid var(--mud-palette-lines-default) !important;
    z-index: 1100 !important;
}

/* Custom header dropdown menus (language / theme) */
.header-dropdown-menu {
    border: 1px solid var(--mud-palette-lines-default) !important;
    box-shadow: none !important;
}
.header-dropdown-menu .mud-button-root.mud-button-root {
    border-radius: 0 !important;
    margin: 0 !important;
}

/* Inner details sections inside dialogs - use Tertiary for visual separation */
.mud-dialog .mud-paper {
    background: var(--mud-palette-tertiary);
}

/* Remove shadows from filled buttons */
.mud-button-filled {
    box-shadow: none !important;
}

.mud-button-filled:hover {
    box-shadow: none !important;
}

.mud-layout {
    display: flex;
    flex-direction: column;
}

body {
    font-family: var(--font-base);
    min-height: 100%;
}

.mud-layout > .mud-main-content {
    flex: 1 1 auto;
}

a, .btn-link {
    color: var(--mud-palette-info);
}

h1:focus {
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid #e50000;
}

.validation-message {
    color: #e50000;
    font-size: .85rem;
    font-weight: 600;
    text-align: start;
    margin: 5px;
}

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBh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ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

.mud-tooltip {
    max-width: min(16rem, calc(100vw - 2rem)) !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
    line-height: 1.45;
}

@keyframes admin-banner-slide-in {
    from { opacity: 0; transform: translateY(-100%); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ========================================================================== */
/* ADMIN TABLE SKELETON - shimmer placeholder rows while data loads           */
/* ========================================================================== */

.admin-skeleton-table {
    width: 100%;
}

.admin-skeleton-table thead th {
    padding: 12px 16px;
}

.admin-skeleton-table tbody td {
    padding: 14px 16px;
}

/* ========================================================================== */
/* EMPTY STATE - loading spin animation                                       */
/* ========================================================================== */

@keyframes empty-state-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.empty-state-spin {
    animation: empty-state-spin 1.5s linear infinite;
}

/* ========================================================================== */
/* PAGE ENTRANCE - staggered fade-in for page sections                        */
/* ========================================================================== */

@keyframes page-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* All direct children of the page wrapper */
.page-stagger > * {
    animation: page-fade-in 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

.page-stagger > *:nth-child(1) { animation-delay: 0ms; }
.page-stagger > *:nth-child(2) { animation-delay: 60ms; }
.page-stagger > *:nth-child(3) { animation-delay: 120ms; }
.page-stagger > *:nth-child(4) { animation-delay: 180ms; }
.page-stagger > *:nth-child(5) { animation-delay: 240ms; }
.page-stagger > *:nth-child(6) { animation-delay: 300ms; }
.page-stagger > *:nth-child(n+7) { animation-delay: 360ms; }

/* Admin pages: also stagger deeper MudStack children inside MudContainer */
.page-stagger > .mud-container > .d-flex.flex-column > * {
    animation: page-fade-in 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

.page-stagger > .mud-container > .d-flex.flex-column > *:nth-child(1) { animation-delay: 0ms; }
.page-stagger > .mud-container > .d-flex.flex-column > *:nth-child(2) { animation-delay: 60ms; }
.page-stagger > .mud-container > .d-flex.flex-column > *:nth-child(3) { animation-delay: 120ms; }
.page-stagger > .mud-container > .d-flex.flex-column > *:nth-child(4) { animation-delay: 180ms; }
.page-stagger > .mud-container > .d-flex.flex-column > *:nth-child(5) { animation-delay: 240ms; }
.page-stagger > .mud-container > .d-flex.flex-column > *:nth-child(6) { animation-delay: 300ms; }
.page-stagger > .mud-container > .d-flex.flex-column > *:nth-child(n+7) { animation-delay: 360ms; }

/* ========================================================================== */
/* PULSE INDICATOR (LED style)                                                 */
/* ========================================================================== */

.pulse {
    --size: 12px;
    --color: #00e600;
    position: relative;
    display: inline-block;
    width: var(--size);
    height: var(--size);
    margin: 0 4px;
    border-radius: 50%;
    background-color: var(--color);
    flex: 0 0 auto;
}

.pulse::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background-color: var(--color);
    opacity: 0.6;
    transform: scale(1);
    animation: pulse-ring 1.8s ease-out infinite;
}

.pulse::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 6px var(--color), 0 0 6px var(--color);
}

@keyframes pulse-ring {
    0% { transform: scale(1); opacity: 0.7; }
    70% { transform: scale(2); opacity: 0; }
    100% { transform: scale(2); opacity: 0; }
}

.pulse.green { --color: #22c55e; }
.pulse.orange { --color: #f59e0b; }
.pulse.red { --color: #ef4444; }
.pulse.sm { --size: 8px; }
.pulse.md { --size: 12px; }
.pulse.lg { --size: 16px; }


/* -------------------------------------------------------------------------- */
/* BACK LINK - same nudge, reversed for start-icon (arrow-back)               */
/* -------------------------------------------------------------------------- */

.back-link.mud-button-root {
    overflow: visible;
    padding-left: 8px !important;
}

.back-link .mud-button-icon-start {
    transition: transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.back-link:hover .mud-button-icon-start {
    transform: translateX(-4px);
}

/* -------------------------------------------------------------------------- */
/* APP LIBRARY - square tiles grid                                            */
/* -------------------------------------------------------------------------- */

.app-tile-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.app-tiles-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 8px 0;
    align-items: flex-start;
}

.app-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 120px;
    height: 120px;
    border-radius: 20px;
    background: var(--mud-palette-surface, #fff);
    cursor: pointer;
    transition: background 0.15s ease;
    padding: 0;
    position: relative;
    outline: none;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    border: none;
}

.app-tile:hover {
    background: var(--mud-palette-table-hover, #F4F4F4);
}

.app-tile:active {
    background: var(--mud-palette-action-disabled-background, #EDEDED);
}

.app-tile-icon {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.app-tile-icon svg {
    width: 100%;
    height: 100%;
}

.app-tile-status-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.app-tile-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--mud-palette-text-primary, #212121);
    text-align: center;
    line-height: 1.3;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-tile-tag {
    font-size: 10px;
    font-weight: 600;
    color: var(--mud-palette-primary, #1976D2);
    background: var(--mud-palette-primary-hover, rgba(25,118,210,0.08));
    padding: 2px 10px;
    border-radius: 10px;
    text-align: center;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.app-tile-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 9px;
    font-weight: 600;
    background: var(--mud-palette-success, #4CAF50);
    color: #fff;
    padding: 2px 7px;
    border-radius: 8px;
    line-height: 1.4;
    letter-spacing: 0.02em;
}

.app-tile-badge.stopped {
    background: var(--mud-palette-error, #F44336);
}

.app-tile-stopped {
    opacity: 0.4;
}

.app-tile-name-stopped {
    opacity: 0.4;
}

.app-tile-badge.installing {
    background: var(--mud-palette-info, #2196F3);
}

/* App detail dialog icon */
.app-detail-icon {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.app-detail-icon svg {
    width: 100%;
    height: 100%;
}

/* Screenshot gallery in detail dialog */
.screenshot-gallery {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 4px 0 12px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.screenshot-frame {
    flex-shrink: 0;
    width: 200px;
    height: 120px;
    border-radius: 8px;
    overflow: hidden;
    scroll-snap-align: start;
    cursor: pointer;
    position: relative;
    transition: box-shadow 0.15s ease;
}

.screenshot-frame:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.screenshot-frame::after {
    content: "View";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.03em;
    color: #fff;
    background: rgba(0,0,0,0.4);
    opacity: 0;
    transition: opacity 0.15s ease;
}

.screenshot-frame:hover::after {
    opacity: 1;
}

.screenshot-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: filter 0.15s ease;
}

.screenshot-frame:hover .screenshot-img {
    filter: brightness(0.85);
}

body.dark-mode .screenshot-frame {
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

body.dark-mode .screenshot-frame:hover {
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

/* ========================================================================== */
/* HELP PAGE - readability improvements for documentation text                 */
/* ========================================================================== */

.help-text {
    line-height: 1.75;
    max-width: 72ch;
}

.help-page .mud-chip {
    font-size: 0.85rem;
    padding: 4px 14px;
}

/* ========================================================================== */
/* M3 EXPRESSIVE SHAPE TOKENS                                                 */
/* ========================================================================== */

/* ---------- Buttons (MudButton & MudIconButton) ---------- */

/* Consistent button spacing - compensates for pill curvature eating into visual gap */
.mud-button-root {
    margin: 2px !important;
}

/* Fully rounded at all times - double class beats inline style from MudTheme */
.mud-button-root.mud-button-root {
    border-radius: var(--m3-shape-full) !important;
}

/* Square profile resting state */
.mud-button-root.m3-btn-square {
    border-radius: var(--m3-shape-l) !important;
}

.mud-button-root.m3-btn-square.mud-button-size-small {
    border-radius: var(--m3-shape-m) !important;
}

/* Ripple inherits button shape */
.mud-ripple {
    border-radius: inherit;
}

/* Switch button reset - isolate from all global button overrides */
.mud-switch-base.mud-switch-base {
    margin: 0 !important;
    border-radius: 50% !important;
}

/* ---------- Chips (MudChip) ---------- */

.mud-chip {
    border-radius: var(--m3-shape-s) !important;
    border: none !important;
}

/* ---------- Card (MudCard) ---------- */

.mud-card {
    border-radius: var(--m3-shape-l) !important;
}

/* ---------- Tables & Data Grids (MudTable, MudDataGrid) ---------- */

/* Outer container - subtle rounding prevents data clipping */
.mud-table-container {
    border-radius: var(--m3-shape-xs);
}

/* Cells and rows - square */
.mud-table-cell,
.mud-table-row {
    border-radius: var(--m3-shape-none) !important;
}

/* ---------- Utility Classes ---------- */

/* Square profile button modifier (use on buttons in layout-dense zones) */
.m3-btn-square {
    /* Applied alongside .mud-button-root above */
}

/* Nested element roundness: Outer Radius - Internal Padding = Inner Radius */
.m3-nested-image {
    border-radius: calc(var(--m3-shape-l) - 4px);
}



