/* Import modern high-tech fonts from Google */
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Outfit:wght@300;400;600;700&display=swap');

:root {
    --bg-main: #080b12;
    --bg-panel: rgba(15, 20, 32, 0.88);
    --bg-header: rgba(12, 16, 26, 0.95);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-cyan: #ef4444; /* Red corporate theme matching OOO - SKM logo */
    --accent-green: #10b981;
    --accent-orange: #f97316;
    --accent-red: #ef4444;
    --accent-blue: #3b82f6;
    --canvas-grid: rgba(255, 255, 255, 0.02);
    --canvas-grid-bold: rgba(255, 255, 255, 0.04);
    --header-h: 56px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --touch-min: 44px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
    height: -webkit-fill-available;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: 'Outfit', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    height: 100vh;
    height: 100dvh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-top: var(--safe-top);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    /* bottom safe area handled by docks/panels */
    touch-action: manipulation;
}

/* Allow text selection in inputs / editable fields */
input, textarea, select, [contenteditable="true"] {
    user-select: text;
    -webkit-user-select: text;
    touch-action: manipulation;
    font-size: 16px; /* prevent iOS Safari auto-zoom on focus */
}

/* --- Login (all platforms) --- */
.login-screen {
    position: fixed;
    inset: 0;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg-main);
    z-index: 10000;
    display: none;
    opacity: 0;
    align-items: center;
    justify-content: center;
    padding: max(16px, var(--safe-top)) max(16px, var(--safe-right)) max(16px, var(--safe-bottom)) max(16px, var(--safe-left));
    transition: opacity 0.5s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.login-card {
    background: rgba(30, 41, 59, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: clamp(24px, 5vw, 40px);
    width: min(400px, 100%);
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: auto;
}

.login-logo {
    height: 64px;
    width: 64px;
    border-radius: 50%;
    border: 2px solid var(--accent-cyan);
    margin-bottom: 16px;
    object-fit: cover;
}

.login-title {
    color: var(--text-primary);
    margin: 0 0 6px 0;
    font-family: 'Orbitron', system-ui, sans-serif;
    font-size: clamp(1.1rem, 4vw, 1.35rem);
    text-align: center;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 12px;
    margin: 0 0 20px 0;
    text-align: center;
}

.login-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-field label {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    display: block;
}

.login-field input {
    width: 100%;
    box-sizing: border-box;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 6px;
    padding: 12px 10px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    min-height: var(--touch-min);
}

.login-field input:focus {
    border-color: var(--accent-cyan);
}

.login-error {
    color: #ef4444;
    font-size: 12px;
    text-align: center;
    display: none;
}

.login-submit {
    width: 100%;
    background: var(--accent-cyan);
    color: #000;
    border: none;
    border-radius: 6px;
    padding: 14px;
    font-weight: bold;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    margin-top: 4px;
    min-height: var(--touch-min);
}

.login-submit:hover {
    filter: brightness(1.08);
}

.login-submit:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* --- App Layout --- */
header {
    background: linear-gradient(180deg, rgba(12, 16, 26, 0.98) 0%, rgba(10, 13, 22, 0.9) 100%);
    border-bottom: 1px solid rgba(239, 68, 68, 0.25);
    padding: 8px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    z-index: 10;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255,255,255,0.05);
    min-height: var(--header-h);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.brand-section:hover {
    transform: scale(1.05);
}

.brand-badge {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-cyan);
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 30px;
    border: 1px solid rgba(239, 68, 68, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 0 0 5px rgba(239, 68, 68, 0.5);
}

.controls-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Mode Switcher Slider */
.mode-toggle {
    display: flex;
    background: #111827;
    border: 1px solid var(--border-color);
    border-radius: 30px;
    padding: 2px;
    position: relative;
    cursor: pointer;
}

.mode-btn {
    padding: 6px 18px;
    font-size: 12px;
    font-weight: 700;
    border-radius: 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 6px;
    letter-spacing: 0.5px;
}

.mode-btn.active {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.25), rgba(239, 68, 68, 0.08));
    border: 1px solid rgba(239, 68, 68, 0.5);
    color: #ef4444;
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.25);
}

.mode-btn.active.play-active {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.25), rgba(16, 185, 129, 0.08));
    border: 1px solid rgba(16, 185, 129, 0.5);
    color: var(--accent-green);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.25);
}

/* Action Buttons */
.btn {
    background: #1e293b;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.btn-icon {
    padding: 8px !important;
    width: 34px;
    height: 34px;
    justify-content: center;
    align-items: center;
}

.btn:hover {
    background: #334155;
    border-color: var(--text-secondary);
}

.btn:disabled, .btn-icon:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
    box-shadow: none;
}

.btn-primary {
    background: var(--accent-cyan);
    color: #020617;
    border: none;
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.3);
}

.btn-primary:hover {
    background: #38bdf8;
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.5);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
    border-color: #ef4444;
}

/* Layout Workspace */
.workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* Left components toolbar */
.toolbox {
    width: 240px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 5;
    backdrop-filter: blur(10px);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease, border-right-color 0.3s ease;
    opacity: 1;
    overflow: hidden;
}

body.play-mode-active .toolbox {
    width: 0;
    opacity: 0;
    border-right-color: transparent;
    pointer-events: none;
}

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

.panel-header h3 {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-primary);
}

.panel-header span {
    font-size: 11px;
    color: var(--text-muted);
}

.toolbox-items {
    padding: 16px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    overflow-y: auto;
}

.toolbox-section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--accent-cyan);
    opacity: 0.85;
    padding: 10px 4px 0;
    border-top: 1px dashed var(--border-color);
    margin-top: 4px;
}

.toolbox-card {
    background: rgba(30, 41, 59, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    cursor: grab;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s ease;
}

.toolbox-card:hover {
    background: rgba(30, 41, 59, 0.7);
    border-color: var(--accent-cyan);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.1);
    transform: translateY(-2px);
}

.toolbox-card:active {
    cursor: grabbing;
}

.toolbox-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    background: rgba(15, 23, 42, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    color: var(--accent-cyan);
}

.toolbox-card-details h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

.toolbox-card-details p {
    font-size: 10px;
    color: var(--text-muted);
}

/* Center canvas area */
.canvas-container {
    flex: 1;
    overflow: auto;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #07090e;
    /* Grid Pattern */
    background-image: 
        radial-gradient(var(--canvas-grid-bold) 1px, transparent 1px),
        linear-gradient(to right, var(--canvas-grid) 1px, transparent 1px),
        linear-gradient(to bottom, var(--canvas-grid) 1px, transparent 1px);
    background-size: 40px 40px, 40px 40px, 40px 40px;
    cursor: grab;
}

.canvas-container:active {
    cursor: grabbing;
}

#scada-canvas {
    width: 1400px;
    height: 800px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
    background-color: rgba(10, 13, 20, 0.4);
    border: 1px solid var(--border-color);
    overflow: visible;
    position: relative;
}

/* SVG interactive classes */
.hvac-element {
    cursor: move;
    transition: filter 0.2s ease;
}

.hvac-element:hover {
    filter: drop-shadow(0 0 4px rgba(0, 240, 255, 0.3));
}

.hvac-element.selected {
    filter: drop-shadow(0 0 8px rgba(0, 240, 255, 0.6));
}

/* Run mode elements */
.hvac-element.play-mode {
    cursor: pointer;
}

/* Right properties inspector panel */
.inspector {
    width: 320px;
    background-color: var(--bg-panel);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 5;
    backdrop-filter: blur(10px);
}

.inspector-content {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.inspector-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 40px;
    line-height: 1.5;
}

.inspector-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
}

.inspector-section h4 {
    font-size: 11px;
    color: var(--accent-cyan);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
}

/* Property Input Elements */
.prop-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.prop-label {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 80px;
}

.prop-input {
    background: #0b0f19;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'Orbitron', monospace;
    width: 100%;
    outline: none;
    transition: border-color 0.2s ease;
}

.prop-input:focus {
    border-color: var(--accent-cyan);
}

.prop-input-half {
    width: calc(50% - 6px);
}

/* Preset color picker chips */
.color-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.color-chip {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.color-chip:hover {
    transform: scale(1.15);
}

.color-chip.active {
    border-color: var(--text-primary);
    transform: scale(1.1);
}

/* Slider values styling */
.slider-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
}

.slider-val {
    font-family: 'Orbitron', monospace;
    color: var(--accent-cyan);
    font-weight: bold;
}

.prop-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #1e293b;
    outline: none;
    cursor: pointer;
}

.prop-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-cyan);
    box-shadow: 0 0 6px var(--accent-cyan);
}

/* Status selection pills */
.status-pill-group {
    display: flex;
    gap: 8px;
    width: 100%;
}

.status-pill {
    flex: 1;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    padding: 6px 4px;
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

.status-pill.active[data-val="ACTIVE"] {
    background: rgba(0, 230, 118, 0.15);
    border-color: var(--accent-green);
    color: var(--accent-green);
}

.status-pill.active[data-val="INACTIVE"] {
    background: rgba(148, 163, 184, 0.15);
    border-color: var(--text-secondary);
    color: var(--text-secondary);
}

.status-pill.active[data-val="ALARM"] {
    background: rgba(255, 23, 68, 0.15);
    border-color: var(--accent-red);
    color: var(--accent-red);
}

/* --- SVG Transformer Selection Box Overlays --- */
.transform-outline {
    fill: none;
    stroke: var(--accent-cyan);
    stroke-width: 1.5;
    stroke-dasharray: 4 3;
    pointer-events: none;
}

.transform-handle {
    fill: #0a0d14;
    stroke: var(--accent-cyan);
    stroke-width: 2;
    cursor: pointer;
    transition: fill 0.15s ease, transform 0.15s ease;
}

.transform-handle:hover {
    fill: var(--accent-cyan);
    transform: scale(1.2);
}

.transform-handle-rotate {
    fill: var(--accent-cyan);
    stroke: #0a0d14;
}

.transform-line {
    stroke: var(--accent-cyan);
    stroke-width: 1.5;
    stroke-dasharray: 2 2;
    pointer-events: none;
}

/* --- Animations --- */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.spin-animation {
    transform-origin: 0px 0px;
    animation: spin 2.5s linear infinite;
}

/* Water pump rotation oscillation */
@keyframes pump-pulse {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 2px var(--accent-green)); }
    50% { transform: scale(1.08); filter: drop-shadow(0 0 8px var(--accent-green)); }
}
.spinning-pump {
    transform-origin: center;
    animation: pump-pulse 1.5s ease-in-out infinite;
}

/* Seamless Flow Arrow movement */
@keyframes flow-right-seamless {
    from {
        transform: translateX(0px);
    }
    to {
        transform: translateX(45px); /* Equal to arrow spacing S */
    }
}

.seamless-flow-arrows {
    animation: flow-right-seamless 1.2s linear infinite;
}

/* Filter scan flow animation */
@keyframes filter-flow {
    from {
        stroke-dashoffset: 28;
    }
    to {
        stroke-dashoffset: 0;
    }
}

.filter-flow-animation {
    animation: filter-flow 1.5s linear infinite;
}

/* Snowflake slow rotation */
@keyframes rotate-snowflake {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.rotate-snowflake {
    transform-origin: 0px 0px;
    animation: rotate-snowflake 12s linear infinite;
}

/* Heat tube waves anim */
@keyframes wave-glow {
    0%, 100% { stroke-dashoffset: 0; opacity: 0.4; }
    50% { stroke-dashoffset: -10; opacity: 0.9; }
}

.flow-wave-animation {
    animation: wave-glow 2s linear infinite;
}

/* Air breeze flow in room card */
@keyframes room-breeze {
    from {
        stroke-dashoffset: 24;
    }
    to {
        stroke-dashoffset: 0;
    }
}

.room-breeze-line {
    animation: room-breeze 2s linear infinite;
}

/* Zoom controls HUD overlay */
.zoom-hud {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 8;
    backdrop-filter: blur(10px);
}

.zoom-btn {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.zoom-btn:hover {
    background: #334155;
    color: var(--accent-cyan);
}

.zoom-text {
    font-size: 11px;
    font-family: 'Orbitron', monospace;
    font-weight: bold;
    color: var(--text-secondary);
    padding: 0 4px;
}

/* Custom Scrollbar for side panels */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Red alarm flashing effect for SCADA control panel */
.alarm-banner-scada {
    animation: blink-red-border 1.5s infinite;
}

@keyframes blink-red-border {
    0%, 100% {
        border-color: rgba(239, 68, 68, 0.4);
        box-shadow: 0 0 4px rgba(239, 68, 68, 0.2);
        background-color: rgba(239, 68, 68, 0.08);
    }
    50% {
        border-color: rgba(239, 68, 68, 1);
        box-shadow: 0 0 12px rgba(239, 68, 68, 0.6);
        background-color: rgba(239, 68, 68, 0.22);
    }
}

/* --- Bottom dock: PLC vars bump + alarms console --- */
.bottom-dock {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    pointer-events: none;
}

.bottom-dock > * {
    pointer-events: auto;
}

/* PLC variables — ridge/bump sitting on top of alarms panel */
.plc-vars-dock {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    z-index: 10;
}

.plc-vars-bump {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 200px;
    max-width: min(420px, 92%);
    margin: 0 auto;
    padding: 7px 16px 8px;
    border: 1px solid rgba(0, 240, 255, 0.28);
    border-bottom: none;
    border-radius: 14px 14px 0 0;
    background: linear-gradient(180deg, rgba(18, 28, 48, 0.98) 0%, rgba(11, 15, 26, 0.98) 100%);
    color: var(--accent-cyan);
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.35), 0 0 12px rgba(0, 240, 255, 0.08);
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.4px;
    transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}

.plc-vars-bump:hover {
    background: linear-gradient(180deg, rgba(22, 36, 58, 1) 0%, rgba(14, 20, 34, 1) 100%);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4), 0 0 16px rgba(0, 240, 255, 0.14);
}

.plc-vars-bump:active {
    transform: translateY(1px);
}

.plc-vars-bump-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.plc-vars-scheme {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 10px;
    opacity: 0.9;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.plc-vars-bump-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    line-height: 0;
    transition: transform 0.2s ease;
}

.plc-vars-dock:not(.collapsed) .plc-vars-bump-chevron {
    transform: rotate(180deg);
    color: var(--accent-cyan);
}

.plc-vars-sheet {
    width: 100%;
    max-height: 0;
    overflow: hidden;
    background: rgba(11, 15, 26, 0.97);
    border-top: 1px solid rgba(0, 240, 255, 0.15);
    backdrop-filter: blur(12px);
    transition: max-height 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.plc-vars-dock:not(.collapsed) .plc-vars-sheet {
    max-height: 220px;
}

.plc-vars-list {
    max-height: 150px;
    overflow-y: auto;
    padding: 8px 14px;
}

.plc-vars-sheet-footer {
    padding: 6px 14px 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* --- Expandable Alarms Center Console --- */
.alarms-console {
    position: relative;
    bottom: auto;
    left: auto;
    right: auto;
    width: 100%;
    background: rgba(11, 15, 26, 0.95);
    border-top: 1px solid var(--border-color);
    z-index: 9;
    backdrop-filter: blur(15px);
    transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.alarms-console.collapsed {
    height: 42px;
}

.alarms-console.expanded {
    height: 250px;
}

.alarms-console-header {
    height: 42px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    background: rgba(16, 22, 35, 0.5);
    border-bottom: 1px solid var(--border-color);
}

.alarms-console-header:hover {
    background: rgba(30, 41, 59, 0.4);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.green {
    background-color: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green);
}

.status-dot.red {
    background-color: var(--accent-red);
    box-shadow: 0 0 8px var(--accent-red);
    animation: pulse-red 1s infinite alternate;
}

@keyframes pulse-red {
    0% { transform: scale(0.9); opacity: 0.7; }
    100% { transform: scale(1.2); opacity: 1; }
}

.status-text {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.alarms-summary {
    font-size: 12px;
    color: var(--text-secondary);
}

.toggle-console-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
}

.alarms-console-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.alarms-tabs {
    display: flex;
    background: rgba(10, 13, 20, 0.6);
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    padding: 10px 20px;
    font-family: 'Outfit', sans-serif;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.02);
}

.tab-btn.active {
    color: var(--accent-cyan);
    border-bottom-color: var(--accent-cyan);
    background: rgba(0, 240, 255, 0.05);
}

.alarms-tab-content {
    display: none;
    flex: 1;
    padding: 12px 20px;
    overflow-y: auto;
}

.alarms-tab-content.active {
    display: block;
}

/* Tab active alarms list */
.alarms-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.alarm-item {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 6px;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    animation: slide-in 0.2s ease-out;
}

@keyframes slide-in {
    from { transform: translateY(5px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.alarm-item-title {
    font-size: 12px;
    font-weight: 700;
    color: #ef4444;
    display: flex;
    align-items: center;
    gap: 6px;
}

.alarm-item-hint {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.4;
    background: rgba(0, 0, 0, 0.2);
    padding: 6px 10px;
    border-radius: 4px;
    border-left: 2px solid var(--accent-orange);
}

.no-alarms-placeholder {
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
    padding: 20px 0;
}

/* Event log design */
.event-log-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-family: 'Orbitron', monospace;
    font-size: 11px;
}

.event-log-entry {
    display: flex;
    gap: 12px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.event-log-time {
    color: var(--accent-cyan);
    min-width: 80px;
}

.event-log-text {
    color: var(--text-secondary);
}

.event-log-entry.alarm-event .event-log-text {
    color: var(--accent-red);
}

.event-log-entry.reset-event .event-log-text {
    color: var(--accent-green);
}

/* Diagnostics guide layout */
.guide-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
}

.guide-item {
    background: rgba(30, 41, 59, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
}

.guide-item h4 {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-cyan);
    margin-bottom: 6px;
}

.guide-item p {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    line-height: 1.4;
}

/* View layouts */
#dashboard-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 30px;
    overflow-y: auto;
    background: #020617;
}

#workspace-view {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.view-hidden {
    display: none !important;
}

/* Dashboard Header & Stats */
.db-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
}

.db-title h1 {
    font-size: 22px;
    font-family: 'Orbitron', sans-serif;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
    text-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
}

.db-title p {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Stats Row */
.db-stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.db-stat-card {
    background: rgba(16, 22, 35, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.db-stat-card:hover {
    border-color: rgba(0, 240, 255, 0.3);
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.05);
}

.db-stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: rgba(0, 240, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-cyan);
}

.db-stat-icon.red {
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-red);
}

.db-stat-icon.green {
    background: rgba(34, 197, 94, 0.1);
    color: var(--accent-green);
}

.db-stat-info {
    display: flex;
    flex-direction: column;
}

.db-stat-val {
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    font-family: 'Orbitron', monospace;
}

.db-stat-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Search / Filter Bar */
.db-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.db-search-wrapper {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.db-search-input {
    width: 100%;
    padding: 10px 16px;
    background: rgba(16, 22, 35, 0.8);
    border: 1px solid var(--border-color);
    color: #fff;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s ease;
}

.db-search-input:focus {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.15);
}

.db-filter-select {
    padding: 10px 16px;
    background: rgba(16, 22, 35, 0.8);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    outline: none;
}

/* Card Grid */
.db-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    padding-bottom: 40px;
}

.schema-card {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
}

.schema-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent-cyan);
    box-shadow: 0 4px 20px rgba(0, 240, 255, 0.1);
    background: rgba(15, 23, 42, 0.7);
}

.schema-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 12px;
}

.schema-card-title-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.schema-card-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    font-family: 'Outfit', sans-serif;
}

.schema-card-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
}

.schema-card-status .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.schema-card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.schema-card-desc {
    font-size: 12.5px;
    color: var(--text-secondary);
    line-height: 1.5;
    min-height: 38px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.schema-card-plc-details {
    background: rgba(10, 15, 26, 0.5);
    padding: 10px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.03);
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 11px;
}

.plc-detail-row {
    display: flex;
    justify-content: space-between;
    color: var(--text-muted);
}

.plc-detail-row strong {
    color: var(--text-primary);
}

.schema-card-alarms {
    color: var(--accent-red);
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
}

.schema-card-footer {
    display: flex;
    gap: 8px;
    margin-top: auto;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(2, 6, 23, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    padding: max(8px, env(safe-area-inset-top, 0px)) max(8px, env(safe-area-inset-right, 0px)) max(8px, env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid var(--accent-cyan);
    box-shadow: 0 0 30px rgba(0, 240, 255, 0.25);
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    transform: scale(0.9);
    transition: transform 0.25s ease;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 12px;
}

.modal-header h3 {
    font-size: 14px;
    font-family: 'Orbitron', sans-serif;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    transition: color 0.15s ease;
}

.modal-close-btn:hover {
    color: #fff;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 16px;
}

.modal-body .prop-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.modal-body .prop-label {
    min-width: auto;
}

/* === Three-Dots Dropdown Menu === */
.dropdown-wrapper {
    position: relative;
}

.btn-more-actions {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 18px;
    letter-spacing: 2px;
    line-height: 1;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-more-actions:hover {
    background: rgba(0, 240, 255, 0.12);
    border-color: var(--accent-cyan);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
}

.dropdown-menu-content {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 240px;
    background: rgba(15, 20, 35, 0.97);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 20px rgba(0, 240, 255, 0.08);
    backdrop-filter: blur(16px);
    z-index: 9999;
    overflow: hidden;
    animation: dropdownSlideIn 0.15s ease-out;
}

@keyframes dropdownSlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.dropdown-menu-content.show {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.dropdown-item:hover {
    background: rgba(0, 240, 255, 0.08);
    color: var(--text-primary);
}

.dropdown-item .dropdown-icon {
    font-size: 16px;
    min-width: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: color 0.15s ease;
}

.dropdown-item:hover .dropdown-icon {
    color: var(--accent-cyan);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* === Console Control Buttons (ВКЛ / ВЫКЛ in Alarms Header) === */
.console-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    margin-right: 10px;
}

.console-ctrl-btn {
    padding: 5px 14px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    letter-spacing: 0.5px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.console-ctrl-btn.start-btn {
    background: rgba(0, 200, 100, 0.15);
    color: #00e676;
    border-color: rgba(0, 200, 100, 0.3);
}
.console-ctrl-btn.start-btn:hover {
    background: rgba(0, 200, 100, 0.3);
    box-shadow: 0 0 12px rgba(0, 200, 100, 0.25);
}
.console-ctrl-btn.start-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.console-ctrl-btn.stop-btn {
    background: rgba(255, 60, 60, 0.15);
    color: #ff5252;
    border-color: rgba(255, 60, 60, 0.3);
}
.console-ctrl-btn.stop-btn:hover {
    background: rgba(255, 60, 60, 0.3);
    box-shadow: 0 0 12px rgba(255, 60, 60, 0.25);
}
.console-ctrl-btn.stop-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* === Monitoring mode: hide sidebars === */
.workspace-view-monitoring .toolbox {
    display: none !important;
}
.workspace-view-monitoring .inspector {
    display: none !important;
}
.workspace-view-monitoring.show-inspector .inspector {
    display: flex !important;
}
.workspace-view-monitoring .canvas-container {
    flex: 1;
}

/* === Devices catalog list === */
.devices-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.device-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.55);
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.device-card:hover, .device-card.active {
    border-color: rgba(0, 240, 255, 0.4);
    box-shadow: 0 0 14px rgba(0, 240, 255, 0.08);
}
.device-card-title {
    font-weight: 700;
    color: #fff;
    font-size: 13px;
}
.device-card-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 3px;
}
.device-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.4px;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid rgba(0, 240, 255, 0.3);
    color: var(--accent-cyan);
    background: rgba(0, 240, 255, 0.08);
    white-space: nowrap;
}
.device-edit-panel {
    padding: 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: rgba(2, 6, 23, 0.4);
}

/* === PLC config: per-scheme variable picker === */
.plc-vars-picker {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px dashed var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.plc-vars-picker-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.plc-vars-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.plc-vars-hint {
    margin: 0;
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
}

.plc-vars-checklist {
    max-height: 220px;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(2, 6, 23, 0.45);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.plc-vars-group-title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--accent-cyan);
    margin: 8px 0 4px;
    opacity: 0.9;
}

.plc-var-check {
    display: grid;
    grid-template-columns: 18px 1fr;
    grid-template-rows: auto auto;
    column-gap: 8px;
    row-gap: 1px;
    align-items: start;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
}

.plc-var-check:hover {
    background: rgba(0, 240, 255, 0.06);
}

.plc-var-check input {
    grid-row: 1 / span 2;
    margin-top: 2px;
    accent-color: var(--accent-cyan);
}

.plc-var-check-name {
    color: var(--text-primary);
    font-family: ui-monospace, monospace;
    font-size: 11px;
    word-break: break-all;
}

.plc-var-check-label {
    color: var(--text-muted);
    font-size: 10px;
}

/* === Schema side drawer === */
.schema-drawer {
    position: fixed;
    top: 0;
    left: -320px;
    width: 300px;
    height: 100vh;
    background: rgba(12, 18, 32, 0.97);
    backdrop-filter: blur(12px);
    border-right: 1px solid rgba(0, 240, 255, 0.2);
    z-index: 11000;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.55);
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.schema-drawer-header {
    padding: 14px 14px 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    background: rgba(0, 240, 255, 0.06);
}

.schema-drawer-title {
    margin: 0;
    color: var(--accent-cyan);
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    letter-spacing: 1px;
}

.schema-drawer-close {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    margin: 0;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(15, 23, 42, 0.95);
    color: #e2e8f0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 0;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.schema-drawer-close:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.5);
    color: #fca5a5;
}

.schema-drawer-close:active {
    transform: scale(0.96);
}

.schema-drawer-list {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.schema-drawer-item {
    padding: 12px;
    background: rgba(30, 41, 59, 0.55);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.schema-drawer-item:hover {
    border-color: rgba(0, 240, 255, 0.35);
    box-shadow: 0 0 12px rgba(0, 240, 255, 0.08);
}

.schema-drawer-item.active {
    background: rgba(0, 240, 255, 0.1);
    border-color: var(--accent-cyan);
}

.schema-drawer-item-title {
    font-weight: 600;
    color: #fff;
    font-size: 13px;
}

.schema-drawer-item.active .schema-drawer-item-title {
    color: var(--accent-cyan);
}

.schema-drawer-item-desc {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.35;
}

.schema-drawer-item-mode {
    margin-top: 6px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--accent-cyan);
    opacity: 0.85;
}

.schema-drawer-footer {
    padding: 14px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Variable rows inside dock sheet */
.var-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 11px;
}

.var-name {
    color: var(--text-secondary);
    word-break: break-all;
}

.var-val {
    font-family: ui-monospace, monospace;
    white-space: nowrap;
}

.var-empty {
    color: var(--text-muted);
    font-size: 11px;
    text-align: center;
    padding: 12px 0;
}

/* === OwenCloud help hint === */
.owen-api-hint {
    background: rgba(0, 240, 255, 0.06);
    border: 1px solid rgba(0, 240, 255, 0.15);
    border-radius: 8px;
    padding: 12px 14px;
    margin-top: 4px;
    font-size: 11.5px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.owen-api-hint strong {
    color: var(--accent-cyan);
}

.owen-api-hint ol {
    margin: 6px 0 0 16px;
    padding: 0;
}

.owen-api-hint ol li {
    margin-bottom: 4px;
}

/* === Keyboard Shortcuts Modal Styling === */
.shortcuts-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.shortcut-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(30, 41, 59, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

.shortcut-keys {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

kbd {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--border-color);
    border-bottom: 2px solid var(--accent-cyan);
    border-radius: 5px;
    color: var(--accent-cyan);
    font-family: 'Outfit', monospace;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.shortcut-desc {
    color: var(--text-primary);
    font-size: 12.5px;
    font-weight: 500;
}

/* === Weekly Schedule Overlay === */
.schedule-overlay {
    position: absolute;
    top: 20px;
    left: 20px; /* Moved left */
    z-index: 5000;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    min-width: 320px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
}

.schedule-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: rgba(30, 41, 59, 0.6);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    user-select: none;
    border-bottom: 1px solid transparent;
}
.schedule-header:hover {
    background: rgba(30, 41, 59, 0.9);
}
.schedule-overlay.expanded .schedule-header {
    border-bottom-color: var(--border-color);
}
.schedule-overlay.expanded .chevron-icon {
    transform: rotate(180deg);
}

.schedule-header-actions {
    display: none;
    align-items: center;
    gap: 8px;
}
.schedule-overlay.expanded .schedule-header-actions {
    display: flex;
}

.btn-schedule-edit {
    background: rgba(0, 240, 255, 0.1);
    border: 1px solid rgba(0, 240, 255, 0.3);
    color: var(--accent-cyan);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-schedule-edit:hover {
    background: rgba(0, 240, 255, 0.2);
}

.schedule-body {
    display: none;
    padding: 16px;
    flex-direction: column;
    gap: 16px;
}
.schedule-overlay.expanded .schedule-body {
    display: flex;
}

.schedule-control-row {
    padding-bottom: 12px;
    border-bottom: 1px dashed var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.schedule-days-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.schedule-day-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    opacity: 0.5; /* Default disabled opacity */
    transition: opacity 0.2s;
}
.schedule-day-row.day-enabled {
    opacity: 1.0;
}

.schedule-day-name {
    font-size: 12px;
    color: var(--text-secondary);
    width: 30px;
    font-weight: 600;
}
.schedule-day-name.active-today {
    color: var(--accent-cyan);
}
.schedule-time-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}
.schedule-time-inputs input[type="time"] {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 4px;
    padding: 4px 6px;
    font-family: 'Orbitron', monospace;
    font-size: 12px;
    outline: none;
}
.schedule-time-inputs input[type="time"][readonly] {
    border-color: transparent;
    pointer-events: none;
}
.schedule-time-inputs input[type="time"]:focus {
    border-color: var(--accent-cyan);
}

.schedule-day-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-secondary);
}

.btn-schedule-save {
    background: var(--accent-cyan);
    color: #000;
    border: none;
    border-radius: 4px;
    padding: 6px 0;
    font-weight: bold;
    font-size: 12px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    width: 100%;
}
.btn-schedule-save:hover {
    background: #00e0ff;
}
.btn-schedule-save:active {
    transform: scale(0.98);
}

/* === Auth & Admin Users === */
.user-card {
    display: flex;
    flex-direction: column;
    padding: 0;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    transition: border-color 0.2s;
    overflow: hidden;
}
.user-card:hover {
    border-color: rgba(255, 255, 255, 0.2);
}
.user-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
}
.user-card-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}
.user-expand-icon {
    color: var(--text-secondary);
    transition: transform 0.2s;
    display: flex;
    align-items: center;
}
.user-card.expanded .user-expand-icon {
    transform: rotate(180deg);
}
.user-card-body {
    display: none;
    padding: 10px 12px;
    padding-top: 0;
    justify-content: space-between;
    align-items: flex-end;
}
.user-card.expanded .user-card-body {
    display: flex;
}
.user-info-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.user-name-display {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}
.user-login-display {
    font-size: 12px;
    color: var(--text-secondary);
}
.user-role-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}
.user-role-badge.admin {
    background: rgba(239, 68, 68, 0.2);
    color: var(--accent-red);
}
.user-role-badge.operator {
    background: rgba(14, 165, 233, 0.2);
    color: var(--accent-cyan);
}
.user-actions {
    display: flex;
    gap: 6px;
}
.operator-mode-hide {
    display: none !important;
}

/* === Operator Mode Restrictions === */
body.operator-mode .schema-card-plc-details {
    display: none !important;
}
body.operator-mode .schema-card-footer button:nth-child(2) {
    display: none !important;
}
body.operator-mode #btn-create-schema,
body.operator-mode #btn-delete-schema,
body.operator-mode #btn-admin-users,
body.operator-mode #btn-admin-devices {
    display: none !important;
}
body.operator-mode .stat-badge-plc {
    display: none !important;
}

/* Public demo banner */
.demo-public-banner {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9000;
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
    background: linear-gradient(90deg, rgba(120, 53, 15, 0.95), rgba(69, 26, 3, 0.95));
    border-top: 1px solid rgba(249, 115, 22, 0.45);
    color: #ffedd5;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    line-height: 1.35;
    pointer-events: none;
}
body.has-demo-banner .bottom-dock {
    bottom: 34px;
}
@media (max-width: 640px) {
    .demo-public-banner {
        font-size: 10px;
        padding: 6px 8px;
        padding-bottom: max(6px, env(safe-area-inset-bottom, 0px));
    }
}

/* ============================================================
   CROSS-PLATFORM RESPONSIVE LAYOUT
   Phone · Tablet · Desktop · iOS · iPadOS · Android · Windows · macOS · Linux
   ============================================================ */

/* Users modal two-column (desktop default) */
.users-modal-layout {
    display: flex;
    gap: 16px;
}
.users-modal-list {
    flex: 1;
    min-width: 0;
}
.users-modal-form {
    width: 260px;
    flex-shrink: 0;
}

/* Mobile panel chrome (hidden on desktop) */
.mobile-panel-backdrop {
    display: none;
}
.mobile-fab-bar {
    display: none;
}
.panel-close-mobile {
    display: none;
}
.inspector-mobile-header {
    display: none;
}

.btn-header-action {
    padding: 6px 12px;
    gap: 6px;
}

/* Prefer GPU-friendly scrolling on WebKit (iOS/Safari) */
.toolbox-items,
.inspector-content,
#dashboard-view,
.schema-drawer-list,
.modal-body,
.plc-vars-checklist,
.alarms-console-body {
    -webkit-overflow-scrolling: touch;
}

/* Larger hit targets for coarse pointers (touch) */
@media (pointer: coarse) {
    .btn,
    .mode-btn,
    .zoom-btn,
    .toolbox-card,
    .schema-card-footer .btn,
    .dropdown-item {
        min-height: 40px;
    }
    .btn-icon {
        min-width: 40px;
        min-height: 40px;
    }
    .plc-var-check {
        min-height: 40px;
        padding-top: 8px;
        padding-bottom: 8px;
    }
}

/* ---------- Large tablet / small laptop ---------- */
@media (max-width: 1200px) {
    .toolbox {
        width: 200px;
    }
    .inspector {
        width: 280px;
    }
    #dashboard-view {
        padding: 20px;
    }
    .db-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 16px;
    }
}

/* ---------- Tablet portrait & landscape phones in landscape ---------- */
@media (max-width: 960px) {
    header {
        padding: 6px 10px;
        gap: 6px;
    }

    .controls-section {
        gap: 6px;
        flex-wrap: wrap;
        justify-content: flex-end;
        flex: 1;
        min-width: 0;
    }

    .mode-btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    .btn-header-action {
        padding: 6px 8px;
    }

    /* Workspace: side panels become drawers */
    #workspace-view {
        position: relative;
    }

    .toolbox,
    .inspector {
        position: fixed;
        top: calc(var(--header-h) + var(--safe-top));
        bottom: var(--safe-bottom);
        width: min(320px, 88vw);
        max-width: 100%;
        z-index: 80;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.55);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.28s;
        visibility: hidden;
    }

    .toolbox {
        left: 0;
        right: auto;
        transform: translateX(-105%);
        border-right: 1px solid var(--border-color);
        border-left: none;
    }

    .inspector {
        right: 0;
        left: auto;
        transform: translateX(105%);
        border-left: 1px solid var(--border-color);
        border-right: none;
        width: min(360px, 92vw);
    }

    /* In play mode toolbox already width 0 — keep drawer logic for editor */
    body.play-mode-active .toolbox {
        width: min(320px, 88vw);
        opacity: 1;
        pointer-events: auto;
        border-right-color: var(--border-color);
        /* still closed unless opened */
        transform: translateX(-105%);
        visibility: hidden;
    }

    body.mobile-toolbox-open .toolbox,
    body.mobile-toolbox-open.play-mode-active .toolbox {
        transform: translateX(0);
        visibility: visible;
        pointer-events: auto;
        opacity: 1;
    }

    body.mobile-inspector-open .inspector,
    body.workspace-view-monitoring.show-inspector .inspector,
    body.mobile-inspector-open .inspector {
        transform: translateX(0);
        visibility: visible;
        display: flex !important;
    }

    /* Monitoring mode: inspector was display:none — allow drawer */
    .workspace-view-monitoring .inspector {
        display: flex !important;
        transform: translateX(105%);
        visibility: hidden;
    }
    body.mobile-inspector-open .workspace-view-monitoring .inspector,
    .workspace-view-monitoring.show-inspector .inspector {
        transform: translateX(0);
        visibility: visible;
    }

    .mobile-panel-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        top: calc(var(--header-h) + var(--safe-top));
        background: rgba(0, 0, 0, 0.45);
        z-index: 70;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }

    body.mobile-toolbox-open .mobile-panel-backdrop,
    body.mobile-inspector-open .mobile-panel-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-fab-bar {
        display: flex;
        position: absolute;
        top: 10px;
        left: 10px;
        z-index: 15;
        gap: 8px;
        flex-wrap: wrap;
        max-width: calc(100% - 20px);
        pointer-events: none;
    }

    .mobile-fab {
        pointer-events: auto;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 8px 12px;
        min-height: 40px;
        border-radius: 999px;
        border: 1px solid rgba(239, 68, 68, 0.35);
        background: rgba(12, 16, 26, 0.92);
        color: #f8fafc;
        font-size: 12px;
        font-weight: 700;
        font-family: inherit;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
        cursor: pointer;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    .mobile-fab:active {
        transform: scale(0.97);
    }

    body.play-mode-active .mobile-fab-bar #btn-mobile-toolbox {
        display: none; /* no components in monitor mode */
    }

    .panel-close-mobile {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        min-width: 36px;
        border-radius: 8px;
        border: 1px solid var(--border-color);
        background: rgba(15, 23, 42, 0.9);
        color: #e2e8f0;
        font-size: 22px;
        line-height: 1;
        cursor: pointer;
        margin-left: auto;
    }

    .panel-header {
        gap: 8px;
    }

    .panel-header-hint {
        display: none;
    }

    .inspector-mobile-header {
        display: flex;
        flex-shrink: 0;
    }

    .canvas-container {
        width: 100%;
        min-width: 0;
    }

    #scada-canvas {
        /* keep design size; user pans/zooms */
        width: 1400px;
        height: 800px;
        max-width: none;
    }

    .zoom-hud {
        bottom: max(72px, calc(60px + var(--safe-bottom)));
        right: 10px;
        transform: scale(0.95);
        transform-origin: bottom right;
    }

    .bottom-dock {
        padding-bottom: var(--safe-bottom);
    }

    #dashboard-view {
        padding: 16px;
        padding-bottom: max(24px, var(--safe-bottom));
    }

    .db-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .db-header .btn-primary {
        width: 100%;
        justify-content: center;
    }

    .db-stats-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .db-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .db-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .schema-card:hover {
        transform: none; /* less motion jank on touch */
    }

    .schema-card-footer {
        flex-wrap: wrap;
    }

    .schema-card-footer .btn {
        flex: 1 1 auto;
        min-width: 0;
        justify-content: center;
    }

    .modal-content {
        width: min(640px, calc(100vw - 20px)) !important;
        max-width: calc(100vw - 20px) !important;
        max-height: calc(100dvh - 24px - var(--safe-top) - var(--safe-bottom));
        margin: 10px;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1;
        min-height: 0;
    }

    .users-modal-layout {
        flex-direction: column;
    }

    .users-modal-form {
        width: 100%;
    }

    .schema-drawer {
        width: min(300px, 86vw);
    }

    .schedule-overlay {
        max-width: calc(100vw - 16px);
        left: 8px !important;
        right: 8px;
    }

    /* Workspace toolbar: allow wrap */
    #workspace-actions-container {
        flex-wrap: wrap;
        max-width: 100%;
    }

    #edit-mode-toolbar {
        flex-wrap: wrap;
        max-width: 100%;
    }

    #schema-select {
        max-width: 120px !important;
    }
}

/* ---------- Phone (portrait) ---------- */
@media (max-width: 640px) {
    header {
        padding: 6px 8px;
        padding-left: max(8px, var(--safe-left));
        padding-right: max(8px, var(--safe-right));
    }

    .brand-section img {
        height: 36px !important;
        width: 36px !important;
    }

    /* Icon-only header actions to save space */
    .btn-header-action .btn-text,
    .mode-btn .btn-text {
        display: none;
    }

    .btn-header-action {
        padding: 8px;
        min-width: 40px;
        min-height: 40px;
        justify-content: center;
    }

    .mode-btn {
        padding: 8px 10px;
        min-width: 40px;
        justify-content: center;
    }

    .mode-toggle {
        flex-shrink: 0;
    }

    #btn-save-return .btn-text,
    #btn-save-return {
        font-size: 0;
    }
    #btn-save-return svg {
        /* keep icon visible — button has text node after svg */
    }
    #btn-save-return {
        font-size: 11px;
        padding: 6px 8px !important;
    }

    /* Hide long labels on create schema in toolbar */
    #btn-create-schema {
        font-size: 0;
        padding: 6px !important;
        min-width: 36px;
        justify-content: center;
    }
    #btn-create-schema svg {
        width: 14px;
        height: 14px;
    }

    .db-title h1 {
        font-size: 16px;
        letter-spacing: 0.5px;
    }

    .db-title p {
        font-size: 12px;
    }

    .db-stat-card {
        padding: 12px;
    }

    .plc-vars-bump {
        max-width: 96%;
        font-size: 11px;
        padding: 8px 12px;
    }

    .plc-vars-sheet {
        max-height: 40vh;
    }

    .alarms-console {
        max-height: 45vh;
    }

    .dropdown-menu-content {
        right: 0;
        left: auto;
        max-width: min(280px, calc(100vw - 16px));
    }

    .modal-footer {
        flex-wrap: wrap;
        gap: 8px;
    }

    .modal-footer .btn {
        flex: 1 1 auto;
        justify-content: center;
        min-height: 44px;
    }

    /* Login full-bleed comfort on small phones */
    .login-card {
        padding: 22px 18px;
    }

    .zoom-hud {
        bottom: max(88px, calc(76px + var(--safe-bottom)));
        scale: 0.9;
    }

    /* FABs sit above bottom dock */
    .mobile-fab-bar {
        top: auto;
        bottom: max(100px, calc(88px + var(--safe-bottom)));
        left: 10px;
    }

    #scada-canvas {
        /* slightly smaller base for easier framing on phone */
        width: 1200px;
        height: 720px;
    }
}

/* ---------- Very small phones ---------- */
@media (max-width: 380px) {
    .db-stats-row {
        gap: 8px;
    }
    .mobile-fab span {
        display: none;
    }
    .mobile-fab {
        padding: 10px;
        border-radius: 50%;
        min-width: 44px;
        min-height: 44px;
        justify-content: center;
    }
}

/* ---------- Landscape phone ---------- */
@media (max-height: 480px) and (orientation: landscape) {
    header {
        min-height: 44px;
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .login-card {
        padding: 16px;
        max-height: calc(100dvh - 16px);
        overflow-y: auto;
    }

    .login-logo {
        height: 40px;
        width: 40px;
        margin-bottom: 8px;
    }

    .toolbox,
    .inspector {
        top: calc(44px + var(--safe-top));
        width: min(280px, 70vw);
    }

    .mobile-fab-bar {
        top: 6px;
        bottom: auto;
    }

    .plc-vars-sheet {
        max-height: 35vh;
    }
}

/* ---------- Large desktop / ultra-wide ---------- */
@media (min-width: 1600px) {
    .db-grid {
        grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    }
    #dashboard-view {
        padding: 32px 40px;
    }
}

/* ---------- Prefers reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- Print (optional) ---------- */
@media print {
    header,
    .toolbox,
    .inspector,
    .bottom-dock,
    .mobile-fab-bar,
    .zoom-hud,
    .login-screen {
        display: none !important;
    }
    body {
        overflow: visible;
        height: auto;
        background: #fff;
        color: #000;
    }
    #scada-canvas {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}

/* High-contrast / forced-colors (Windows) */
@media (forced-colors: active) {
    .btn,
    .mode-btn,
    .toolbox-card,
    .schema-card,
    .modal-content {
        border: 1px solid ButtonText;
    }
}

/* Ensure modals respect safe areas on notched devices */
.modal-overlay {
    padding: max(8px, var(--safe-top)) max(8px, var(--safe-right)) max(8px, var(--safe-bottom)) max(8px, var(--safe-left));
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Fix canvas container for touch pan */
.canvas-container {
    touch-action: none; /* custom pan/zoom via JS */
    overscroll-behavior: contain;
}

/* Inputs stay 16px on mobile so iOS doesn't zoom; desktop can be 13px via media */
@media (min-width: 961px) {
    input.prop-input,
    select.prop-input,
    textarea.prop-input,
    .db-search-input,
    .db-filter-select,
    .plc-input {
        font-size: 13px;
    }
}
