:root {
    /* Colors */
    --color-primary: #2E5AA7;
    --color-primary-dark: #1A3A6D;
    --color-primary-light: #E1E9F5;
    /* Derived or separate? Keeping separate for now but could just use primary */
    --color-secondary: #4CAF50;

    --color-text: #000000;
    --color-bg: #F8F9FA;

    --color-white: #FFFFFF;
    --color-gray-light: #F8F9FA;
    /* Legacy, maybe keep for panels? */
    --color-gray-border: #E0E0E0;
    --color-success: var(--color-secondary);
    --color-alert: #E53935;

    /* Typography */
    --font-family: 'Inter', 'Roboto', sans-serif;

    /* Spacing */
    --spacing-unit: 8px;
    --header-height: 64px;
}

body {
    margin: 0;
    font-family: var(--font-family);
    background-color: var(--color-bg);
    color: var(--color-text);
    height: 100vh;
    overflow: hidden;
}

/* Typography */
h1,
h2,
h3 {
    margin: 0;
    font-weight: 600;
}

/* Layout */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    height: var(--header-height);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--color-gray-border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    justify-content: space-between;
    z-index: 100;
}

.brand {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.brand span {
    color: var(--color-primary);
}

/* Main Content Area */
main {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
}

/* Views */
.view {
    display: none;
    width: 100%;
    height: 100%;
}

.view.active {
    display: flex;
    /* or block depending on view */
}

/* Site Selection View */
#site-view {
    flex-direction: column;
    padding: 40px;
    align-items: center;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    width: 100%;
    max-width: 1200px;
    margin-top: 24px;
}

.card {
    background: var(--color-white);
    /* Keep cards white for contrast, or use another var? User said "everything theme-ised" */
    border: 1px solid var(--color-gray-border);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* Zone View */
#zone-view {
    position: relative;
    background-color: #000;
    overflow: hidden;
    /* display: none; Handled by .view class, but if we need specific override: */
    display: none;
    flex-direction: row;
    /* Flex Layout */
}

#zone-view.active {
    display: flex;
}

/* Zone Viewport (Wrapper) */
#zone-viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
}

/* Zone Stage */
#zone-stage {
    width: 100%;
    height: 100%;
    overflow: auto;
    /* Allow scrolling if image is wide */
    display: flex;
    /* To center content */
    position: relative;
}

#zone-image-wrapper {
    position: relative;
    height: 100%;
    margin: 0 auto;
    /* Center horizontally if space allows */
    display: inline-block;
    /* Wrap image tight */
}

#zone-background {
    height: 100%;
    width: auto;
    display: block;
    max-width: none;
    /* Allow exceeding container */
}

#nodes-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass to image/wrapper */
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: color-mix(in srgb, var(--color-bg), transparent 5%);
    /* Using color-mix for opacity on var */
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--color-gray-border);
    display: flex;
    flex-direction: column;
    position: relative;
    /* Changing from absolute to relative for flex */
    z-index: 40;
    transition: width 0.3s ease, transform 0.3s ease, margin 0.3s ease;
    flex-shrink: 0;
}

.sidebar.collapsed {
    width: 0;
    border-right: none;
    overflow: hidden;
    /* transform: translateX(-100%);  Remove transform for flex flow */
}

#sidebar-toggle-btn {
    position: absolute;
    top: 24px;
    left: 24px;
    z-index: 30;
    background: var(--color-white);
    border: 1px solid var(--color-gray-border);
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    /* Hidden when sidebar is open via JS or CSS logic */
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Hide toggle when sidebar is OPEN */
.sidebar:not(.collapsed)~#sidebar-toggle-btn {
    display: none;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--color-gray-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header button {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.5;
}

#zones-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.zone-item {
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 8px;
    transition: background 0.2s;
}

.zone-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.zone-item.active {
    background: var(--color-primary);
    color: white;
}

.add-zone-btn {
    margin: 16px;
    padding: 12px;
    background: var(--color-white);
    border: 1px solid var(--color-primary);
    color: var(--color-primary);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
}

/* Node Markers */
.node-marker {
    position: absolute;
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid var(--color-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transform: translate(-50%, -50%);
    /* Center on coordinate */
    transition: transform 0.2s;
    font-size: 20px;
    color: var(--color-primary-dark);
    pointer-events: auto;
    /* Enable clicks */
}

.node-marker:hover,
.node-marker.selected {
    transform: translate(-50%, -50%) scale(1.1);
    background: var(--color-primary);
    color: var(--color-white);
    z-index: 10;
}

/* Node Properties Panel */
#properties-panel {
    width: 320px;
    background: color-mix(in srgb, var(--color-bg), transparent 5%);
    backdrop-filter: blur(20px);
    border-left: 1px solid var(--color-gray-border);
    padding: 24px;
    display: none;
    /* Hidden by default */
    flex-direction: column;
    position: relative;
    /* relative for flex */
    z-index: 50;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

#properties-panel.open {
    display: flex;
}

.panel-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--color-gray-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.5;
}

/* Controls */
#panel-content {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    /* Fix for flex scrolling */
    padding-right: 4px;
    /* Space for scrollbar */
}

/* Controls */
.control-group {
    margin-bottom: 20px;
}

.control-label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-primary-dark);
}

/* Inputs */
select,
input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #CED4DA;
    font-family: inherit;
    font-size: 14px;
}

input[type="range"] {
    width: 100%;
}

button.primary {
    background: var(--color-primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    width: 100%;
}

button.primary:hover {
    background: var(--color-primary-dark);
}

.toggle-switch {
    /* Simple CSS Toggle */
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

/* Add Node Button */
.add-node-btn {
    position: absolute;
    bottom: 24px;
    left: 24px;
    /* Default left */
    z-index: 20;
    background: var(--color-white);
    color: var(--color-primary);
    border: 1px solid var(--color-gray-border);
    padding: 12px 24px;
    border-radius: 24px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: left 0.3s ease;
}

/* If sidebar is present and not collapsed */
.sidebar:not(.collapsed)~.add-node-btn {
    left: 304px;
    /* 280 + 24 */
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--color-gray-border);
    border-radius: 8px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    margin-bottom: 12px;
    background: var(--color-bg);
    transition: background 0.2s, border-color 0.2s;
}

.upload-area:hover,
.upload-area.dragover {
    background: color-mix(in srgb, var(--color-bg), var(--color-primary) 10%);
    border-color: var(--color-primary);
}

.badge-success {
    color: var(--color-success);
    font-weight: 600;
    padding: 8px 16px;
    background: color-mix(in srgb, var(--color-success), transparent 90%);
    border-radius: 6px;
    border: 1px solid color-mix(in srgb, var(--color-success), transparent 80%);
}

/* Scroll Hint Overlay */
#scroll-hint {
    position: absolute;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    pointer-events: none;
    /* Click through */
    z-index: 15;
    /* Above image, below add-btn (20) and modals */
    display: none;
    /* Hidden by default */
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, 10px);
    }

    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

/* Spinner */
.spinner {
    width: 48px;
    height: 48px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--color-primary);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal-card {
    background: var(--color-white);
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    max-width: 90%;
}

/* Node Labels */
.node-label {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    margin-bottom: 8px;
    pointer-events: none;
    display: none;
    z-index: 50;
    backdrop-filter: blur(2px);
}

.show-labels .node-label {
    display: block;
    animation: fadeIn 0.2s ease;
}

/* Position below if near top */
.node.label-below .node-label {
    bottom: auto;
    top: 100%;
    margin-bottom: 0;
    margin-top: 8px;
}

/* Notifications */
#notifications-panel {
    position: fixed;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    width: 320px;
    background: color-mix(in srgb, var(--color-bg), transparent 5%);
    backdrop-filter: blur(20px);
    border-left: 1px solid var(--color-gray-border);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

#notifications-panel.open {
    transform: translateX(0);
}

#notifications-list {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.notification-item {
    padding: 16px;
    border-bottom: 1px solid var(--color-gray-border);
    background: rgba(255, 255, 255, 0.5);
    transition: background 0.2s;
}

.notification-item:hover {
    background: white;
}

.notification-item.unread {
    background: white;
    border-left: 3px solid var(--color-primary);
}

.notif-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 11px;
    color: #666;
}

.notif-title {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
    color: var(--color-primary-dark);
}

.notif-message {
    font-size: 13px;
    color: #333;
    line-height: 1.4;
}

.badge-count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--color-alert);
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    pointer-events: none;
    animation: bounceIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes bounceIn {
    from {
        transform: scale(0);
    }

    to {
        transform: scale(1);
    }
}

/* Generic Data Modal Table Styles */
.data-row {
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background-color 0.2s;
}

.data-row:hover {
    background-color: #f5f5f5;
}

.data-row.selected {
    background-color: rgba(46, 90, 167, 0.25) !important;
    font-weight: bold;
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}