/* MenhirWMS - App styles */

html, body {
    font-family: 'Inter', 'Roboto', 'Helvetica Neue', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== Scrollbar customization ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: #94a3b8 transparent;
}

/* ===== Loading placeholder ===== */
.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}

.loading-progress circle {
    fill: none;
    stroke: #4f46e5;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: #e2e8f0;
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.42), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

/* ===== Accessibility ===== */

/* Skip-to-content link (visible only on focus) */
.skip-to-content {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    padding: 8px 16px;
    background: #4f46e5;
    color: #fff;
    border-radius: 0 0 4px 4px;
    text-decoration: none;
    font-weight: 600;
    transition: top 0.2s;
}

.skip-to-content:focus {
    top: 0;
}

/* Focus-visible ring for keyboard navigation */
*:focus-visible {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

/* Remove default outline for mouse users */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===== Responsive Design ===== */

/* DataGrid horizontal scroll on small screens */
.mud-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Sidebar - hide on mobile */
@media (max-width: 960px) {
    .mud-drawer--open.mud-drawer-mini {
        width: 0 !important;
    }

    /* Appbar scope selector: reduce width on tablet */
    .mud-appbar .mud-autocomplete {
        max-width: 200px !important;
    }

    /* Stack page header actions vertically on small screens */
    .page-header-actions {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 600px) {
    /* Reduce padding on mobile */
    .mud-main-content {
        padding: 8px !important;
    }

    /* Hide scope selector on very small screens */
    .mud-appbar .mud-autocomplete,
    .mud-appbar .mud-chip {
        display: none !important;
    }

    /* Full-width dialogs on mobile */
    .mud-dialog {
        margin: 8px !important;
        max-width: calc(100vw - 16px) !important;
    }

    /* Stack form fields vertically */
    .form-row {
        flex-direction: column;
    }
}

/* Print styles */
@media print {
    .mud-drawer,
    .mud-appbar,
    .mud-snackbar-provider,
    .skip-to-content,
    .no-print {
        display: none !important;
    }

    .mud-main-content {
        padding: 0 !important;
        margin: 0 !important;
    }

    body {
        background: #fff !important;
        color: #000 !important;
    }
}

/* ===== Utility classes ===== */

/* Visually hidden but accessible to screen readers */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Truncate text with ellipsis */
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Responsive table wrapper */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Content area min-height to prevent footer jumping */
.mud-main-content {
    min-height: calc(100vh - 64px);
}

/* ===== Dashboard Grid (GridStack) ===== */

.grid-stack {
    min-height: 200px;
}

.grid-stack-item-content {
    inset: 0;
    overflow: hidden;
    border-radius: 4px;
}

/* Edit mode visual feedback */
.grid-stack .grid-stack-item.ui-draggable-dragging > .grid-stack-item-content,
.grid-stack .grid-stack-item.ui-resizable-resizing > .grid-stack-item-content {
    opacity: 0.85;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* Placeholder while dragging */
.grid-stack .grid-stack-placeholder > .placeholder-content {
    background: rgba(79, 70, 229, 0.1);
    border: 2px dashed #4f46e5;
    border-radius: 4px;
}

/* Resize handle styling */
.grid-stack > .grid-stack-item > .ui-resizable-se {
    width: 20px;
    height: 20px;
    background: none;
    right: 4px;
    bottom: 4px;
}

.grid-stack > .grid-stack-item > .ui-resizable-se::after {
    content: '';
    position: absolute;
    right: 0;
    bottom: 0;
    width: 12px;
    height: 12px;
    border-right: 2px solid #94a3b8;
    border-bottom: 2px solid #94a3b8;
    border-radius: 0 0 2px 0;
}

/* Mobile: single column */
@media (max-width: 600px) {
    .grid-stack {
        --gs-columns: 1 !important;
    }

    .grid-stack > .grid-stack-item {
        width: 100% !important;
        position: relative !important;
        left: 0 !important;
    }
}

/* ===== Integration dialog dynamic width ===== */
/* Integration dialog: constrain content height in preview mode */
.mud-dialog-width-xxl .mud-dialog-content {
    max-height: 85vh;
}

/* ===== Orchestrator Layout ===== */

.orchestrator-container {
    display: flex;
    height: 100%;
    overflow: hidden;
}

.orchestrator-left-panel {
    width: 260px;
    min-width: 200px;
    border-right: 1px solid var(--mud-palette-lines-default, #e2e8f0);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: var(--mud-palette-surface, #fff);
}

.orchestrator-left-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--mud-palette-lines-default, #e2e8f0);
}

.orchestrator-workflow-list {
    flex: 0 1 auto;
    overflow-y: auto;
    max-height: 40vh;
}

.orchestrator-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.orchestrator-action-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 12px;
    border-bottom: 1px solid var(--mud-palette-lines-default, #e2e8f0);
    background: var(--mud-palette-surface, #fff);
    gap: 8px;
    flex-wrap: wrap;
    min-height: 36px;
}

.orchestrator-canvas {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-height: 200px;
}

.orchestrator-empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}

.orchestrator-bottom-panel {
    height: 200px;
    min-height: 32px;
    border-top: 1px solid var(--mud-palette-lines-default, #e2e8f0);
    display: flex;
    flex-direction: column;
    background: var(--mud-palette-surface, #fff);
}

.orchestrator-bottom-panel.collapsed {
    height: 32px;
    overflow: hidden;
}

/* Help button glow — applied while the user account is < 7 days old to nudge new users
   toward the in-app guide. CSS animation only, no JS keep-alive required. */
.orchestrator-help-button-glow,
.global-help-button-glow {
    border-radius: 50%;
    animation: orchestrator-help-pulse 1.8s ease-in-out infinite;
}

@keyframes orchestrator-help-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(129, 140, 248, 0.55),
                    0 0 8px 2px rgba(129, 140, 248, 0.35);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(129, 140, 248, 0),
                    0 0 14px 4px rgba(129, 140, 248, 0.6);
    }
}

@media (prefers-reduced-motion: reduce) {
    .orchestrator-help-button-glow,
    .global-help-button-glow {
        animation: none;
        box-shadow: 0 0 8px 2px rgba(129, 140, 248, 0.45);
    }
}

/* Page help dialog content polish — keeps section spacing readable across pages. */
.page-help-content h3,
.page-help-content .help-section-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 12px 0 4px;
    color: var(--mud-palette-primary);
}

.page-help-content h3:first-child,
.page-help-content .help-section-title:first-child {
    margin-top: 0;
}

.page-help-content p,
.page-help-content ul,
.page-help-content ol {
    font-size: 0.875rem;
    line-height: 1.5;
}

.page-help-content code {
    font-size: 0.8125rem;
    background: var(--mud-palette-background-grey, #f5f5f5);
    padding: 1px 5px;
    border-radius: 3px;
}

/* Right panel (node palette or config) */
.orchestrator-right-panel {
    width: 380px;
    min-width: 320px;
    border-left: 1px solid var(--mud-palette-lines-default, #e2e8f0);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: var(--mud-palette-surface, #fff);
}

.orchestrator-right-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--mud-palette-lines-default, #e2e8f0);
}

/* Config panel (inside right panel) */
.orchestrator-config-panel {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex: 1;
}

/* Disabled palette */
.node-palette-disabled {
    opacity: 0.4;
    pointer-events: none;
}

.node-palette-item.disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.orchestrator-config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--mud-palette-lines-default, #e2e8f0);
}

.orchestrator-config-body {
    padding: 12px;
    flex: 1;
    overflow-y: auto;
}

/* fw-bold utility */
.fw-bold {
    font-weight: 600 !important;
}

/* Text truncate for workflow names */
.text-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
