/* Flowchart Styles */
/* Card hover effects */
.hover-shadow {
    transition: all 0.3s ease;
}

.hover-shadow:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1) !important;
}

/* Hero section styles */
.hero-section {
    background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.hero-section::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: url('data:image/svg+xml;utf8,<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h100v100H0z" fill="none"/><path d="M50 20v60M20 50h60" stroke="rgba(255,255,255,0.1)" stroke-width="2"/></svg>') repeat;
    opacity: 0.3;
}

/* Dark mode styles */
:root {
    --bg-light: #f8f9fa;
    --bg-dark: #212529;
    --shape-bg-light: #fff;
    --shape-bg-dark: #343a40;
    --text-light: #212529;
    --text-dark: #c0c0c0;
    --border-light: #dee2e6;
    --border-dark: #495057;
    --grid-color-light: rgba(0, 0, 0, 0.3);
    --grid-color-dark: rgba(255, 255, 255, 0.3);
    --control-bg-light: rgba(255, 255, 255, 0.9);
    --control-bg-dark: rgba(52, 58, 64, 0.9);
}

body.dark-mode {
    background-color: #343a40;
    color: var(--text-dark);
}

/* Dark mode styles for Bootstrap components */
body.dark-mode .card {
    background-color: var(--shape-bg-dark);
    color: var(--text-dark);
    border-color: var(--border-dark);
}

body.dark-mode .table {
    color: var(--text-dark) !important;
    border-color: var(--border-dark);
}

body.dark-mode .table thead th {
    background-color: rgba(52, 58, 64, 0.9);
    color: var(--text-dark) !important;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

body.dark-mode .table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(255, 255, 255, 0.15);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-dark) !important;
}

body.dark-mode .table-striped tbody tr:nth-of-type(even) {
    background-color: rgba(52, 58, 64, 0.7);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-dark) !important;
}

body.dark-mode .table-hover tbody tr:hover {
    background-color: rgba(73, 80, 87, 0.8) !important;
    color: var(--text-dark) !important;
}

/* Ensure all table cells have darker text in dark mode */
body.dark-mode .table td,
body.dark-mode .table th {
    color: var(--text-dark) !important;
}

body.dark-mode .text-muted {
    color: #adb5bd !important;
}

body.dark-mode .form-text {
    color: #adb5bd !important;
}

body.dark-mode .comment-text {
    background-color: rgba(52, 58, 64, 0.8);
    border-left: 3px solid #adb5bd;
    color: var(--text-dark);
}

body.dark-mode .modal-content {
    background-color: var(--shape-bg-dark);
    color: var(--text-dark);
}

body.dark-mode .form-control,
body.dark-mode .form-select {
    background-color: #495057;
    color: #ffffff;
    border-color: var(--border-dark);
}

body.dark-mode .form-control:focus,
body.dark-mode .form-select:focus {
    background-color: #495057;
    color: #ffffff;
}

/* Placeholder text color in dark mode */
body.dark-mode .form-control::placeholder {
    color: #ffffff;
    opacity: 0.7;
}

/* Ensure text is visible in dark mode for all browser-specific pseudo-classes */
body.dark-mode .form-control::-webkit-input-placeholder {
    color: #ffffff;
    opacity: 0.7;
}

body.dark-mode .form-control::-moz-placeholder {
    color: #ffffff;
    opacity: 0.7;
}

body.dark-mode .form-control:-ms-input-placeholder {
    color: #ffffff;
    opacity: 0.7;
}

body.dark-mode .form-control:-moz-placeholder {
    color: #ffffff;
    opacity: 0.7;
}

/* Ensure text color for input value */
body.dark-mode .form-control {
    color: #ffffff !important;
}

body.dark-mode .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

.flowchart-container {
    padding: 20px;
    background-color: var(--bg-light);
    border-radius: 5px;
    min-height: 400px; /* Reduced from 600px to match the minimum in JavaScript */
    position: relative;
    overflow: auto;
    width: 100%;
    cursor: grab;
    height: 100%; /* Allow the height to be set dynamically */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

/* Make the flowchart container take full page width in edit mode */
.flowchart-container[data-published="false"] {
    min-height: 600px; /* Increase minimum height for better usability */
    padding: 30px; /* Increase padding for better spacing in full-width mode */
}

body.dark-mode .flowchart-container {
    background-color: var(--bg-dark);
}

/* Full width card in edit mode */
.card-fullwidth-edit {
    width: calc(100% + 40px); /* Account for content-wrapper padding */
    max-width: calc(100% + 40px);
    margin-left: -20px; /* Offset the content-wrapper padding */
    margin-right: -20px;
    border-radius: 0;
    border-left: none;
    border-right: none;
}

/* Adjust card body padding in edit mode */
.card-fullwidth-edit .card-body {
    padding: 0 !important;
}

/* Hide scrollbar for Chrome, Safari and Opera */
.flowchart-container::-webkit-scrollbar {
    display: none;
}

.flowchart-container:active {
    cursor: grabbing;
}

.flowchart-content-wrapper {
    position: relative;
    transform-origin: 0 0;
    transition: transform 0.1s ease-out;
    min-height: 100%;
    min-width: 100%;
}

/* Grid background for the flowchart */
.flowchart-content-wrapper.show-grid {
    background-color: var(--bg-light);
    background-size: 20px 20px;
    background-image:
        linear-gradient(to right, var(--grid-color-light) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-color-light) 1px, transparent 1px);
    background-position: 0 0;
    background-repeat: repeat;
}

body.dark-mode .flowchart-content-wrapper.show-grid {
    background-color: var(--bg-dark);
    background-image:
        linear-gradient(to right, var(--grid-color-dark) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-color-dark) 1px, transparent 1px);
}

/* Zoom Controls */
.zoom-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
    background-color: var(--control-bg-light);
    border-radius: 5px;
    padding: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    gap: 5px;
}

body.dark-mode .zoom-controls {
    background-color: var(--control-bg-dark);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
}

.zoom-btn {
    width: 30px;
    height: 30px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Floating Shape Palette */
.floating-palette {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 10;
    background-color: var(--control-bg-light);
    border-radius: 5px;
    padding: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 180px;
}

body.dark-mode .floating-palette {
    background-color: var(--control-bg-dark);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
}

.floating-palette-btn {
    width: 100%;
    padding: 6px 10px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.9rem;
}

.floating-palette-btn i {
    width: 16px;
    text-align: center;
}

.floating-palette-divider {
    height: 1px;
    background-color: var(--border-light);
    margin: 2px 0;
}

body.dark-mode .floating-palette-divider {
    background-color: var(--border-dark);
}

.shape {
    position: absolute; /* Changed from relative to absolute for dynamic positioning */
    width: 180px; /* Changed from 200px to 180px (9 grid cells) */
    min-height: 100px; /* Kept at 100px (5 grid cells) */
    padding: 12px; /* Increased from 10px to 12px for better readability */
    border-radius: 5px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    background-color: var(--shape-bg-light);
    color: var(--text-light);
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    z-index: 2; /* Increased to ensure shapes appear above connectors and connector labels */
    transition: all 0.3s ease; /* Smooth transition for any changes */
}

body.dark-mode .shape {
    background-color: var(--shape-bg-dark);
    color: var(--text-dark);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.shape-decision {
    transform: rotate(45deg);
    width: 160px; /* Changed from 150px to 160px (8 grid cells) */
    height: 160px; /* Changed from 150px to 160px (8 grid cells) */
}

.shape-decision .shape-content {
    transform: rotate(-45deg);
}

.shape-action\/process {
    border-radius: 5px;
    position: relative;
    width: 200px; /* Changed to 200px (10 grid cells) to make it wider */
}

.shape-subroutine {
    border-radius: 5px;
    position: relative;
    width: 200px; /* Changed to 200px (10 grid cells) to make it wider */
}

.shape-subroutine::before,
.shape-subroutine::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 3px;
}

.shape-subroutine::before {
    left: 15px; /* Distance from the left edge */
}

.shape-subroutine::after {
    right: 15px; /* Distance from the right edge */
}

/* Tramline colors based on importance */
.shape-subroutine.shape-success::before,
.shape-subroutine.shape-success::after {
    background-color: #28a745; /* Match success border color */
}

.shape-subroutine.shape-alert::before,
.shape-subroutine.shape-alert::after {
    background-color: #dc3545; /* Match alert border color */
}

.shape-subroutine.shape-warning::before,
.shape-subroutine.shape-warning::after {
    background-color: #ffc107; /* Match warning border color */
}

/* Tramline colors for inactive subroutine shapes - match border color */
.shape-inactive.shape-subroutine::before,
.shape-inactive.shape-subroutine::after {
    background-color: #ccc !important; /* Match inactive border color */
}

body.dark-mode .shape-inactive.shape-subroutine::before,
body.dark-mode .shape-inactive.shape-subroutine::after {
    background-color: #000000 !important; /* Match inactive border color in dark mode */
}

.shape-document {
    position: relative;
    width: 200px;
    border-radius: 5px 5px 0 0;
}

.shape-document::after {
    content: "";
    position: absolute;
    bottom: -20px;
    left: 0;
    width: 100%;
    height: 20px;
    border-radius: 0 0 50% 50%;
}

/* Curved bottom for different importance levels */
.shape-document.shape-success::after {
    background-color: #28a745;
}

.shape-document.shape-alert::after {
    background-color: #dc3545;
}

.shape-document.shape-warning::after {
    background-color: #ffc107;
}

.shape-finish {
    border-radius: 50px;
}

.shape-start {
    border-radius: 50px;
}

.shape-input\/output {
    position: relative;
    width: 200px;
    height: 100px;
    border-radius: 0; /* Remove border radius to ensure sharp corners */
    background-color: var(--shape-bg-light); /* Use variable for background color */
    transform: skew(20deg); /* Create a parallelogram with 20 degree skew */
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); /* Add shadow */
}

body.dark-mode .shape-input\/output {
    background-color: var(--shape-bg-dark); /* Use dark mode variable for background color */
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3); /* Darker shadow for dark mode */
}

.shape-input\/output .shape-content {
    position: relative;
    z-index: 1; /* Ensure content is above the background */
    padding: 10px; /* Add padding to prevent text from being cut off */
    width: 100%; /* Ensure content takes full width */
    height: 100%; /* Ensure content takes full height */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transform: skew(-20deg); /* Counter-transform to keep text readable */
}

.shape-success {
    border: 2px solid #28a745;
}

.shape-alert {
    border: 2px solid #dc3545;
}

.shape-warning {
    border: 2px solid #ffc107;
}

.shape-content {
    word-wrap: break-word;
    padding: 5px; /* Add general padding to all shape content */
}

.reference-number {
    font-size: 0.8rem;
    color: #6c757d;
    margin-bottom: 5px;
    font-style: italic;
    border-bottom: 1px dashed #ccc;
    display: inline-block;
    padding-bottom: 2px;
}

/* Add padding to process shape content to prevent text from overlapping tramlines */
.shape-process .shape-content {
    padding-left: 20px;
    padding-right: 20px;
}

/* Add padding to subroutine shape content to prevent text from overlapping tramlines */
.shape-subroutine .shape-content {
    padding-left: 20px;
    padding-right: 20px;
}

.shape-actions {
    position: absolute;
    top: 0;
    right: -45px; /* Positioned outside the shape */
    display: flex;
    flex-direction: column; /* Stack buttons vertically */
    gap: 5px;
    background-color: var(--control-bg-light); /* Semi-transparent background */
    border-radius: 4px; /* Rounded corners */
    padding: 5px; /* Increased padding from 3px to 5px */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); /* Subtle shadow */
    z-index: 3; /* Increased to ensure buttons appear above shapes */
}

body.dark-mode .shape-actions {
    background-color: var(--control-bg-dark);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.connector {
    position: absolute;
    background-color: #6c757d;
    z-index: 1; /* Below shapes (z-index: 2) */
    box-shadow: none; /* Removed shadow to ensure consistent 1px thickness */
}

body.dark-mode .connector {
    background-color: #adb5bd;
    box-shadow: none; /* Removed shadow to ensure consistent 1px thickness */
}

.connector-arrow {
    position: absolute;
    z-index: 1; /* Same as connectors, below shapes (z-index: 2) */
    pointer-events: none; /* Prevent arrow from interfering with mouse events */
    overflow: visible; /* Ensure the SVG content is visible */
}

/* Style for connector arrows in the playback path - using priority colors */
.flowchart-container[data-is-playback="true"] .connector-arrow-active {
    animation: arrow-pulse 1.5s infinite ease-in-out; /* Add pulsing animation to all active arrows */
}

/* Success (green) */
.flowchart-container[data-is-playback="true"] .connector-arrow-success {
    animation: arrow-pulse-success 1.5s infinite ease-in-out; /* Success-specific animation */
}

/* Alert (red) */
.flowchart-container[data-is-playback="true"] .connector-arrow-alert {
    animation: arrow-pulse-alert 1.5s infinite ease-in-out; /* Alert-specific animation */
}

/* Warning (yellow) */
.flowchart-container[data-is-playback="true"] .connector-arrow-warning {
    animation: arrow-pulse-warning 1.5s infinite ease-in-out; /* Warning-specific animation */
}

/* Arrow animation keyframes */
@keyframes arrow-pulse {
    0% {
        transform: scale(1) translate(0, 0);
        opacity: 0.7;
    }
    50% {
        transform: scale(1.2) translate(var(--move-x, 3px), var(--move-y, 3px));
        opacity: 1;
    }
    100% {
        transform: scale(1) translate(0, 0);
        opacity: 0.7;
    }
}

@keyframes arrow-pulse-success {
    0% {
        transform: scale(1) translate(0, 0);
    }
    50% {
        transform: scale(1.2) translate(var(--move-x, 3px), var(--move-y, 3px));
    }
    100% {
        transform: scale(1) translate(0, 0);
    }
}

@keyframes arrow-pulse-alert {
    0% {
        transform: scale(1) translate(0, 0);
    }
    50% {
        transform: scale(1.2) translate(var(--move-x, 3px), var(--move-y, 3px));
    }
    100% {
        transform: scale(1) translate(0, 0);
    }
}

@keyframes arrow-pulse-warning {
    0% {
        transform: scale(1) translate(0, 0);
    }
    50% {
        transform: scale(1.2) translate(var(--move-x, 3px), var(--move-y, 3px));
    }
    100% {
        transform: scale(1) translate(0, 0);
    }
}

.connector-label {
    position: absolute;
    background-color: var(--shape-bg-light);
    color: var(--text-light);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.8rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 5; /* Above connectors, connector-arrows, and shapes */
}

body.dark-mode .connector-label {
    background-color: var(--shape-bg-dark);
    color: var(--text-dark);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.tip-badge {
    position: absolute;
    top: 5px;
    left: 5px;
    cursor: pointer;
}

.link-badge {
    position: absolute;
    bottom: 5px;
    left: 5px;
    cursor: pointer;
}

.start-badge {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #28a745;
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.8rem;
}

.finish-badge {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #28a745;
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.8rem;
}

/* Connection badge styles */
.badge.bg-success, .badge.bg-primary {
    font-size: 0.7rem;
    padding: 3px 6px;
    margin-left: 5px;
    vertical-align: middle;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Connect to next badge */
.badge.bg-success {
    position: relative;
    border: 1px solid #1e7e34;
}

/* Connect to previous badge */
.badge.bg-primary {
    position: relative;
    border: 1px solid #0062cc;
}

/* Style for inactive shapes (not in the playback path) */
.shape-inactive {
    background-color: #f0f0f0 !important;
    border-color: #ccc !important;
    color: #666 !important;
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.05) !important;
}

body.dark-mode .shape-inactive {
    background-color: #1a1d20 !important; /* Darker background */
    border-color: #000000 !important; /* Black border */
    color: var(--text-dark) !important; /* Darker text */
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.5) !important; /* Stronger shadow */
    border-width: 2px !important; /* Thicker border */
}

/* Style for active shapes (in the playback path) - using priority colors */
/* Success (green) */
.flowchart-container[data-is-playback="true"] .shape-success:not(.shape-inactive) {
    box-shadow: 0 0 15px rgba(40, 167, 69, 0.5), 0 0 30px rgba(40, 167, 69, 0.3) !important; /* Enhanced glowing effect */
    animation: shape-glow-success 2s infinite alternate;
}

@keyframes shape-glow-success {
    from {
        box-shadow: 0 0 15px rgba(40, 167, 69, 0.5), 0 0 30px rgba(40, 167, 69, 0.3);
    }
    to {
        box-shadow: 0 0 20px rgba(40, 167, 69, 0.7), 0 0 40px rgba(40, 167, 69, 0.5);
    }
}

/* Alert (red) */
.flowchart-container[data-is-playback="true"] .shape-alert:not(.shape-inactive) {
    box-shadow: 0 0 15px rgba(220, 53, 69, 0.5), 0 0 30px rgba(220, 53, 69, 0.3) !important; /* Enhanced glowing effect */
    animation: shape-glow-alert 2s infinite alternate;
}

@keyframes shape-glow-alert {
    from {
        box-shadow: 0 0 15px rgba(220, 53, 69, 0.5), 0 0 30px rgba(220, 53, 69, 0.3);
    }
    to {
        box-shadow: 0 0 20px rgba(220, 53, 69, 0.7), 0 0 40px rgba(220, 53, 69, 0.5);
    }
}

/* Warning (yellow) */
.flowchart-container[data-is-playback="true"] .shape-warning:not(.shape-inactive) {
    box-shadow: 0 0 15px rgba(255, 193, 7, 0.5), 0 0 30px rgba(255, 193, 7, 0.3) !important; /* Enhanced glowing effect */
    animation: shape-glow-warning 2s infinite alternate;
}

@keyframes shape-glow-warning {
    from {
        box-shadow: 0 0 15px rgba(255, 193, 7, 0.5), 0 0 30px rgba(255, 193, 7, 0.3);
    }
    to {
        box-shadow: 0 0 20px rgba(255, 193, 7, 0.7), 0 0 40px rgba(255, 193, 7, 0.5);
    }
}

/* Style for connectors in the playback path - using priority colors */
/* Success (green) */
.flowchart-container[data-is-playback="true"] .connector-active.connector-success {
    background-color: #28a745; /* Success color */
    z-index: 1; /* Same as regular connectors, below shapes (z-index: 2) */
    box-shadow: none; /* Remove shadow to prevent the appearance of thickness */
}

/* Alert (red) */
.flowchart-container[data-is-playback="true"] .connector-active.connector-alert {
    background-color: #dc3545; /* Alert color */
    z-index: 1; /* Same as regular connectors, below shapes (z-index: 2) */
    box-shadow: none; /* Remove shadow to prevent the appearance of thickness */
}

/* Warning (yellow) */
.flowchart-container[data-is-playback="true"] .connector-active.connector-warning {
    background-color: #ffc107; /* Warning color */
    z-index: 1; /* Same as regular connectors, below shapes (z-index: 2) */
    box-shadow: none; /* Remove shadow to prevent the appearance of thickness */
}

/* Default connector style (fallback) */
.flowchart-container[data-is-playback="true"] .connector-active:not(.connector-success):not(.connector-alert):not(.connector-warning) {
    background-color: #28a745; /* Default to success color */
    z-index: 1; /* Same as regular connectors, below shapes (z-index: 2) */
    box-shadow: none; /* Remove shadow to prevent the appearance of thickness */
}

/* Style for connector labels in the playback path - using priority colors */
/* Success (green) */
.flowchart-container[data-is-playback="true"] .connector-label-active.connector-label-success {
    background-color: #28a745; /* Success color */
    color: white;
    font-weight: bold;
}

/* Alert (red) */
.flowchart-container[data-is-playback="true"] .connector-label-active.connector-label-alert {
    background-color: #dc3545; /* Alert color */
    color: white;
    font-weight: bold;
}

/* Warning (yellow) */
.flowchart-container[data-is-playback="true"] .connector-label-active.connector-label-warning {
    background-color: #ffc107; /* Warning color */
    color: black; /* Better contrast with yellow */
    font-weight: bold;
}

/* Default connector label style (fallback) */
.flowchart-container[data-is-playback="true"] .connector-label-active:not(.connector-label-success):not(.connector-label-alert):not(.connector-label-warning) {
    background-color: #28a745; /* Default to success color */
    color: white;
    font-weight: bold;
}

/* Styles for shape connection mode */
.shape-connecting-from {
    box-shadow: 0 0 15px rgba(0, 123, 255, 0.7), 0 0 30px rgba(0, 123, 255, 0.5) !important;
    border: 2px solid #007bff !important;
    z-index: 10 !important;
}

.shape-connecting-to {
    box-shadow: 0 0 15px rgba(40, 167, 69, 0.7), 0 0 30px rgba(40, 167, 69, 0.5) !important;
    border: 2px solid #28a745 !important;
}

/* Dark mode styles for shape connection */
body.dark-mode .shape-connecting-from {
    box-shadow: 0 0 15px rgba(0, 123, 255, 0.7), 0 0 30px rgba(0, 123, 255, 0.5) !important;
    border: 2px solid #007bff !important;
}

body.dark-mode .shape-connecting-to {
    box-shadow: 0 0 15px rgba(40, 167, 69, 0.7), 0 0 30px rgba(40, 167, 69, 0.5) !important;
    border: 2px solid #28a745 !important;
}
