/* ============================================================
   Layout
   ============================================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body,
#app {
    height: 100%;
    font-family:
        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    background: #f0f2f5;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
}

/* ============================================================
   Diagram title bar
   ============================================================ */
#diagram-title {
    background: #0f172a;
    color: #94a3b8;
    font-size: 11px;
    font-weight: 500;
    padding: 3px 12px;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.02em;
}

#diagram-title .dirty-indicator {
    color: #f59e0b;
    font-size: 9px;
    vertical-align: middle;
}

/* ============================================================
   Menu bar
   ============================================================ */
#menu-bar {
    display: flex;
    align-items: stretch;
    background: #0f172a;
    border-bottom: 1px solid #1e293b;
    flex-shrink: 0;
    padding: 0 4px;
    user-select: none;
}

.menu {
    position: relative;
}

.menu-title {
    display: flex;
    align-items: center;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 12px;
    font-family: inherit;
    padding: 3px 10px;
    cursor: pointer;
    border-radius: 3px;
    white-space: nowrap;
    height: 100%;
    transition:
        color 0.1s,
        background 0.1s;
}

.menu-title:hover,
.menu.open .menu-title {
    background: #1e293b;
    color: #e2e8f0;
}

.menu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    z-index: 1100;
    min-width: 220px;
    padding: 4px 0;
    list-style: none;
}

.menu.open .menu-dropdown {
    display: block;
}

.menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 6px 14px 6px 14px;
    background: none;
    border: none;
    color: #e2e8f0;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    gap: 24px;
}

.menu-item:hover {
    background: #2563eb;
    color: #fff;
}

.menu-item:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.menu-item kbd {
    font-family: inherit;
    font-size: 11px;
    color: #64748b;
    flex-shrink: 0;
}

.menu-item:hover kbd {
    color: rgba(255, 255, 255, 0.6);
}

.menu-sep {
    height: 1px;
    background: #334155;
    margin: 4px 0;
}

/* ============================================================
   Toolbar
   ============================================================ */
#toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: #1e293b;
    border-bottom: 1px solid #0f172a;
    color: #e2e8f0;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 3px;
}

.toolbar-separator {
    margin-left: 6px;
    padding-left: 10px;
    border-left: 1px solid #334155;
}

#toolbar button {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    background: #334155;
    color: #e2e8f0;
    border: 1px solid #475569;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    white-space: nowrap;
    transition:
        background 0.1s,
        border-color 0.1s;
    user-select: none;
}

#toolbar button:hover {
    background: #475569;
    border-color: #64748b;
}

#toolbar button:active {
    background: #1e40af;
}

#toolbar .tool-btn.active {
    background: #2563eb;
    border-color: #3b82f6;
    color: #fff;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

/* Generic active toggle state for toolbar buttons (e.g. snap-to-grid) */
#toolbar button.btn-active {
    background: #d97706;
    border-color: #f59e0b;
    color: #fff;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3);
}

/* Snap button icon states */
#btn-snap .snap-icon-on  { display: none; }
#btn-snap.btn-active .snap-icon-off { display: none; }
#btn-snap.btn-active .snap-icon-on  { display: inline; }

#toolbar button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

#toolbar-status {
    margin-left: auto;
    font-size: 11px;
    color: #94a3b8;
}

/* ============================================================
   Main area
   ============================================================ */
#main {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* ============================================================
   Icon Library Panel
   ============================================================ */
#icon-panel {
    display: flex;
    flex-direction: column;
    width: 240px;
    flex-shrink: 0;
    background: #1e293b;
    border-right: 1px solid #0f172a;
    overflow: hidden;
    transition: width 0.2s ease;
}

#icon-panel.icon-panel-closed {
    width: 0;
}

#icon-panel-header {
    padding: 8px;
    border-bottom: 1px solid #0f172a;
    flex-shrink: 0;
}

#icon-search {
    width: 100%;
    padding: 5px 8px;
    background: #0f172a;
    color: #e2e8f0;
    border: 1px solid #334155;
    border-radius: 4px;
    font-size: 12px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
}

#icon-search::placeholder {
    color: #475569;
}
#icon-search:focus {
    border-color: #3b82f6;
}

#icon-tree {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 0;
}

#icon-tree::-webkit-scrollbar {
    width: 6px;
}
#icon-tree::-webkit-scrollbar-track {
    background: transparent;
}
#icon-tree::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 3px;
}

.icon-provider {
    margin-bottom: 2px;
}

.icon-provider-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    user-select: none;
    background: #162032;
}

.icon-provider-header:hover {
    color: #e2e8f0;
    background: #1e2d3e;
}

.icon-category {
    margin-bottom: 1px;
}

.icon-category-header {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px 4px 18px;
    cursor: pointer;
    font-size: 11px;
    color: #64748b;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-category-header:hover {
    color: #94a3b8;
    background: #1e2d3e;
}

.icon-chevron {
    font-size: 9px;
    flex-shrink: 0;
    transition: transform 0.15s;
    display: inline-block;
}

.icon-chevron.open {
    transform: rotate(90deg);
}

.icon-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 8px 6px 24px;
}

.icon-grid.hidden {
    display: none;
}

.icon-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 52px;
    padding: 4px 2px;
    border-radius: 4px;
    cursor: grab;
    user-select: none;
    border: 1px solid transparent;
}

.icon-item:hover {
    background: #334155;
    border-color: #475569;
}

.icon-item.dragging {
    opacity: 0.4;
}

.icon-item img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    pointer-events: none;
}

.icon-item span {
    font-size: 9px;
    color: #64748b;
    text-align: center;
    line-height: 1.2;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    pointer-events: none;
}

.icon-item:hover span {
    color: #94a3b8;
}

/* ============================================================
   Left toolbar (drawing tools)
   ============================================================ */
#left-toolbar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 5px;
    background: #1e293b;
    border-right: 1px solid #0f172a;
    flex-shrink: 0;
    width: 48px;
}

#left-toolbar .tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 36px;
    height: 32px;
    padding: 4px 2px;
    background: #334155;
    color: #e2e8f0;
    border: 1px solid #475569;
    border-radius: 5px;
    cursor: pointer;
    font-size: 10px;
    font-family: inherit;
    white-space: nowrap;
    transition:
        background 0.1s,
        border-color 0.1s;
    user-select: none;
}

#left-toolbar .tool-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

#left-toolbar .tool-btn span:not(#shape-tool-icon) {
    display: none;
}

#left-toolbar .tool-btn:hover {
    background: #475569;
    border-color: #64748b;
}

#left-toolbar .tool-btn:active {
    background: #1e40af;
}

#left-toolbar .tool-btn.active {
    background: #2563eb;
    border-color: #3b82f6;
    color: #fff;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.left-tb-sep {
    width: 80%;
    border-top: 1px solid #334155;
    margin: 4px 0;
}

/* Pop-out indicator triangle on the Shape tool button */
#btn-shape-tool {
    position: relative;
}

#btn-shape-tool::after {
    content: '';
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 0 5px 5px;
    border-color: transparent transparent #94a3b8 transparent;
    pointer-events: none;
}

#btn-shape-tool.active::after {
    border-color: transparent transparent rgba(255,255,255,0.7) transparent;
}

/* Shape pop-out panel */
#shape-popout {
    position: fixed;
    z-index: 1200;
    background: #1e293b;
    border: 1px solid #475569;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    min-width: 152px;
    display: none;
}

#shape-popout.open {
    display: block;
}

#shape-popout-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
    margin-bottom: 8px;
    text-align: center;
}

#shape-popout-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.shape-popout-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 4px;
    background: #334155;
    color: #e2e8f0;
    border: 1px solid #475569;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0;
    font-family: inherit;
    transition:
        background 0.1s,
        border-color 0.1s;
    user-select: none;
}

.shape-popout-btn svg {
    width: 20px;
    height: 20px;
}

.shape-popout-btn:hover {
    background: #475569;
    border-color: #64748b;
}

.shape-popout-btn.active {
    background: #2563eb;
    border-color: #3b82f6;
    color: #fff;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

#app-version {
    margin-top: auto;
    padding-top: 8px;
    font-size: 9px;
    color: #475569;
    text-align: center;
    user-select: none;
    letter-spacing: 0.04em;
    word-break: break-all;
}

/* ============================================================
   Canvas
   ============================================================ */
#canvas-container {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    position: relative;
    background: #f8fafc;
    /* Dot grid */
    background-image: radial-gradient(circle, #cbd5e1 1px, transparent 1px);
    background-size: 24px 24px;
    overflow: hidden;
}

#canvas {
    flex: 1;
    min-height: 0;
    display: block;
}

/* ============================================================
   Tab bar
   ============================================================ */
#tab-bar {
    display: flex;
    align-items: center;
    background: #1e293b;
    border-top: 1px solid #0f172a;
    min-height: 32px;
    padding: 3px 6px;
    gap: 2px;
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: thin;
}

.tab-bar-links {
    margin-left: auto;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.tab-privacy-link {
    padding: 3px 10px;
    font-size: 11px;
    color: #475569;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.1s;
}

.tab-privacy-link:hover {
    color: #94a3b8;
    text-decoration: underline;
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px 3px 10px;
    background: #334155;
    border: 1px solid #475569;
    border-radius: 4px;
    color: #94a3b8;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    max-width: 160px;
    transition:
        background 0.1s,
        color 0.1s;
}

.tab-btn:hover {
    background: #475569;
    color: #e2e8f0;
}

.tab-btn.active {
    background: #1e40af;
    border-color: #3b82f6;
    color: #fff;
}

.tab-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 110px;
}

.tab-close {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 0;
    font-size: 14px;
    line-height: 1;
    opacity: 0;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    pointer-events: none;
    transition: opacity 0.1s;
}

.tab-btn:hover .tab-close,
.tab-btn.active .tab-close,
.tab-close:focus-visible {
    opacity: 0.4;
    pointer-events: auto;
}

.tab-close:hover {
    opacity: 1;
}

.tab-add-btn {
    background: none;
    border: 1px solid transparent;
    color: #64748b;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 1px 8px;
    border-radius: 4px;
    flex-shrink: 0;
    font-family: inherit;
}

.tab-add-btn:hover {
    background: #334155;
    color: #e2e8f0;
    border-color: #475569;
}

.tab-rename-input {
    background: #0f172a;
    border: 1px solid #3b82f6;
    color: #e2e8f0;
    font-size: 12px;
    font-family: inherit;
    padding: 1px 4px;
    border-radius: 2px;
    width: 90px;
    outline: none;
}

/* ============================================================
   SVG — Nodes (all shape types share .node-shape)
   ============================================================ */
.node-shape {
    fill: var(--node-fill, #ffffff);
    stroke: var(--node-stroke, #475569);
    stroke-width: 1.5;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.1));
    cursor: move;
}

.node-shape.selected {
    stroke: #2563eb !important;
    stroke-width: 2.5 !important;
    filter: drop-shadow(0 0 5px rgba(37, 99, 235, 0.45)) !important;
}

.node-shape.connector-hover {
    stroke: #16a34a !important;
    stroke-width: 2 !important;
    stroke-dasharray: 4 2 !important;
}

.node-shape.connector-target {
    stroke: #16a34a !important;
    stroke-width: 2 !important;
}

.node-label {
    fill: #1e293b;
    font-family:
        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    pointer-events: none;
    user-select: none;
}

/* ============================================================
   SVG — Edges
   ============================================================ */
.edge-hit {
    stroke: transparent;
    stroke-width: 12;
    fill: none;
    cursor: pointer;
}

.edge-line {
    stroke-width: 1.5;
    fill: none;
    cursor: pointer;
}

.edge-line.selected {
    stroke-width: 2;
}

.edge-label {
    fill: #475569;
    font-family:
        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    pointer-events: none;
    user-select: none;
    background: #f8fafc;
}

.edge-label-bg {
    fill: #f8fafc;
    stroke: none;
}

/* Arrowheads inherit colour from the referencing line element via currentColor */
.arrow-fill {
    fill: currentColor;
}
.arrow-fill-sel {
    fill: currentColor;
}

/* Line endpoint symbols (dot / square) */
.line-sym-fill {
    fill: currentColor;
    stroke: none;
}
.line-sym-fill-sel {
    fill: currentColor;
    stroke: none;
}

/* ER (Crow's Foot) connector end markers */
.er-marker-line {
    stroke: currentColor;
    stroke-width: 1.5;
    fill: none;
}
.er-marker-circle {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
}

/* ============================================================
   SVG — Line endpoint handles
   ============================================================ */
.line-endpoint-handle {
    fill: #ffffff;
    stroke: #64748b;
    stroke-width: 1.5;
    cursor: move;
}

.line-endpoint-handle:hover {
    fill: #f1f5f9;
    stroke: #2563eb;
}

/* ============================================================
   SVG — Waypoint handles
   ============================================================ */
.waypoint-handle {
    fill: #ffffff;
    stroke: #2563eb;
    stroke-width: 1.5;
    cursor: move;
}

.waypoint-handle:hover {
    fill: #dbeafe;
}

.edge-endpoint-handle {
    fill: #16a34a;
    stroke: #ffffff;
    stroke-width: 1.5;
    cursor: move;
}

.edge-endpoint-handle:hover {
    fill: #22c55e;
}

/* ============================================================
   SVG — Annotations
   ============================================================ */
.annotation-text {
    fill: #7c3aed;
    font-family:
        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    cursor: move;
}

.annotation-bg {
    fill: none;
    stroke: none;
    pointer-events: none;
}

.annotation-selection {
    fill: none;
    stroke: #2563eb;
    stroke-width: 1.5;
    stroke-dasharray: 4 3;
    pointer-events: none;
}

/* ============================================================
   SVG — Resize handles
   ============================================================ */
.resize-handle {
    fill: #ffffff;
    stroke: #2563eb;
    stroke-width: 1.5;
    cursor: pointer;
}

/* ============================================================
   SVG — Temporary drawing shapes
   ============================================================ */
.temp-shape {
    fill: rgba(37, 99, 235, 0.05);
    stroke: #2563eb;
    stroke-width: 1.5;
    stroke-dasharray: 5 3;
    pointer-events: none;
}

.temp-connector {
    stroke: #2563eb;
    stroke-width: 1.5;
    stroke-dasharray: 6 3;
    fill: none;
    marker-end: url(#arrowhead-sel);
    pointer-events: none;
}

.selection-box {
    fill: rgba(37, 99, 235, 0.06);
    stroke: #2563eb;
    stroke-width: 1;
    stroke-dasharray: 4 3;
    pointer-events: none;
}

.group-selection {
    fill: rgba(139, 92, 246, 0.05);
    stroke: #7c3aed;
    stroke-width: 1.5;
    stroke-dasharray: 6 3;
    pointer-events: none;
}

/* ============================================================
   SVG — Inline editor (foreignObject input)
   ============================================================ */
.inline-input {
    box-sizing: border-box;
    border: 1.5px solid #2563eb;
    border-radius: 3px;
    background: #fff;
    color: #1e293b;
    font-size: 13px;
    font-family:
        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    padding: 2px 5px;
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

/* Single-line node/edge label inputs are centred; textarea annotation editors use their own text-align */
input.inline-input {
    text-align: center;
}

.inline-textarea {
    text-align: left;
    resize: both;
    overflow: auto;
    line-height: 1.4;
}

/* ============================================================
   Properties panel
   ============================================================ */
#properties-header {
    padding: 10px 14px 8px;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#btn-collapse-props {
    background: none;
    border: none;
    cursor: pointer;
    color: #64748b;
    font-size: 18px;
    line-height: 1;
    padding: 0 0 0 6px;
    display: flex;
    align-items: center;
    transition: color 0.15s;
}
#btn-collapse-props:hover { color: #1e293b; }

/* Collapsed state */
#right-panel {
    display: flex;
    flex-direction: column;
    width: 210px;
    flex-shrink: 0;
    border-left: 1px solid #e2e8f0;
    overflow: hidden;
    transition: width 0.2s ease;
}

#properties-panel {
    flex: 1;
    min-height: 0;
    background: #fff;
    display: flex;
    flex-direction: column;
}

#right-panel.props-collapsed {
    width: 28px;
}
#right-panel.props-collapsed #properties-header span,
#right-panel.props-collapsed #properties-content,
#right-panel.props-collapsed #layers-panel {
    display: none;
}
#right-panel.props-collapsed #properties-header {
    padding: 10px 4px 8px;
    justify-content: center;
    border-bottom: none;
}
#right-panel.props-collapsed #btn-collapse-props {
    padding: 0;
}

#properties-content {
    padding: 0;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.no-selection {
    padding: 12px;
    color: #94a3b8;
    font-style: italic;
    font-size: 12px;
}

.prop-group {
    margin-bottom: 10px;
}

/* ============================================================
   Collapsible property sections
   ============================================================ */
.prop-section {
    border-bottom: 1px solid #e2e8f0;
}

.prop-section:last-child {
    border-bottom: none;
}

.prop-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 14px;
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
    user-select: none;
    list-style: none;
    background: #f1f5f9;
}

.prop-section-title::-webkit-details-marker {
    display: none;
}

.prop-section-title::after {
    content: '▸';
    font-size: 10px;
    color: #94a3b8;
    transition: transform 0.15s;
    flex-shrink: 0;
}

.prop-section[open] > .prop-section-title::after {
    transform: rotate(90deg);
}

.prop-section-title:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.prop-section-body {
    padding: 10px 14px 4px;
}

.prop-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 3px;
}

.prop-group input[type='text'],
.prop-group input[type='number'] {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    color: #1e293b;
    background: #f8fafc;
    outline: none;
    transition: border-color 0.1s;
}

.prop-group input:focus {
    border-color: #2563eb;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.prop-value {
    font-size: 13px;
    color: #475569;
}

#properties-hint {
    padding: 12px 14px;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

#properties-hint p {
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

#properties-hint ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

#properties-hint li {
    font-size: 11px;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 6px;
}

kbd {
    display: inline-block;
    padding: 1px 5px;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 3px;
    font-size: 10px;
    font-family: monospace;
    color: #475569;
    white-space: nowrap;
}

/* ============================================================
   Layers Panel
   ============================================================ */
#layers-panel {
    flex-shrink: 0;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    min-height: 120px;
    max-height: 30%;
    overflow: hidden;
}

#layers-header {
    padding: 8px 14px 7px;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#layers-header button {
    background: none;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 2px 5px;
    cursor: pointer;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

#layers-header button:hover {
    background: #f1f5f9;
    color: #2563eb;
    border-color: #93c5fd;
}

#layers-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.layer-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    cursor: grab;
    border-radius: 4px;
    margin: 1px 4px;
    font-size: 12px;
    color: #1e293b;
    transition: background 0.1s;
    user-select: none;
    border-top: 2px solid transparent;
}

.layer-row:hover {
    background: #f1f5f9;
}

.layer-row.layer-active {
    background: #eff6ff;
    color: #1d4ed8;
}

.layer-row.layer-hidden {
    color: #94a3b8;
}

.layer-row.layer-locked .layer-name {
    color: #94a3b8;
    font-style: italic;
}

.layer-row.layer-locked {
    border-left: 2px solid #f59e0b;
}

.layer-row.dragging {
    opacity: 0.4;
    cursor: grabbing;
}

.layer-row.drag-over-above {
    border-top: 2px solid #2563eb;
}

.layer-row.drag-over-below {
    border-bottom: 2px solid #2563eb;
}

.layer-eye {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    color: #94a3b8;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.layer-eye:hover {
    color: #2563eb;
}

.layer-lock {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    color: #cbd5e1;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    transition: color 0.1s;
}

.layer-lock:hover {
    color: #f59e0b;
}

.layer-row.layer-locked .layer-lock {
    color: #f59e0b;
}

.layer-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.layer-rename-input {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    font-family: inherit;
    padding: 1px 4px;
    border: 1px solid #93c5fd;
    border-radius: 3px;
    outline: none;
    background: #fff;
    color: #1e293b;
}

.layer-delete {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    color: #cbd5e1;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.1s, color 0.1s;
}

.layer-row:hover .layer-delete {
    opacity: 1;
}

.layer-delete:hover {
    color: #ef4444;
}

.layer-delete:disabled {
    opacity: 0 !important;
    cursor: default;
}

.active-layer-hint {
    font-size: 11px;
    color: #64748b;
    margin-top: 6px;
    padding: 4px 6px;
    background: #f8fafc;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
}

.active-layer-hint strong {
    color: #1d4ed8;
}

.locked-layer-banner {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 10px;
    padding: 10px 12px;
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 6px;
    font-size: 12px;
    color: #92400e;
    line-height: 1.4;
}

/* ============================================================
   Zoom controls
   ============================================================ */
#zoom-select {
    padding: 5px 6px;
    background: #334155;
    color: #e2e8f0;
    border: 1px solid #475569;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    outline: none;
    transition:
        background 0.1s,
        border-color 0.1s;
    min-width: 62px;
}

#zoom-select:hover {
    background: #475569;
    border-color: #64748b;
}
#zoom-select:focus {
    border-color: #3b82f6;
}

/* ============================================================
   Shape picker
   ============================================================ */
#shape-picker {
    display: flex;
    align-items: center;
    gap: 2px;
}

.shape-label {
    font-size: 11px;
    color: #94a3b8;
    margin-right: 2px;
    white-space: nowrap;
}

.shape-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: #334155;
    color: #e2e8f0;
    border: 1px solid #475569;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition:
        background 0.1s,
        border-color 0.1s;
    user-select: none;
}

.shape-btn svg {
    width: 24px;
    height: 24px;
}

.shape-btn:hover {
    background: #475569;
}
.shape-btn.active {
    background: #2563eb;
    border-color: #3b82f6;
    color: #fff;
}

/* Shape select in properties panel */
.prop-group select {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    color: #1e293b;
    background: #f8fafc;
    outline: none;
    cursor: pointer;
}

.prop-group select:focus {
    border-color: #2563eb;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* Colour input row */
/* ---- Colour target rows (select which property to edit) ---- */
.color-target-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 2px;
}

.color-target-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    padding: 4px 8px;
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    color: #475569;
    text-align: left;
    transition:
        background 0.1s,
        border-color 0.1s;
}

.color-target-btn:hover {
    background: #f8fafc;
    border-color: #e2e8f0;
}

.color-swatch-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    display: inline-block;
}

.color-target-active .color-target-btn {
    background: #eff6ff;
    border-color: #6366f1;
    color: #1e293b;
}

.color-reset-btn {
    font-size: 13px;
    padding: 2px 5px;
    background: none;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    font-family: inherit;
    transition: color 0.1s;
}

.color-reset-btn:hover {
    color: #475569;
}

/* ---- Shared colour picker section ---- */
.color-shared-section {
    margin-top: 6px;
    padding: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

.color-shared-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.color-pick-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    color: #334155;
    flex: 1;
    transition:
        border-color 0.1s,
        background 0.1s;
}

.color-pick-btn:hover {
    border-color: #6366f1;
    background: #eef2ff;
}

.color-pick-swatch {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    display: inline-block;
}

.color-hex-display {
    font-size: 11px;
    font-family: monospace;
    color: #475569;
    min-width: 54px;
    text-align: center;
}

.color-save-btn {
    font-size: 15px;
    font-weight: 600;
    line-height: 1;
    padding: 2px 7px;
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 3px;
    cursor: pointer;
    color: #64748b;
    font-family: inherit;
    transition:
        border-color 0.1s,
        color 0.1s,
        background 0.1s;
}

.color-save-btn:hover {
    border-color: #6366f1;
    color: #6366f1;
    background: #eef2ff;
}

.palette-strip {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    margin-bottom: 2px;
}

.palette-swatch {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: transform 0.1s, box-shadow 0.1s;
}

.palette-swatch:hover {
    transform: scale(1.15);
    box-shadow: 0 0 0 2px #6366f1;
}

.palette-swatch-empty {
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    cursor: default;
}

.palette-swatch-empty:hover {
    transform: none;
    box-shadow: none;
}

/* ============================================================
   Opacity control
   ============================================================ */
.opacity-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.opacity-row input[type='range'] {
    flex: 1;
    height: 4px;
    cursor: pointer;
    accent-color: #2563eb;
}

.opacity-row span {
    font-size: 12px;
    font-family: monospace;
    color: #475569;
    min-width: 34px;
    text-align: right;
    flex-shrink: 0;
}

/* ============================================================
   Font controls (size select + B/I/U toggles)
   ============================================================ */
.font-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.font-size-select {
    flex: 1;
    min-width: 0;
    padding: 4px 6px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 12px;
    font-family: inherit;
    color: #1e293b;
    background: #f8fafc;
    outline: none;
    cursor: pointer;
}

.font-size-select:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.font-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    background: #f8fafc;
    color: #475569;
    cursor: pointer;
    font-size: 13px;
    font-family: serif;
    flex-shrink: 0;
    transition:
        background 0.1s,
        border-color 0.1s,
        color 0.1s;
    user-select: none;
}

.font-btn:hover {
    border-color: #94a3b8;
    background: #f1f5f9;
}

.font-btn.active {
    background: #2563eb;
    border-color: #1d4ed8;
    color: #fff;
}

/* ── Floating align/distribute popup ──────────────────────────── */
.align-popup {
    position: fixed;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 6px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.align-popup[hidden] {
    display: none;
}

.align-popup-row {
    display: flex;
    gap: 3px;
}

.align-popup-divider {
    border-top: 1px solid #334155;
    margin: 2px 0;
}

.align-popup-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: #334155;
    border: 1px solid #475569;
    border-radius: 4px;
    color: #e2e8f0;
    cursor: pointer;
}

.align-popup-btn:hover {
    background: #475569;
    border-color: #64748b;
}

.align-popup-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

#btn-align-toggle.active {
    background: #2563eb;
    border-color: #1d4ed8;
}

/* ── Label position picker (3×3 grid) ─────────────────────────── */
.pos-picker {
    display: inline-grid;
    grid-template-columns: repeat(3, 22px);
    gap: 3px;
}

.pos-btn {
    width: 22px;
    height: 22px;
    border: 1px solid #cbd5e1;
    border-radius: 3px;
    background: #f8fafc;
    cursor: pointer;
    padding: 0;
    position: relative;
}

.pos-btn::after {
    content: '';
    position: absolute;
    width: 5px;
    height: 5px;
    background: #94a3b8;
    border-radius: 50%;
}

.pos-btn[data-pos='tl']::after {
    top: 3px;
    left: 3px;
}
.pos-btn[data-pos='tm']::after {
    top: 3px;
    left: 50%;
    transform: translateX(-50%);
}
.pos-btn[data-pos='tr']::after {
    top: 3px;
    right: 3px;
}
.pos-btn[data-pos='ml']::after {
    top: 50%;
    left: 3px;
    transform: translateY(-50%);
}
.pos-btn[data-pos='mm']::after {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.pos-btn[data-pos='mr']::after {
    top: 50%;
    right: 3px;
    transform: translateY(-50%);
}
.pos-btn[data-pos='bl']::after {
    bottom: 3px;
    left: 3px;
}
.pos-btn[data-pos='bm']::after {
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
}
.pos-btn[data-pos='br']::after {
    bottom: 3px;
    right: 3px;
}

.pos-btn:hover {
    border-color: #3b82f6;
    background: #eff6ff;
}

.pos-btn.active {
    border-color: #3b82f6;
    background: #dbeafe;
}

.pos-btn.active::after {
    background: #3b82f6;
}

/* Outside state: dashed border + amber accent to distinguish from inside */
.pos-btn.pos-btn-outside.active {
    border: 2px dashed #f59e0b;
    background: #fef9c3;
}

.pos-btn.pos-btn-outside.active::after {
    background: #f59e0b;
}

/* ── Marker picker (connector endpoints) ─────────────────── */
.marker-picker {
    display: flex;
    gap: 4px;
    align-items: center;
}

.marker-btn {
    width: 32px;
    height: 24px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #f8fafc;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #64748b;
}

.marker-btn svg {
    display: block;
    overflow: visible;
}

.marker-btn:hover {
    border-color: #3b82f6;
    background: #eff6ff;
    color: #3b82f6;
}

.marker-btn.active {
    border-color: #3b82f6;
    background: #dbeafe;
    color: #3b82f6;
}

/* ── Marker dropdown (connector endpoints — graphical, closed by default) ── */
.marker-dropdown {
    position: relative;
    display: inline-block;
}

.marker-dropdown-toggle {
    width: 44px;
    height: 24px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #f8fafc;
    cursor: pointer;
    padding: 0 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: #64748b;
}

.marker-dropdown-toggle svg {
    display: block;
    overflow: visible;
}

.marker-dropdown-caret {
    font-size: 9px;
    line-height: 1;
    flex-shrink: 0;
}

.marker-dropdown-toggle:hover,
.marker-dropdown.open .marker-dropdown-toggle {
    border-color: #3b82f6;
    background: #eff6ff;
    color: #3b82f6;
}

.marker-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 20;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 6px;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    width: max-content;
}

.marker-dropdown.open .marker-dropdown-menu {
    display: grid;
}

.marker-dropdown-option {
    width: 32px;
    height: 24px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #f8fafc;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #64748b;
}

.marker-dropdown-option svg {
    display: block;
    overflow: visible;
}

.marker-dropdown-option:hover {
    border-color: #3b82f6;
    background: #eff6ff;
    color: #3b82f6;
}

.marker-dropdown-option.active {
    border-color: #3b82f6;
    background: #dbeafe;
    color: #3b82f6;
}

/* ============================================================
   Presentation Mode
   ============================================================ */

/* Hide all chrome when in presentation mode */
body.presentation-mode #menu-bar,
body.presentation-mode #toolbar,
body.presentation-mode #left-toolbar,
body.presentation-mode #icon-panel,
body.presentation-mode #right-panel,
body.presentation-mode #tab-bar,
body.presentation-mode #shape-popout {
    display: none !important;
}

body.presentation-mode #main {
    /* canvas fills the full viewport below the now-hidden toolbar */
}

body.presentation-mode #canvas-container {
    flex: 1;
    height: 100vh;
}

/* Presentation controls overlay */
#presentation-controls {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    align-items: center;
    gap: 4px;
    background: rgba(15, 23, 42, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 6px 10px;
    backdrop-filter: blur(6px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

body.presentation-mode #presentation-controls {
    display: flex;
}

#presentation-controls button {
    display: flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: none;
    color: #e2e8f0;
    cursor: pointer;
    padding: 5px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-family: inherit;
    transition: background 0.1s;
    user-select: none;
}

#presentation-controls button:hover {
    background: rgba(255, 255, 255, 0.12);
}

#presentation-controls button:disabled {
    opacity: 0.3;
    cursor: default;
}

#pres-tab-label {
    font-size: 12px;
    color: #94a3b8;
    padding: 0 6px;
    white-space: nowrap;
    min-width: 60px;
    text-align: center;
}

.pres-sep {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.15);
    margin: 0 4px;
}

#pres-exit {
    color: #f87171 !important;
}

#pres-exit:hover {
    background: rgba(239, 68, 68, 0.15) !important;
}

/* ============================================================
   Locked layer objects — force default cursor on all children
   ============================================================ */
.layer-locked .node-shape,
.layer-locked image,
.layer-locked .edge-hit,
.layer-locked .edge-line,
.layer-locked .annotation-text,
.layer-locked .annotation-bg {
    cursor: default !important;
}
