/* =========================================================
   Multi-Map Factory Layout Monitor
   ========================================================= */

.layout-app {
    position: relative;
    max-width: 1600px;
    margin: 22px auto 40px;
    color: #172033;
}

.layout-page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
}

.layout-page-header h1 {
    margin: 0;
    color: #102447;
    font-size: 30px;
}

.layout-page-header p {
    margin: 6px 0 0;
    color: #667085;
}

.layout-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.layout-button,
.layout-main-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 15px;
    border: 1px solid transparent;
    border-radius: 9px;
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    text-decoration: none;
}

.layout-button.primary,
.layout-main-button {
    background: #145c96;
    color: #fff;
}

.layout-button.secondary {
    border-color: #c8d4e1;
    background: #fff;
    color: #344054;
}

.layout-button.warning {
    border-color: #e59534;
    background: #fff8ed;
    color: #9a4d00;
}

.layout-button.active {
    box-shadow: 0 0 0 3px rgba(20, 92, 150, .15);
}

.layout-button:disabled {
    cursor: not-allowed;
    opacity: .5;
}

.layout-button.has-change {
    animation: savePulse 1.1s ease-in-out infinite;
}

/* -------- map switcher -------- */
.map-switcher {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.map-card {
    display: block;
    padding: 14px 15px;
    border: 1px solid #d6e0ea;
    border-radius: 14px;
    background: linear-gradient(180deg, #fff 0%, #f7fbff 100%);
    box-shadow: 0 4px 16px rgba(16, 36, 71, .06);
    color: #172033;
    text-decoration: none;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.map-card:hover {
    transform: translateY(-2px);
    border-color: #145c96;
    box-shadow: 0 8px 22px rgba(16, 36, 71, .10);
}

.map-card.active {
    border-color: #145c96;
    background: linear-gradient(180deg, #ecf5ff 0%, #dff0ff 100%);
    box-shadow: 0 0 0 3px rgba(20, 92, 150, .12);
}

.map-card-title {
    display: block;
    color: #102447;
    font-size: 15px;
    font-weight: 900;
}

.map-card-desc {
    display: block;
    min-height: 32px;
    margin-top: 5px;
    color: #667085;
    font-size: 12px;
    line-height: 1.35;
}

.map-card-count {
    display: inline-block;
    margin-top: 9px;
    padding: 4px 9px;
    border-radius: 999px;
    background: #102447;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
}

.layout-stat-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(135px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.layout-stat-grid article {
    padding: 15px 17px;
    border: 1px solid #d7e0ea;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 4px 14px rgba(16, 36, 71, .06);
}

.layout-stat-grid span {
    display: block;
    color: #667085;
    font-size: 12px;
}

.layout-stat-grid strong {
    display: block;
    margin-top: 6px;
    color: #102447;
    font-size: 27px;
}

.layout-stat-grid .online { border-left: 5px solid #07883f; }
.layout-stat-grid .offline { border-left: 5px solid #d20a18; }
.layout-stat-grid .unknown { border-left: 5px solid #687386; }

.layout-workspace {
    display: grid;
    grid-template-columns: 310px minmax(0, 1fr);
    min-height: 760px;
    overflow: hidden;
    border: 1px solid #cbd7e5;
    border-radius: 15px;
    background: #fff;
    box-shadow: 0 8px 25px rgba(16, 36, 71, .08);
}

.layout-sidebar {
    display: flex;
    flex-direction: column;
    min-width: 0;
    border-right: 1px solid #d7e0ea;
    background: #f8fafc;
}

.sidebar-heading {
    padding: 17px;
    border-bottom: 1px solid #d7e0ea;
}

.sidebar-heading h2 {
    margin: 0;
    color: #102447;
    font-size: 17px;
}

.sidebar-heading span {
    display: block;
    margin-top: 5px;
    color: #667085;
    font-size: 12px;
}

.layout-search-box { padding: 12px 13px 8px; }

.layout-search-box input {
    width: 100%;
    min-height: 40px;
    padding: 0 12px;
    border: 1px solid #c9d5e2;
    border-radius: 8px;
    background: #fff;
    font: inherit;
}

.layout-filter-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 7px;
    padding: 0 13px 12px;
}

.filter-button {
    min-height: 34px;
    border: 1px solid #cbd7e5;
    border-radius: 7px;
    background: #fff;
    color: #475467;
    cursor: pointer;
    font-weight: 700;
}

.filter-button.active {
    border-color: #145c96;
    background: #145c96;
    color: #fff;
}

.layout-device-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 9px 12px;
}

.device-list-item {
    display: grid;
    grid-template-columns: 12px minmax(0, 1fr) auto;
    align-items: center;
    gap: 9px;
    width: 100%;
    margin-bottom: 6px;
    padding: 10px;
    border: 1px solid #d8e2ec;
    border-radius: 9px;
    background: #fff;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

.device-list-item:hover,
.device-list-item.selected {
    border-color: #145c96;
    box-shadow: 0 0 0 3px rgba(20, 92, 150, .11);
}

.list-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.list-status.online {
    background: #07883f;
    box-shadow: 0 0 0 4px rgba(7, 136, 63, .13);
}

.list-status.offline {
    background: #d20a18;
    box-shadow: 0 0 0 4px rgba(210, 10, 24, .13);
    animation: offlineDotBlink .8s steps(2, start) infinite;
}

.list-status.unknown { background: #687386; }

.list-main { min-width: 0; }

.list-main strong,
.list-main small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-main strong { font-size: 13px; }

.list-main small {
    margin-top: 3px;
    color: #667085;
    font-size: 11px;
}

.placement-state {
    color: #667085;
    font-size: 10px;
    white-space: nowrap;
}

.layout-sidebar-help {
    padding: 13px 16px;
    border-top: 1px solid #d7e0ea;
    background: #eef5fb;
    color: #344054;
    font-size: 11px;
}

.layout-sidebar-help ol {
    margin: 7px 0 0;
    padding-left: 17px;
}

.layout-main-panel {
    display: flex;
    min-width: 0;
    flex-direction: column;
    background:
        linear-gradient(#edf2f7 1px, transparent 1px),
        linear-gradient(90deg, #edf2f7 1px, transparent 1px),
        #f5f7fa;
    background-size: 22px 22px;
}

.layout-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 14px;
    border-bottom: 1px solid #d7e0ea;
    background: #fff;
}

.layout-map-title strong {
    display: block;
    color: #102447;
}

.layout-map-title span {
    display: block;
    margin-top: 3px;
    color: #667085;
    font-size: 11px;
}

.zoom-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.zoom-controls button {
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid #cbd7e5;
    border-radius: 7px;
    background: #fff;
    cursor: pointer;
    font-weight: 700;
}

.zoom-controls button.active {
    border-color: #d20a18;
    background: #d20a18;
    color: #fff;
}

#zoomValue {
    min-width: 52px;
    color: #475467;
    text-align: center;
    font-size: 12px;
}

.layout-viewport {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 20px;
}

.layout-canvas {
    position: relative;
    width: 100%;
    min-width: 900px;
    margin: 0 auto;
    overflow: hidden;
    border: 1px solid #9eabb8;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 8px 25px rgba(16, 36, 71, .15);
    transform-origin: top left;
}

.layout-canvas img {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
    user-select: none;
}

.marker-layer {
    position: absolute;
    inset: 0;
}

.layout-marker {
    position: absolute;
    z-index: 5;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 2px solid #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: pointer;
    color: #fff;
    box-shadow: 0 3px 12px rgba(0, 0, 0, .34);
    user-select: none;
    touch-action: none;
}

.edit-mode .layout-marker { cursor: grab; }

.layout-marker.dragging {
    z-index: 300;
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.22);
}

.marker-icon {
    position: relative;
    z-index: 2;
    display: grid;
    width: 100%;
    height: 100%;
    place-items: center;
    font-size: 11px;
    font-weight: 950;
}

.marker-pulse {
    position: absolute;
    inset: -5px;
    border: 2px solid currentColor;
    border-radius: 50%;
    opacity: .55;
}

.marker-label {
    position: absolute;
    left: 50%;
    top: calc(100% + 5px);
    min-width: max-content;
    max-width: 170px;
    padding: 4px 7px;
    border: 1px solid rgba(255,255,255,.55);
    border-radius: 5px;
    transform: translateX(-50%) translateY(-4px) scale(.94);
    background: rgba(16, 36, 71, .96);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    line-height: 1.2;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,.32);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity .16s ease, transform .16s ease, visibility .16s ease;
    z-index: 30;
}

.layout-marker:hover .marker-label,
.layout-marker:focus .marker-label,
.layout-marker:focus-visible .marker-label,
.layout-marker.dragging .marker-label,
.layout-marker.marker-focus .marker-label {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0) scale(1);
}

.layout-marker:hover,
.layout-marker:focus,
.layout-marker:focus-visible,
.layout-marker.dragging,
.layout-marker.marker-focus {
    z-index: 220;
}

.layout-marker.status-online {
    background: #07883f;
    color: #21d67b;
}

.layout-marker.status-online .marker-pulse {
    animation: onlineMarkerPulse 1.8s ease-out infinite;
}

.layout-marker.status-offline {
    background: #d20a18;
    color: #ff2736;
    animation: offlineMarkerBlink .75s steps(2, start) infinite;
}

.layout-marker.status-offline .marker-pulse {
    animation: offlineMarkerRing .8s ease-out infinite;
}

.layout-marker.status-offline .marker-label {
    background: rgba(174,0,15,.97);
}

.layout-marker.status-unknown {
    background: #687386;
    color: #aeb7c4;
}

.layout-marker.marker-focus {
    animation: markerFocus 1.7s ease-in-out;
}

.layout-notice {
    padding: 10px 14px;
    border-top: 1px solid #d7e0ea;
    background: #fff;
    color: #667085;
    font-size: 12px;
}

.marker-popup {
    position: absolute;
    z-index: 500;
    width: 285px;
    padding: 17px;
    border: 1px solid #cbd7e5;
    border-radius: 13px;
    background: #fff;
    box-shadow: 0 14px 40px rgba(16, 36, 71, .22);
}

.popup-close {
    position: absolute;
    right: 8px;
    top: 7px;
    width: 29px;
    height: 29px;
    border: 0;
    border-radius: 50%;
    background: #eef2f6;
    cursor: pointer;
    font-size: 20px;
}

.popup-status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #475467;
    font-size: 12px;
}

.popup-status-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
}
.popup-status-dot.online { background: #07883f; }
.popup-status-dot.offline { background: #d20a18; animation: offlineDotBlink .8s steps(2, start) infinite; }
.popup-status-dot.unknown { background: #687386; }

.marker-popup h3 {
    margin: 10px 30px 12px 0;
    color: #102447;
    font-size: 18px;
}

.marker-popup dl { margin: 0; }
.marker-popup dl div {
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr);
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid #edf1f5;
}
.marker-popup dt { color: #667085; font-size: 11px; }
.marker-popup dd {
    margin: 0;
    overflow-wrap: anywhere;
    color: #172033;
    font-size: 12px;
    font-weight: 700;
}

.popup-actions {
    display: grid;
    gap: 7px;
    margin-top: 13px;
}
.popup-actions a,
.popup-actions button {
    display: inline-flex;
    min-height: 37px;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    text-decoration: none;
}
.popup-actions a { background: #145c96; color: #fff; }
.popup-actions button { border-color: #ef9a9a; background: #fff1f1; color: #b42318; }

.layout-install-card {
    max-width: 700px;
    margin: 55px auto;
    padding: 28px;
    border: 1px solid #cbd7e5;
    border-radius: 15px;
    background: #fff;
    box-shadow: 0 8px 26px rgba(16, 36, 71, .1);
}
.layout-install-card h1 { margin-top: 0; color: #102447; }
.layout-message { margin: 18px 0; padding: 13px; border-radius: 9px; }
.layout-message.success { background: #dcfce7; color: #11653a; }
.layout-message.error { background: #fee2e2; color: #a10f18; }

@keyframes onlineMarkerPulse {
    0% { transform: scale(.75); opacity: .75; }
    100% { transform: scale(1.8); opacity: 0; }
}
@keyframes offlineMarkerBlink {
    0%, 46% { filter: brightness(1); transform: translate(-50%, -50%) scale(1); }
    47%, 100% { filter: brightness(1.45); transform: translate(-50%, -50%) scale(1.18); }
}
@keyframes offlineMarkerRing {
    0% { transform: scale(.8); opacity: .85; }
    100% { transform: scale(2); opacity: 0; }
}
@keyframes offlineDotBlink {
    0%, 45% { opacity: 1; }
    46%, 100% { opacity: .25; }
}
@keyframes markerFocus {
    0%, 100% { box-shadow: 0 3px 12px rgba(0, 0, 0, .34); }
    50% { box-shadow: 0 0 0 14px rgba(255, 196, 0, .38), 0 3px 12px rgba(0, 0, 0, .34); }
}
@keyframes savePulse {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.3); }
}

@media (max-width: 1100px) {
    .layout-workspace { grid-template-columns: 270px minmax(0, 1fr); }
    .layout-stat-grid { grid-template-columns: repeat(3, minmax(135px, 1fr)); }
}

@media (max-width: 780px) {
    .layout-page-header { align-items: flex-start; flex-direction: column; }
    .layout-workspace { display: block; }
    .layout-sidebar {
        max-height: 460px;
        border-right: 0;
        border-bottom: 1px solid #d7e0ea;
    }
    .layout-main-panel { min-height: 650px; }
    .layout-stat-grid { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
    .layout-toolbar { align-items: flex-start; flex-direction: column; }
}

@media (hover: none) {
    .layout-marker:hover .marker-label {
        opacity: 0;
        visibility: hidden;
    }

    .layout-marker.marker-focus .marker-label,
    .layout-marker.dragging .marker-label {
        opacity: 1;
        visibility: visible;
    }
}
