.app-shell {
    min-height: 100vh;
}

.sidebar {
    width: 290px;
    min-height: 100vh;
    position: sticky;
    top: 0;
    border-right: 1px solid var(--glass-border);
    z-index: 30;
}

.sidebar-header {
    min-height: 46px;
}

.sidebar-menu {
    display: block;
}

.sidebar-toggle {
    width: 44px;
    height: 44px;
    display: none;
    place-items: center;
    padding: 0;
    flex: 0 0 auto;
}

.sidebar-footer {
    border-top: 1px solid var(--glass-border);
}

.min-w-0 {
    min-width: 0;
}

.brand-mark {
    width: 46px;
    height: 46px;
    display: inline-grid;
    place-items: center;
    border-radius: 16px;
    border: rgba(0, 0, 0, 0.1) 1px solid;
    color: #fff;
    background: none;
    /*background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 16px 30px rgba(77, 171, 247, 0.22);*/
}

    .brand-mark img {
        height: 46px;
    }

.nav-link {
    color: var(--text-muted);
    border-radius: 14px;
    padding: .85rem 1rem;
    display: flex;
    align-items: center;
    gap: .75rem;
    transition: .2s ease;
}

    .nav-link:hover, .nav-link.active {
        color: var(--text-main);
        background: var(--surface-3);
    }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(18px);
    background: var(--topbar);
    border-bottom: 1px solid var(--glass-border);
}

.metric-card {
    border-radius: 24px;
    padding: 1.25rem;
    background: linear-gradient(180deg, var(--surface-3), var(--surface-2));
    border: 1px solid var(--glass-border);
    height: 100%;
}

.metric-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: inline-grid;
    place-items: center;
    background: var(--surface-3);
    font-size: 1.2rem;
}

.section-card {
    border-radius: 28px;
    overflow: hidden;
}

    .section-card .card-header {
        background: transparent;
        border-bottom: 1px solid var(--glass-border);
        padding: 1rem 1.25rem;
    }

    .section-card .card-body {
        padding: 1.25rem;
    }

.small-muted {
    color: var(--text-muted);
    font-size: .85rem;
}

.nav-pills .nav-link,
.theme-aware-btn {
    border: 1px solid var(--glass-border);
    background: var(--surface-2);
    color: var(--text-main);
    transition: background .2s ease, border-color .2s ease, color .2s ease, transform .2s ease;
}

    .nav-pills .nav-link.active,
    .theme-aware-btn.is-active,
    .theme-aware-btn:hover {
        background: linear-gradient(135deg, rgba(77,171,247,.25), rgba(124,77,255,.26));
        border-color: rgba(77,171,247,.36);
        color: var(--text-main);
    }

    .theme-aware-btn.is-active {
        box-shadow: 0 0 0 1px rgba(77,171,247,.18) inset;
    }

.theme-switcher .theme-aware-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.theme-aware-addon {
    background: var(--surface-2);
    color: var(--text-main);
    border-color: var(--glass-border);
}

.theme-aware-table {
    --bs-table-bg: transparent;
    --bs-table-hover-bg: var(--surface-2);
    color: var(--text-main);
}

.theme-aware-modal {
    background: var(--modal-bg);
    color: var(--text-main);
}

    .theme-aware-modal .modal-header {
        border-color: var(--glass-border);
    }

.machine-mini-card {
    background: var(--surface-2);
    border: 1px solid var(--glass-border);
    border-radius: 18px;
    padding: 1rem;
    height: auto;
}

.dashboard-state-column {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

    .dashboard-state-column .machine-mini-card {
        flex: 0 0 auto;
        margin-bottom: 0 !important;
    }

.factory-plan {
    position: relative;
    min-height: 680px;
    height: 72vh;
    border-radius: 24px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    cursor: grab;
    touch-action: none;
}

    .factory-plan.is-dragging {
        cursor: grabbing;
    }

.plan-viewport {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.plan-stage {
    position: absolute;
    width: 1600px;
    height: 1200px;
    transform-origin: 0 0;
    background: linear-gradient(180deg, var(--surface-2), rgba(255,255,255,0.01)), repeating-linear-gradient(0deg, var(--grid), var(--grid) 1px, transparent 1px, transparent 48px), repeating-linear-gradient(90deg, var(--grid), var(--grid) 1px, transparent 1px, transparent 48px);
    will-change: transform;
}

.floor-background,
.map-objects-layer {
    position: absolute;
    inset: 0;
}

.floor-background {
    opacity: 0.28;
    pointer-events: none;
    z-index: 1;
}

.map-objects-layer {
    z-index: 5;
}

.zone, .machine, .stairs-zone {
    position: absolute;
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: .5rem;
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}

.zone {
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    font-size: .85rem;
    font-weight: 600;
}

    .zone.workshop {
        background: var(--plan-workshop);
    }

    .zone.room {
        background: var(--plan-room);
    }

    .zone.stairs-zone {
        background: var(--plan-stairs);
        border-style: dashed;
    }

.machine {
    border: 1px solid var(--glass-border);
    background: color-mix(in srgb, var(--glass) 65%, transparent);
    color: var(--text-main);
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(0,0,0,.12);
    font-weight: 700;
}

    .machine:hover {
        transform: translateY(-2px) scale(1.01);
        box-shadow: 0 16px 36px rgba(0,0,0,.18);
    }

    .machine.on {
        box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.45), 0 12px 28px rgba(0,0,0,.18);
    }

    .machine.off {
        box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.4), 0 12px 28px rgba(0,0,0,.18);
    }

    .machine.maintenance {
        box-shadow: 0 0 0 1px rgba(255,193,7,0.5), 0 12px 28px rgba(0,0,0,.18);
    }

    .machine.disabled {
        box-shadow: 0 0 0 1px rgba(108, 117, 125, 0.45), 0 12px 28px rgba(0,0,0,.12);
        opacity: .9;
    }

    .machine.active {
        outline: 2px solid rgba(77,171,247,.6);
        outline-offset: 3px;
    }

.machine-name {
    font-size: .76rem;
    line-height: 1.15;
}

.scada-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 500px), 1fr));
    gap: 1rem;
}

.scada-card {
    position: relative;
    border-radius: 22px;
    padding: 1rem;
    border: 1px solid var(--glass-border);
    background: var(--surface-2);
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 1rem;
    min-height: 220px;
    cursor: pointer;
    transition: .2s ease;
}

    .scada-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 16px 36px rgba(0,0,0,.12);
    }

    .scada-card.active {
        box-shadow: 0 0 0 2px rgba(77,171,247,.35), 0 16px 36px rgba(0,0,0,.12);
    }

.scada-card-body {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.scada-preview.is-fallback .scada-fallback {
    display: flex;
}

.scada-fallback {
    display: none;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.scada-history-box, .history-chart-box, .modal-history-chart-box {
    position: relative;
    width: 100%;
    overflow: hidden;
}

.scada-history-box {
    height: 110px;
    min-height: 110px;
    max-height: 110px;
}

.history-chart-box {
    height: 220px;
    min-height: 220px;
    max-height: 220px;
}

.modal-history-chart-box {
    height: 240px;
    min-height: 240px;
    max-height: 240px;
}

    .scada-history-box canvas, .history-chart-box canvas, .modal-history-chart-box canvas {
        width: 100% !important;
        height: 100% !important;
        display: block;
    }

.scada-preview {
    position: relative;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    background: linear-gradient(180deg, var(--surface-3), var(--surface-2));
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
}

    .scada-preview img {
        width: 100%;
        height: 100%;
        object-fit: contain;
        display: block;
        filter: invert(var(--invert-machine-image));
    }

.scada-fallback {
    font-size: 2rem;
    opacity: .7;
}

.scada-status-dot {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,.9);
    box-shadow: 0 0 0 3px rgba(15,23,42,.16);
}

    .scada-status-dot.on {
        background: #2bd576;
    }

    .scada-status-dot.off {
        background: #ff6b6b;
    }

    .scada-status-dot.maintenance {
        background: #ffd43b;
    }

    .scada-status-dot.disabled {
        background: #adb5bd;
    }

.scada-card .mini-history-wrap {
    margin-top: .6rem;
}

.scada-card .metric-row {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    font-size: .9rem;
    margin-top: .35rem;
}

.scada-card .card-actions {
    margin-top: .65rem;
    color: var(--text-muted);
    font-size: .82rem;
}

.chart-placeholder {
    height: 180px;
    border: 1px dashed var(--glass-border);
    border-radius: 16px;
    display: grid;
    place-items: center;
    color: var(--text-muted);
}

@media (min-width: 992px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
    }

    .sidebar-menu {
        min-height: 0;
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
    }

    .sidebar-actions {
        margin-bottom: 1rem;
    }

    .sidebar-toggle {
        display: none !important;
    }

    .app-shell > main {
        min-width: 0;
        margin-left: 290px;
    }

    .dashboard-state-column {
        display: flex;
    }

    .state-panel {
        display: block;
    }
}

@media (max-width: 991.98px) {
    .sidebar {
        width: 100%;
        min-height: auto;
        position: relative;
        border-right: 0;
        border-bottom: 1px solid var(--glass-border);
    }

    .sidebar-header {
        margin-bottom: 0;
    }

    .sidebar-toggle {
        display: inline-grid;
    }

    .sidebar-menu {
        display: none;
        padding-top: 1rem;
    }

        .sidebar-menu.is-open {
            display: flex;
            flex-direction: column;
            gap: 1rem;
        }

    .sidebar-footer {
        margin-top: .25rem;
    }

    .factory-plan {
        height: min(72vh, 620px);
        min-height: 360px;
    }

    .dashboard-state-column.is-empty {
        display: none;
    }

    .state-panel.is-empty {
        display: none;
    }

    .scada-card {
        grid-template-columns: 1fr;
        min-height: 0;
    }

    .scada-preview {
        min-height: 150px;
        height: clamp(150px, 42vw, 230px);
    }

    .scada-card .mini-history-wrap {
        margin-top: .75rem;
    }
}

@media (max-width: 575.98px) {
    .section-card .card-body {
        padding: 1rem;
    }

    .factory-plan {
        height: min(70vh, 560px);
        min-height: 320px;
        border-radius: 18px;
    }

    .zone, .machine, .stairs-zone {
        border-radius: 12px;
        padding: .35rem;
    }

    .machine-name {
        font-size: .68rem;
    }

    .history-chart-box {
        height: 180px;
        min-height: 180px;
        max-height: 180px;
    }
}
