﻿/* ============================================================
   MoSys App Layout — App-specific layout classes
   Reusable components (card, btn, alert, grid, etc.) are in
   _content/Gazprom.UI.Kit/css/components.css
   ============================================================ */

.layout-root.global {
    display: flex;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

.layout-sidebar-shell {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    transition: width var(--transition-normal), flex-basis var(--transition-normal);
}

.layout-root.global.sidebar-collapsed .layout-sidebar-shell {
    width: var(--sidebar-width-collapsed);
    flex-basis: var(--sidebar-width-collapsed);
}

.layout-main {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Header: 3-zone layout (left / center / right) ───── */
.layout-header {
    height: var(--topbar-height);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: 0 var(--space-6);
    background: var(--color-bg-surface);
    border-bottom: 1px solid var(--color-border-default);
}

.layout-header__left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    flex-shrink: 1;
}

.layout-header__center {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-left: auto;
    min-width: 0;
}

.layout-header__right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-shrink: 0;
}

.layout-header__titles {
    min-width: 0;
}

.layout-header__eyebrow {
    font-size: var(--text-2xs);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    line-height: 1.2;
}

.layout-header__project {
    display: block;
    font-size: var(--text-md);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.layout-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    width: 100%;
}

.widget-area {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    padding: var(--space-6);
    background: var(--color-bg-secondary);
}

.page-shell,
.global {
    min-height: 0;
}

.page-shell {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.page-header__left {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.page-header h1 {
    margin: 0;
    font-size: var(--text-2xl);
    font-weight: var(--font-weight-semibold);
    letter-spacing: -0.02em;
}

.page-header p {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

/* ── Home Page Grid ─────────────────────────────────────── */
.home-grid,
.status-strip {
    display: grid;
    gap: var(--grid-gap);
}

.home-grid {
    grid-template-columns: repeat(3, 1fr);
}

.status-strip {
    grid-template-columns: repeat(3, 1fr);
}

.home-radzen-card {
    width: 100%;
    min-height: 100%;
    padding: var(--space-5);
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-lg);
    transition: box-shadow var(--transition-fast);
}

.home-radzen-card:hover {
    box-shadow: var(--shadow-md);
}

.home-radzen-card--hero {
    border-left: 3px solid var(--color-primary);
}

.home-radzen-card h2 {
    margin: 0 0 var(--space-3);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
}

.home-radzen-card p,
.home-radzen-card li {
    margin: 0;
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
}

.home-radzen-card ul {
    margin: 0;
    padding-left: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

@media (max-width: 1024px) {
    .home-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .home-grid,
    .status-strip {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .layout-root.global {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .layout-sidebar-shell,
    .layout-root.global.sidebar-collapsed .layout-sidebar-shell {
        width: 100%;
        flex-basis: auto;
    }

    .widget-area {
        padding: var(--content-padding-mobile);
    }
}

/* ── Radzen body containing-block fix ──────────────────────
 * Radzen renders <RadzenBody> as <div class="rz-body"> with an inline
 * `transform: matrix(1,0,0,1,0,0)` (identity). Even an identity transform
 * makes that div the containing block for position:fixed descendants
 * (CSS spec). gridstack's drag-helper has `position:fixed` and is positioned
 * by viewport coords (e.clientX/Y); when .rz-body scrolls the helper drifts
 * away from the cursor and drop coords go wrong.
 *
 * The identity matrix has no visual effect, so safely zero it out. !important
 * is required because Radzen sets it inline (specificity-wise, inline beats
 * stylesheet rules unless the rule is !important).
 */
.rz-body {
    transform: none !important;
}

/* ── GridStack Dashboard ────────────────────────────────── */

.dashboard-page {
    box-sizing: border-box;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding-bottom: 16px;
}

.dashboard-grid {
    flex: 1 1 auto;
    min-height: 100%;
    width: 100%;
    display: block;
    background: var(--color-bg-secondary);
    padding: var(--space-3);
}

/* Frame wrapping the gridstack root — owns the border (edit-mode-aware) and
 * the single scroll for dashboard content. Stays at rz-body edges even when
 * the dashboard is empty (border visible around full available area). */
.dashboard-grid-frame {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    overflow-y: auto;
    border-radius: var(--radius-md);
}

.dashboard-grid-frame[data-edit-mode="0"] {
    border: 1px solid var(--color-border-default);
}

.dashboard-grid-frame[data-edit-mode="1"] {
    border: 1px solid var(--color-border-focus);
}

/*
 * IMPORTANT: GridStack v12 writes BOTH inline `style` (CSS vars
 * --gs-cell-height etc) AND classes (`gs-12`, `grid-stack-nested`, ...) onto
 * .grid-stack containers. Any Blazor-managed `style=` or *dynamic* `class=`
 * binding on those elements will overwrite gridstack's state on re-render and
 * items collapse to (0,0) / the grid stays hidden by the prerender mask.
 *
 * Dynamic state goes through `data-*` attributes — Blazor patches each
 * attribute separately, so `data-edit-mode` toggling never touches `class`
 * or `style`. `data-gs-ready` is added by gridstackInterop.js after
 * GridStack.init() has run and CSS vars are in place (lifts the mask below).
 */
.dashboard-grid:not([data-gs-ready]),
.mosys-card-grid:not([data-gs-ready]) {
    visibility: hidden;
}



.dashboard-grid .grid-stack-item-content {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    padding: var(--space-3);
    transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.dashboard-grid .grid-stack-item-content:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--color-border-strong);
}

.dashboard-grid .gs-drag-handle:not(.mosys-card-grid) {
    cursor: grab;
    padding: var(--space-1) var(--space-3);
    border-bottom: 1px solid var(--color-border-subtle);
    background: var(--color-bg-tertiary);
    font-size: var(--text-2xs);
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    user-select: none;
    transition: background var(--transition-fast);
}

.dashboard-grid .gs-drag-handle:not(.mosys-card-grid):hover {
    background: var(--color-bg-elevated);
}

.dashboard-grid .gs-drag-handle:not(.mosys-card-grid):active {
    cursor: grabbing;
}

/* Card widget — frame around the nested gridstack. Owns the edit-mode-aware
 * border, border-radius, and the single scroll (same pattern as
 * .dashboard-grid-frame at dashboard level).
 *
 * Trade-off: with `overflow-y: auto` here, gridstack v12 auto-scroll
 * (`updateScrollPosition`) picks this element as the nearest scroll-ancestor
 * of items dragged inside .mosys-card-grid. Because a card is a small
 * container, the drag helper is almost always near its edge, so auto-scroll
 * can fire immediately and the nested grid may scroll while dragging. This
 * is accepted in exchange for keeping the scrollbar inside the card border
 * in both view and edit mode (so the bottom border stays visible). */
.dashboard-grid .grid-stack-item-content.mosys-card-content {
    padding: 0;
    background: var(--color-bg-secondary);
    display: flex;
    flex-direction: column;
    box-shadow: none;
    overflow-y: auto;
    border-radius: var(--radius-lg);
}

.dashboard-grid .grid-stack-item-content.mosys-card-content[data-edit-mode="0"] {
    border: 1px solid var(--color-border-default);
}

.dashboard-grid .grid-stack-item-content.mosys-card-content[data-edit-mode="1"] {
    border: 1px solid var(--color-border-focus);
}

.dashboard-grid .grid-stack-item-content.mosys-card-content:hover {
    box-shadow: none;
}

.mosys-card-grid {
    flex: 1 1 auto;
    min-height: 100%;
    padding: 0;
}

.mosys-card-grid[data-edit-mode="1"] {
    cursor: grab;
}

.mosys-card-grid[data-edit-mode="1"] > .grid-stack-item {
    cursor: auto;
}

.dashboard-grid .mosys-card-grid.gs-drag-handle {
    cursor: grabbing;
}

/* Palette sidebar */
.palette-sidebar {
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

/* Trash zone */
.trash-card {
    background: var(--color-bg-surface) !important;
    border: 2px dashed var(--color-border-strong) !important;
    border-radius: var(--radius-lg) !important;
    height: 100px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color var(--transition-fast),
                background var(--transition-fast),
                box-shadow var(--transition-fast);
}

.trash-card.drag-over {
    border-color: var(--color-error-icon) !important;
    background: var(--color-error-bg) !important;
    box-shadow: var(--shadow-glow-error);
}

.trash-icon {
    color: var(--color-icon-muted);
    font-size: 24px;
    transition: color var(--transition-fast), transform var(--transition-fast);
}

.trash-card.drag-over .trash-icon {
    color: var(--color-error-icon);
    transform: scale(1.15);
}

.trash-label {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    font-weight: var(--font-weight-medium);
}

.trash-card.drag-over .trash-label {
    color: var(--color-error-text);
}

.trash-zone {
    position: absolute;
    inset: 0;
    z-index: 1;
}

/* Palette items */
.gs-palette-item .grid-stack-item-content {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    cursor: grab;
    transition: box-shadow var(--transition-fast),
                border-color var(--transition-fast);
}

.gs-palette-item .grid-stack-item-content:hover {
    border-color: var(--color-primary-muted);
    box-shadow: var(--shadow-sm);
}

.palette-item-card {
    padding: var(--space-2) var(--space-3) !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

/* Dashboard selector bar */
.dashboard-selector {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-3);
    height: 48px;
}

.dashboard-selector__left {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 0 1 360px;
    min-width: 180px;
}

.dashboard-selector__icon {
    color: var(--color-icon-muted);
    font-size: 20px;
    flex-shrink: 0;
}

.dashboard-selector__input {
    flex: 1 1 auto;
    min-width: 0;
}

.dashboard-selector__actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Dropdown compact size */
.dashboard-selector .rz-dropdown {
    height: 32px !important;
    min-height: 32px !important;
}

.dashboard-selector .rz-dropdown .rz-dropdown-label {
    background: transparent;
    padding: var(--space-1) var(--space-3);
    min-height: unset !important;
    line-height: 1.4;
}

.dashboard-selector__separator {
    width: 1px;
    height: 24px;
    background: var(--color-border-default);
    margin: 0 var(--space-1);
    flex-shrink: 0;
}
