@import url('open-iconic/font/css/open-iconic-bootstrap.min.css');
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

/* DatabaseForge Brand Colors */
:root {
    --df-navy: #0d1b2a;
    --df-navy-light: #1b2838;
    --df-blue: #4a90d9;
    --df-blue-light: #5ba3e8;
    --df-silver: #b0bec5;
    --df-white: #ffffff;
}

html,
body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

h1:focus {
    outline: none;
}

a,
.btn-link {
    color: #0071c1;
}

.btn-primary {
    color: #fff;
    background-color: #1b6ec2;
    border-color: #1861ac;
}

.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

.content {
    padding-top: 1.1rem;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid red;
}

.validation-message {
    color: red;
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFB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Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred."
}

/* Diagram Highlighting & Dimming */
.table-box,
.view-box,
.relationship-line {
    transition: opacity 0.2s ease, box-shadow 0.2s ease, stroke 0.2s ease;
}

/* Tables and views render above relationship lines (SVG at z-index:5) */
.table-box,
.view-box {
    z-index: 10;
    position: relative;
    opacity: 1;
    /* Fully visible by default - not transparent */
}

.dimmed {
    opacity: 0.2 !important;
    /* pointer-events: none; - Disabled to allow hovering over dimmed items to switch focus */
}

.highlighted {
    opacity: 1 !important;
    box-shadow: 0 0 0 2px #0f62fe, 0 10px 30px rgba(0, 0, 0, 0.2) !important;
    z-index: 100 !important;
}

/* Specific styles for SVG lines */
.relationship-line.highlighted {
    stroke: #0f62fe !important;
    stroke-width: 2.5px !important;
    opacity: 1 !important;
}

/* Column row highlighting when relationship is selected */
.column-highlighted {
    background-color: rgba(59, 130, 246, 0.15) !important;
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.5) !important;
}

.dark .column-highlighted {
    background-color: rgba(59, 130, 246, 0.25) !important;
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.6) !important;
}

/* ========== Selection Animation ========== */
@keyframes selection-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 2px #3b82f6, 0 0 8px 2px rgba(59, 130, 246, 0.4);
    }

    50% {
        box-shadow: 0 0 0 3px #60a5fa, 0 0 16px 4px rgba(59, 130, 246, 0.6);
    }
}

.table-box.selected,
.view-box.selected {
    animation: selection-pulse 1.5s ease-in-out infinite !important;
    border-radius: 8px;
    outline: none;
    z-index: 100 !important;
}

.diagram-label.selected,
.diagram-shape.selected {
    animation: selection-pulse 1.5s ease-in-out infinite !important;
    outline: none;
}

/* ========== Cardinality Circles ========== */
.cardinality-circle {
    fill: white;
    stroke: #94a3b8;
    stroke-width: 1.5;
    transition: stroke 0.15s ease, stroke-width 0.15s ease, fill 0.15s ease;
    pointer-events: all;
}

.cardinality-group g:hover .cardinality-circle {
    stroke: #3b82f6;
    stroke-width: 2;
    fill: #eff6ff;
}

.cardinality-text {
    font-size: 9px;
    font-weight: 600;
    fill: #374151;
    text-anchor: middle;
    dominant-baseline: middle;
    alignment-baseline: middle;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    line-height: 0;
    pointer-events: all;
}

.dark .cardinality-circle {
    fill: #1f2937;
    stroke: #6b7280;
}

.dark .cardinality-text {
    fill: #e5e7eb;
}

/* ========== Connection Nodes for Drag-to-Connect ========== */
.connection-node {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #3b82f6;
    border: 2px solid white;
    opacity: 0;
    cursor: crosshair;
    z-index: 100;
    transition: opacity 0.15s ease, transform 0.15s ease, background-color 0.15s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.connection-node-left {
    left: -6px;
}

.connection-node-right {
    right: -6px;
}

/* Show nodes when hovering over the table */
.table-box:hover .connection-node {
    opacity: 1;
}

/* Individual node hover */
.connection-node:hover {
    transform: translateY(-50%) scale(1.3);
    background-color: #2563eb;
}

/* Active/dragging state */
.connection-node.dragging {
    opacity: 1 !important;
    transform: translateY(-50%) scale(1.4);
    background-color: #1d4ed8;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

/* Potential target node - shown when another node is being dragged */
.connection-node.potential-target {
    opacity: 1 !important;
    background-color: #10b981;
    animation: target-pulse 0.8s infinite;
}

.connection-node.potential-target:hover {
    background-color: #059669;
    transform: translateY(-50%) scale(1.4);
}

@keyframes target-pulse {

    0%,
    100% {
        box-shadow: 0 0 4px rgba(16, 185, 129, 0.4);
    }

    50% {
        box-shadow: 0 0 12px rgba(16, 185, 129, 0.8);
    }
}

/* Table highlighted as potential target */
.table-box.connection-target .connection-node {
    opacity: 1 !important;
    background-color: #10b981;
}

/* Dark mode adjustments */
.dark .connection-node {
    border-color: #1f2937;
}

/* Drag line preview */
#connection-line-preview {
    pointer-events: none;
    stroke: #3b82f6;
    stroke-width: 2;
    stroke-dasharray: 5 3;
    fill: none;
}

/* ========== Column Highlighting ========== */
.column-highlighted {
    background-color: rgba(59, 130, 246, 0.2) !important;
    animation: column-pulse 1s infinite;
}

@keyframes column-pulse {

    0%,
    100% {
        background-color: rgba(59, 130, 246, 0.2);
    }

    50% {
        background-color: rgba(59, 130, 246, 0.4);
    }
}

.column-related {
    background-color: rgba(16, 185, 129, 0.15) !important;
    animation: relationship-pulse 2s ease-in-out infinite;
}

@keyframes relationship-pulse {

    0%,
    100% {
        background-color: rgba(16, 185, 129, 0.1);
    }

    50% {
        background-color: rgba(16, 185, 129, 0.25);
    }
}

/* Columns that are part of relationships get subtle indicator */
.column-in-relationship {
    position: relative;
}

.column-in-relationship::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, #3b82f6, #10b981);
    opacity: 0.7;
}

/* Animated relationship lines */
.relationship-line-animated {
    stroke-dasharray: 10 5;
    animation: dash-animation 1s linear infinite;
    stroke-width: 2.5px !important;
}

@keyframes dash-animation {
    to {
        stroke-dashoffset: -15;
    }
}

/* ========== Table Header Gradient ========== */
.table-header-gradient {
    background: linear-gradient(to bottom, var(--gradient-color, transparent) 0%, transparent 100%);
    height: 6px;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    border-radius: 8px 8px 0 0;
    pointer-events: none;
}

/* ========== Sticky Notes ========== */
.note-box {
    position: absolute;
    background-color: var(--note-color, #fef9c3);
    border-radius: 4px;
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    cursor: move;
    min-width: 150px;
    min-height: 100px;
    transform: rotate(-1deg);
}

.note-box.selected {
    animation: selection-pulse 1.5s ease-in-out infinite !important;
}

.note-header {
    padding: 8px 10px;
    font-weight: 600;
    font-size: 13px;
    border-bottom: 1px dashed rgba(0, 0, 0, 0.15);
    cursor: grab;
    user-select: none;
    color: #374151;
}

.note-header:active {
    cursor: grabbing;
}

.note-content {
    flex: 1;
    padding: 8px 10px;
    font-size: 12px;
    color: #4b5563;
    border: none;
    background: transparent;
    resize: none;
    line-height: 1.5;
}

.note-content:focus {
    outline: none;
}

.note-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    cursor: se-resize;
}

/* ========== Group Containers ========== */
.group-box {
    position: absolute;
    border: 2px dashed;
    border-radius: 12px;
    background-color: var(--group-color, rgba(59, 130, 246, 0.1));
    border-color: var(--group-border-color, #3b82f6);
}

.group-box.selected {
    animation: selection-pulse 1.5s ease-in-out infinite !important;
}

.group-header {
    /* Header is now inside the box, not floating above */
    padding: 8px 12px;
    border-radius: 10px 10px 0 0;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    cursor: grab;
    user-select: none;
    background: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
}

.dark .group-header {
    background: #374151;
    color: #f3f4f6;
    border-bottom-color: #4b5563;
}

.group-header:active {
    cursor: grabbing;
}

.group-corner-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: white;
    border: 2px solid #94a3b8;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.group-box:hover .group-corner-handle {
    opacity: 1;
}

.group-corner-handle.nw {
    top: -5px;
    left: -5px;
    cursor: nw-resize;
}

.group-corner-handle.ne {
    top: -5px;
    right: -5px;
    cursor: ne-resize;
}

.group-corner-handle.sw {
    bottom: -5px;
    left: -5px;
    cursor: sw-resize;
}

.group-corner-handle.se {
    bottom: -5px;
    right: -5px;
    cursor: se-resize;
}

.dark .group-corner-handle {
    background: #374151;
    border-color: #6b7280;
}

/* ========== Note Corner Handles ========== */
.note-corner-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: white;
    border: 2px solid #94a3b8;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.note-box:hover .note-corner-handle {
    opacity: 1;
}

.note-corner-handle.nw {
    top: -6px;
    left: -6px;
    cursor: nw-resize;
}

.note-corner-handle.ne {
    top: -6px;
    right: -6px;
    cursor: ne-resize;
}

.note-corner-handle.sw {
    bottom: -6px;
    left: -6px;
    cursor: sw-resize;
}

.note-corner-handle.se {
    bottom: -6px;
    right: -6px;
    cursor: se-resize;
}

.dark .note-corner-handle {
    background: #374151;
    border-color: #6b7280;
}

/* ========== Label Corner Handles ========== */
.label-corner-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: white;
    border: 2px solid #94a3b8;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.label-box:hover .label-corner-handle {
    opacity: 1;
}

.label-corner-handle.nw {
    top: -5px;
    left: -5px;
    cursor: nw-resize;
}

.label-corner-handle.ne {
    top: -5px;
    right: -5px;
    cursor: ne-resize;
}

.label-corner-handle.sw {
    bottom: -5px;
    left: -5px;
    cursor: sw-resize;
}

.label-corner-handle.se {
    bottom: -5px;
    right: -5px;
    cursor: se-resize;
}

.dark .label-corner-handle {
    background: #374151;
    border-color: #6b7280;
}

/* ========== Minimap ========== */
.minimap-container {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 250px;
    height: 200px;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    overflow: hidden;
}

.dark .minimap-container {
    background: rgba(31, 41, 55, 0.95);
    border-color: #4b5563;
}

.minimap-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
}

.dark .minimap-header {
    background: #374151;
    border-color: #4b5563;
    color: #9ca3af;
}

.minimap-toggle {
    padding: 2px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #6b7280;
}

.minimap-toggle:hover {
    color: #374151;
}

.minimap-svg {
    width: 100%;
    height: calc(100% - 30px);
    cursor: pointer;
}

#minimap-viewport {
    fill: rgba(59, 130, 246, 0.2);
    stroke: #3b82f6;
    stroke-width: 2;
    pointer-events: none;
}

/* ========== Mobile Responsiveness ========== */
@media (max-width: 768px) {
    .left-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1001;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);
    }

    .left-sidebar.open {
        transform: translateX(0);
    }

    .right-sidebar {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        z-index: 1001;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
    }

    .right-sidebar.open {
        transform: translateX(0);
    }

    .mobile-menu-btn {
        display: flex !important;
    }

    .mobile-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }

    .mobile-overlay.visible {
        opacity: 1;
        pointer-events: auto;
    }

    .menu-bar {
        padding: 4px 8px !important;
    }

    .menu-trigger {
        padding: 4px 8px !important;
        font-size: 12px !important;
    }

    .minimap-container {
        width: 180px;
        height: 140px;
        bottom: 70px;
        right: 10px;
    }
}

/* Hide mobile menu on desktop */
.mobile-menu-btn {
    display: none;
}

/* Touch-friendly sizing */
@media (pointer: coarse) {
    .menu-trigger {
        min-height: 44px;
        min-width: 44px;
    }

    .context-menu-item {
        min-height: 44px;
        padding: 12px 16px;
    }

    .table-box .divide-y>div {
        min-height: 28px;
    }
}