/* Define color scheme */
:root {

    --color-element-border: #666666;
    --color-selected: #3b82f6;
    --color-text: #1f2937;
    --color-text-placeholder: #717171;
    /*
    --color-bg: #f7fafc;
    --color-node-border: #666666;
    --color-node-border-hover: #2d3748;
    --color-node-border-selected: #3b82f6;
    --color-node-border-editing: #93c5fd;
    --color-connector: #666666;
    --color-connector-hover: #2d3748;
    --color-edge: #2d3748;
    --color-edge-selected: #3b82f6;
    --color-edge-cycle-error: #dc2626;
    --color-edge-temp-line: #2d3748;
    --color-edge-temp-line-warning: #dc2626;
    --color-text: #2d3748;
    --color-text-placeholder: #a0aec0;
    --color-toolbar-bg: #f7fafc;
    --color-toolbar-button-bg: #f7fafc;
    --color-toolbar-button-hover-bg: #dce6ef;
    --color-toolbar-button-disabled-bg: #f7fafc;
    --color-toolbar-button-disabled-opacity: 0.5;
    --color-annotation-bg: #fffbe7;
    --color-annotation-border: #e2e8f0;
    --color-annotation-text: #2d3748;
    --color-annotation-text-placeholder: #a0aec0;
    --color-annotation-frame-border: #999999;
    --color-annotation-frame-border-selected: #3b82f6;
    --color-annotation-frame-title-bg: #f3f4f6;
    */
}

/* Use Inter font */
body {
    font-family: 'Inter', sans-serif;
    touch-action: none; /* Prevents default touch behaviors like pinch-zoom */
    user-select: none; /* Disable text selection for the whole page */
    -webkit-user-select: none; /* For Safari/Chrome */
    -moz-user-select: none;    /* For Firefox */
    -ms-user-select: none;     /* For IE/Edge */
    -webkit-touch-callout: none; /* Prevents callout menu on iOS */

    display: flex; 
    overflow: hidden; 
    flex-direction: column; 
    height: 100vh; 
    background-color: #F3F4F6; 
}

.app-header {
    z-index: 20; 
    background-color: #ffffff; 
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); 
}

.modal-background {
    display: flex; 
    display: none; 
    position: fixed; 
    top: 0;
    right: 0;
    bottom: 0;
    left: 0; 
    z-index: 50; 
    justify-content: center; 
    align-items: center; 
    background-color: rgba(0, 0, 0, 0.4); 
}

.modal-container {
    padding: 1.5rem; 
    border-radius: 0.5rem; 
    width: 100%; 
    max-width: 28rem; 
    text-align: center; 
    background-color: #ffffff; 
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); 
}

#diagram-container {
    position: relative; 
    width: 100%; 
    height: 100%; 
    cursor: grab;
}
#diagram-container.is-panning {
    cursor: grabbing !important;
}
#diagram-container.cursor-grabbing {
    cursor: grabbing !important;
}

/* Custom styles for the grid background */
.grid-background {
    --grid-size: 20px;
    --grid-size-major: 100px;
    --grid-color-light: #e0e0e0;
    --grid-color-dark: #d0d0d0;
    background-color: #f7fafc;
    background-image:
        linear-gradient(to right, var(--grid-color-light) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-color-light) 1px, transparent 1px),
        linear-gradient(to right, var(--grid-color-dark) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-color-dark) 1px, transparent 1px);
    background-position: var(--bg-pos-x) var(--bg-pos-y);
    background-size: var(--bg-size) var(--bg-size), var(--bg-size) var(--bg-size), var(--bg-size-major) var(--bg-size-major), var(--bg-size-major) var(--bg-size-major);
}

/* This container holds all zoomable/pannable content */
#transform-container {
    position: absolute;
    width: 100%;
    height: 100%;
    transform-origin: 0 0;
}

/* Styles for draggable nodes */ /*
.node {
    position: absolute;
    cursor: grab;
    transition: box-shadow 0.2s, border-color 0.2s;
    border: 1px solid #666666;
}

.node:hover .connector::after,
.node.show-connectors .connector::after {
    opacity: 1;
}

.node.selected {
    border-color: #3b82f6; /* Blue border for selected /
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.4);
}

.node.is-editing {
    border-color: #93c5fd; /* Lighter blue for editing /
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.5);
    cursor: default;
}

.node.dragging {
    cursor: grabbing;
    z-index: 1000;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}*/

/*.placeholder {
    color: var(--color-text-placeholder);
    font-style: italic;
}*/

::placeholder {
  color: var(--color-text-placeholder);
  opacity: 1;
}

[contenteditable="true"], [contenteditable="plaintext-only"] {
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    cursor: text;
    outline: none;
    display: inline-block;
}

/* Connector handles on each node */
.connector {
    position: absolute;
    width: 24px;  /* Larger clickable area */
    height: 24px; /* Larger clickable area */
    cursor: crosshair;
    z-index: 10;
}
.connector::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px; /* Visible circle size */
    height: 16px;
    background-color: #666666;
    border: 2px solid white;
    border-radius: 50%;
    transition: background-color 0.2s, opacity 0.2s;
    opacity: 0; /* Hidden by default, shown on hover/selection */
    pointer-events: none; /* Clicks pass through to the parent .connector */
}
.connector:hover::after {
    background-color: #2d3748;
    opacity: 1;
}
.is-exporting .connector::after {
    opacity: 0 !important;
}
.is-exporting .node,
.is-exporting .connector::after {
    transition: none !important;
}
.connector.top { top: -12px; left: 50%; transform: translateX(-50%); }
.connector.right { right: -12px; top: 50%; transform: translateY(-50%); }
.connector.bottom { bottom: -12px; left: 50%; transform: translateX(-50%); }
.connector.left { left: -12px; top: 50%; transform: translateY(-50%); }


/* SVG layer and lines */
#svg-layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: all;
    z-index: 5; /* Above the grid background (0) but below UI elements */
}

#svg-layer line.visible-edge {
    pointer-events: none;
    transition: stroke 0.2s, stroke-width 0.2s;
}
#svg-layer line.visible-edge.selected {
    stroke: #3b82f6;
    stroke-width: 3;
    fill: #3b82f6;
}
#svg-layer line.visible-edge.cycle-error {
    stroke: #dc2626 !important;
    fill: #dc2626 !important;
    stroke-dasharray: 8,4 !important;
}
#svg-layer line.hit-area-edge {
    pointer-events: stroke;
    cursor: pointer;
}

#temp-line.dashed {
    stroke-dasharray: 5,5;
}
#temp-line.warning {
    stroke: #dc2626 !important;
}
#temp-line {
    stroke-dasharray: none;
    stroke: #2d3748;
    stroke-width: 2;
    display: none; /* Hidden by default */
}


.edge-label {
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
    fill: #2d3748;
    text-anchor: middle;
    dominant-baseline: middle;
    cursor: pointer;
    pointer-events: all;
}
.edge-label-bg {
    fill: #f7fafc;
    stroke: #f7fafccc;
    stroke-width: 8px;
    stroke-linejoin: round;
}

/* Context Menu */
#context-menu {
    position: absolute;
    z-index: 2000;
    display: none;
    width: 150px;
}
#context-menu button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
#context-menu button.hidden {
    display: none;
}

/* Selection Box */
#selection-box {
    position: absolute;
    border: 2px solid #3b82f6;
    background-color: #3b82f633;
    pointer-events: none;
    z-index: 3000;
}

/* Edge Label Editor */
#edge-label-editor {
    position: absolute;
    z-index: 4000;
    transform: translate(-50%, -50%);
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    color: #2d3748;
    background-color: #f7fafc;
    border: 2px solid #3b82f6;
    border-radius: 4px;
    padding: 2px 4px;
    text-align: center;
    outline: none;
}

/* Custom Node Styles */

.node-tag {
    border-right: 1px solid #666666;
    border-bottom: 1px solid #666666;
    overflow: hidden;
}
.node-heading {
    border-bottom: 1px solid #666666;
    overflow:hidden;
    white-space: nowrap;
    text-align: left;
}
.node-description {
    overflow:hidden;
    text-align: left;
}
.node-type {
    border-right: 1px solid #666666;
    border-top: 1px solid #666666;
}
.node-value {
    border-top: 1px solid #666666;
    border-top-right-radius: 0;
    border-bottom-left-radius: 0;
    border-top-left-radius: 0;
    border-bottom-right-radius: 0.5rem;
}
[contenteditable="true"]:focus,
[contenteditable="plaintext-only"]:focus {
    outline: none;
}

.chevron-down {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 8px;
    stroke-width: 1.5;
    margin-right: -0.25em;
    margin-bottom: -0.25em;
    stroke: #2d374899;
}

/* Annotations */
.annotation-text {
    min-width: 40px;
    min-height: 24px;
    max-width: 600px;
    box-shadow: none;
    padding: 0.25rem 0.5rem;
    border: none;
    cursor: grab;
    user-select: none;
    text-wrap: nowrap;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    white-space: pre;      /* Prevent wrapping, preserve spaces */
    width: auto;           /* Let JS set the width */
    min-width: 40px;
    max-width: none;       /* Remove max-width restriction */
    overflow: visible;     /* Show all content */
}
.annotation-text[contenteditable="true"] {
    outline: none;
    background: #fffbe7;
    border: 1px solid #e2e8f0;
    padding: calc(0.25rem - 1px) calc(0.5rem - 1px);
    user-select: text;
    text-wrap: nowrap;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    cursor: text;
    white-space: pre;      /* Prevent wrapping, preserve spaces */
    width: auto;           /* Let JS set the width */
    min-width: 40px;
    max-width: none;       /* Remove max-width restriction */
    overflow: visible;     /* Show all content */
}
.annotation-text.selected {
    border: 1px solid #3b82f6 !important;
    padding: calc(0.25rem - 1px) calc(0.5rem - 1px);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.4);
}
.annotation-text.dragging {
    cursor: grabbing !important;
    z-index: 1000;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.annotation-frame {
    background: transparent;
    border: none; /* Remove border from parent */
    border-radius: 1rem;
    position: absolute;
    box-sizing: border-box;
    pointer-events: none;
    min-width: 40px;
    min-height: 40px;
    z-index: 1;
}

.annotation-frame.selected .frame-border-visual {
    border-color: #3b82f6 !important; /* Blue, matches selected edge */
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.4);
}

.annotation-frame.dragging {
    z-index: 1000 !important;
}
.annotation-frame.dragging .frame-title,
.annotation-frame.dragging .frame-border-overlay,
.annotation-frame.dragging .frame-resize-hit-area {
    cursor: grabbing !important;
}
.annotation-frame.dragging .frame-border-visual {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.frame-border-visual {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border: 2px solid #999999;
    border-radius: 1rem;
    pointer-events: none;
    z-index: 2; /* Above handle */
}



.frame-title {
    border-radius: 0.5rem;
    background-color: #f3f4f6;
    pointer-events: auto; /* Allow interaction */
    z-index: 3; /* Above border */
    position: absolute;
    color: #666666;
    top: -16px;
    left: 20px;
    height: 32px;
    padding: 0.25rem 0.5rem;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}
.frame-title.is-editing {
    cursor: text;
    border: 1px solid #aac6f6;
    padding: calc(0.25rem - 1px) calc(0.5rem - 1px);
    text-overflow: clip;
    overflow: hidden;
}

.frame-resize-handle {
    width: 1rem;
    height: 1rem;
    background: #666666;
    position: absolute;
    right: 1px;
    bottom: 1px;
    border-radius: 0.25rem 0 1rem 0;
    cursor: se-resize;
    pointer-events: auto;
    z-index: 1; /** Below border and title */
    opacity: 0; /* Hidden by default, shown on hover */
    transition: opacity 0.15s;
}
.frame-resize-hit-area {
    position: absolute;
    right: 1px;
    bottom: 1px;
    width: 1rem;
    height: 1rem;
    background: transparent;
    border-radius: 0.25rem; /* Less rounded */
    cursor: se-resize;
    opacity: 1; /* Invisible but interactive */
    /*outline: 1px dashed #3b82f6;*/ /* Optionally, add a visible outline for debugging */
}
.annotation-frame:hover .frame-resize-handle, .frame-border-visual,
.frame-resize-handle:hover {
    opacity: 1;
}
.frame-resize-handle.is-resizing-frame,
.frame-resize-hit-area.is-resizing-frame {
    opacity: 1 !important;
}
/* Border overlays for dragging the frame by edge */
.frame-border-overlay {
    pointer-events: auto;
    position: absolute;
    background: transparent; /* No background, just for hit-testing */
    z-index: 3; /* Above border */
    /* outline: 1px dashed #3b82f6; */ /* Optionally, add a visible outline for debugging */
}


#diagram-container.drag-over {
    outline: 3px dashed var(--primary-color, #3b82f6);
    outline-offset: -6px;
    background-color: rgba(59, 130, 246, 0.05);
}

#diagram-container.drag-over::after {
    content: "Drop .sdia file to open";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 1rem 2rem;
    background: var(--primary-color, #3b82f6);
    color: white;
    border-radius: 0.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}