/**
 * Process Diagrams Styling
 *
 * Styles for interactive process diagrams including:
 * - Issue → Triage → Job
 * - Notification Flows
 * - Asset Lifecycle
 * - DVIR Inspection Flow
 * - External Shop Dispatch
 */

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

.diagram-page {
    min-height: 100vh;
    padding-bottom: 4rem;
}

.diagram-header {
    background: linear-gradient(135deg, var(--primary) 0%, #1e40af 100%);
    color: white;
    padding: 3rem 2rem;
    margin-bottom: 2rem;
}

:root[data-theme="dark"] .diagram-header {
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
}

.diagram-header .container {
    max-width: 1200px;
    margin: 0 auto;
}

.diagram-breadcrumb {
    font-size: 0.875rem;
    opacity: 0.8;
    margin-bottom: 1rem;
}

.diagram-breadcrumb a {
    color: white;
    text-decoration: none;
}

.diagram-breadcrumb a:hover {
    text-decoration: underline;
}

.diagram-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0 0 0.5rem;
}

.diagram-description {
    font-size: 1.125rem;
    opacity: 0.9;
    margin: 0;
    max-width: 600px;
}

/* =============================================================================
   Gallery / Index Page
   ============================================================================= */

.diagram-gallery {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

.diagram-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.diagram-card {
    background: var(--white);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--gray-200);
}

:root[data-theme="dark"] .diagram-card {
    background: var(--gray-800);
    border-color: var(--gray-700);
}

.diagram-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

.diagram-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

.diagram-card-icon svg {
    width: 24px;
    height: 24px;
    stroke: white;
}

.diagram-card-icon.blue { background: #3b82f6; }
.diagram-card-icon.purple { background: #8b5cf6; }
.diagram-card-icon.green { background: #10b981; }
.diagram-card-icon.amber { background: #f59e0b; }
.diagram-card-icon.rose { background: #f43f5e; }

.diagram-card h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 0.5rem;
    color: var(--dark);
}

:root[data-theme="dark"] .diagram-card h3 {
    color: var(--gray-100);
}

.diagram-card p {
    color: var(--gray-600);
    font-size: 0.9375rem;
    line-height: 1.5;
    margin: 0;
    flex-grow: 1;
}

:root[data-theme="dark"] .diagram-card p {
    color: var(--gray-400);
}

.diagram-card-arrow {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    color: var(--primary);
    font-size: 0.875rem;
    font-weight: 500;
}

.diagram-card-arrow svg {
    width: 16px;
    height: 16px;
    transition: transform 0.2s;
}

.diagram-card:hover .diagram-card-arrow svg {
    transform: translateX(4px);
}

/* =============================================================================
   Diagram Container
   ============================================================================= */

.diagram-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
}

.diagram-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 2rem;
    align-items: start;
}

@media (max-width: 1024px) {
    .diagram-layout {
        grid-template-columns: 1fr;
    }
}

.diagram-canvas {
    background: var(--white);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--gray-200);
    overflow-x: auto;
}

:root[data-theme="dark"] .diagram-canvas {
    background: var(--gray-800);
    border-color: var(--gray-700);
}

/* Mermaid diagram container */
.diagram-canvas .mermaid {
    display: flex;
    justify-content: center;
}

.diagram-canvas .mermaid svg {
    max-width: 100%;
    height: auto;
}

/* =============================================================================
   Detail Panel (shown on node click)
   ============================================================================= */

.diagram-detail-panel {
    background: var(--white);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--gray-200);
    position: sticky;
    top: 2rem;
}

:root[data-theme="dark"] .diagram-detail-panel {
    background: var(--gray-800);
    border-color: var(--gray-700);
}

.diagram-detail-panel h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0 0 0.75rem;
    color: var(--dark);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

:root[data-theme="dark"] .diagram-detail-panel h3 {
    color: var(--gray-100);
}

.diagram-detail-panel .detail-description {
    color: var(--gray-600);
    font-size: 0.9375rem;
    line-height: 1.6;
    margin: 0 0 1rem;
}

:root[data-theme="dark"] .diagram-detail-panel .detail-description {
    color: var(--gray-400);
}

.diagram-detail-panel .detail-settings {
    border-top: 1px solid var(--gray-200);
    padding-top: 1rem;
    margin-top: 1rem;
}

:root[data-theme="dark"] .diagram-detail-panel .detail-settings {
    border-color: var(--gray-700);
}

.diagram-detail-panel .detail-settings h4 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    margin: 0 0 0.5rem;
}

.diagram-detail-panel .setting-tag {
    display: inline-block;
    background: var(--gray-100);
    color: var(--gray-700);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8125rem;
    font-family: ui-monospace, monospace;
    margin: 0.25rem 0.25rem 0 0;
}

:root[data-theme="dark"] .diagram-detail-panel .setting-tag {
    background: var(--gray-700);
    color: var(--gray-300);
}

.detail-placeholder {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--gray-500);
}

.detail-placeholder svg {
    width: 48px;
    height: 48px;
    stroke: var(--gray-400);
    margin-bottom: 1rem;
}

/* =============================================================================
   Configuration Toggles
   ============================================================================= */

.diagram-config {
    background: var(--white);
    border-radius: 12px;
    padding: 1.5rem;
    margin-top: 2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--gray-200);
}

:root[data-theme="dark"] .diagram-config {
    background: var(--gray-800);
    border-color: var(--gray-700);
}

.diagram-config h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 1rem;
    color: var(--dark);
}

:root[data-theme="dark"] .diagram-config h2 {
    color: var(--gray-100);
}

.config-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.config-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.5rem 1rem;
    background: var(--gray-50);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
    transition: background 0.2s, border-color 0.2s;
}

:root[data-theme="dark"] .config-toggle {
    background: var(--gray-700);
    border-color: var(--gray-600);
}

.config-toggle:hover {
    background: var(--gray-100);
}

:root[data-theme="dark"] .config-toggle:hover {
    background: var(--gray-600);
}

.config-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.config-toggle span {
    font-size: 0.875rem;
    color: var(--gray-700);
}

:root[data-theme="dark"] .config-toggle span {
    color: var(--gray-300);
}

.config-select {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--gray-50);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
}

:root[data-theme="dark"] .config-select {
    background: var(--gray-700);
    border-color: var(--gray-600);
}

.config-select label {
    font-size: 0.875rem;
    color: var(--gray-700);
    white-space: nowrap;
}

:root[data-theme="dark"] .config-select label {
    color: var(--gray-300);
}

.config-select select {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--gray-300);
    background: var(--white);
    font-size: 0.875rem;
}

:root[data-theme="dark"] .config-select select {
    background: var(--gray-600);
    border-color: var(--gray-500);
    color: var(--gray-200);
}

/* =============================================================================
   Animation Controls
   ============================================================================= */

.diagram-controls {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.diagram-controls .btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.diagram-controls .btn svg {
    width: 18px;
    height: 18px;
}

.diagram-controls .btn-primary {
    background: var(--primary);
    color: white;
}

.diagram-controls .btn-primary:hover {
    background: #1d4ed8;
}

.diagram-controls .btn-outline {
    background: transparent;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

:root[data-theme="dark"] .diagram-controls .btn-outline {
    color: var(--gray-300);
    border-color: var(--gray-600);
}

.diagram-controls .btn-outline:hover {
    background: var(--gray-100);
}

:root[data-theme="dark"] .diagram-controls .btn-outline:hover {
    background: var(--gray-700);
}

/* =============================================================================
   Mermaid Theme Overrides (Dark Mode Support)
   ============================================================================= */

/* Light mode colors - let Mermaid use defaults */

/* Dark mode colors */
:root[data-theme="dark"] .mermaid {
    --mermaid-background: transparent;
}

/* Node colors for dark mode */
:root[data-theme="dark"] .mermaid .node rect,
:root[data-theme="dark"] .mermaid .node circle,
:root[data-theme="dark"] .mermaid .node ellipse,
:root[data-theme="dark"] .mermaid .node polygon {
    fill: #374151;
    stroke: #6b7280;
}

:root[data-theme="dark"] .mermaid .node .label {
    color: #f3f4f6;
}

:root[data-theme="dark"] .mermaid .edgePath .path {
    stroke: #6b7280;
}

:root[data-theme="dark"] .mermaid .edgeLabel {
    background-color: #1f2937;
    color: #d1d5db;
}

:root[data-theme="dark"] .mermaid .cluster rect {
    fill: #1f2937;
    stroke: #4b5563;
}

:root[data-theme="dark"] .mermaid .cluster text {
    fill: #f3f4f6;
}

/* Subgraph colors */
:root[data-theme="dark"] .mermaid .subgraph-blue rect { fill: #1e3a5f; stroke: #3b82f6; }
:root[data-theme="dark"] .mermaid .subgraph-amber rect { fill: #422006; stroke: #f59e0b; }
:root[data-theme="dark"] .mermaid .subgraph-green rect { fill: #064e3b; stroke: #10b981; }
:root[data-theme="dark"] .mermaid .subgraph-purple rect { fill: #2e1065; stroke: #8b5cf6; }
:root[data-theme="dark"] .mermaid .subgraph-rose rect { fill: #4c0519; stroke: #f43f5e; }

/* =============================================================================
   Flow Animation
   ============================================================================= */

.diagram-canvas.animating .mermaid .edgePath .path {
    stroke-dasharray: 10;
    animation: flowAnimation 1s linear infinite;
}

@keyframes flowAnimation {
    0% { stroke-dashoffset: 20; }
    100% { stroke-dashoffset: 0; }
}

/* Highlight active node during animation */
.diagram-canvas .mermaid .node.active rect,
.diagram-canvas .mermaid .node.active circle,
.diagram-canvas .mermaid .node.active polygon {
    stroke: var(--primary);
    stroke-width: 3px;
    filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.5));
}

/* Node hover effect */
.diagram-canvas .mermaid .node {
    cursor: pointer;
    transition: filter 0.2s;
}

.diagram-canvas .mermaid .node:hover {
    filter: brightness(0.95);
}

:root[data-theme="dark"] .diagram-canvas .mermaid .node:hover {
    filter: brightness(1.1);
}

/* =============================================================================
   Legend
   ============================================================================= */

.diagram-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: 8px;
}

:root[data-theme="dark"] .diagram-legend {
    background: var(--gray-900);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: var(--gray-600);
}

:root[data-theme="dark"] .legend-item {
    color: var(--gray-400);
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 4px;
}

.legend-color.blue { background: #dbeafe; border: 1px solid #3b82f6; }
.legend-color.amber { background: #fef3c7; border: 1px solid #f59e0b; }
.legend-color.green { background: #d1fae5; border: 1px solid #10b981; }
.legend-color.purple { background: #ede9fe; border: 1px solid #8b5cf6; }
.legend-color.rose { background: #ffe4e6; border: 1px solid #f43f5e; }

:root[data-theme="dark"] .legend-color.blue { background: #1e3a5f; }
:root[data-theme="dark"] .legend-color.amber { background: #422006; }
:root[data-theme="dark"] .legend-color.green { background: #064e3b; }
:root[data-theme="dark"] .legend-color.purple { background: #2e1065; }
:root[data-theme="dark"] .legend-color.rose { background: #4c0519; }

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

@media (max-width: 768px) {
    .diagram-header {
        padding: 2rem 1rem;
    }

    .diagram-header h1 {
        font-size: 1.75rem;
    }

    .diagram-main {
        padding: 0 1rem;
    }

    .diagram-canvas {
        padding: 1rem;
    }

    .diagram-detail-panel {
        position: static;
        margin-top: 1.5rem;
    }

    .config-toggles {
        flex-direction: column;
    }

    .config-toggle {
        width: 100%;
    }

    .diagram-controls {
        flex-direction: column;
    }

    .diagram-controls .btn {
        width: 100%;
        justify-content: center;
    }
}

/* =============================================================================
   Print Styles
   ============================================================================= */

@media print {
    .diagram-header {
        background: none;
        color: black;
        border-bottom: 2px solid black;
    }

    .diagram-config,
    .diagram-controls,
    .diagram-detail-panel {
        display: none;
    }

    .diagram-layout {
        grid-template-columns: 1fr;
    }

    .diagram-canvas {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}
