html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    background: #f4f6f8;
    overflow: hidden;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
}

.app-shell {
    display: grid;
    grid-template-columns: 380px 1fr;
    height: calc(100vh - 56px);
}

.sidebar {
    background: #ffffff;
    border-right: 1px solid #dfe3e8;
    overflow-y: auto;
}

.sidebar-inner {
    padding: 24px 16px;
}

.sidebar-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.category-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.category-filter.active {
    background: #212529 !important;
    color: #fff !important;
    border-color: #212529 !important;
}

.legend-group {
    padding-top: 2px;
}

.legend-group-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #6b7280;
    margin-bottom: 10px;
}

.legend-list {
    display: grid;
    gap: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    cursor: pointer;
}

.legend-item input[type="checkbox"] {
    margin: 0;
}

.legend-swatch {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    border: 2px solid #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,.18);
    flex: 0 0 auto;
    background: #64748b;
}

.legend-network { background: #2563eb; }
.legend-electric-group { background: #f59e0b; }
.legend-site { background: #6366f1; }

.legend-swatch svg {
    width: 16px;
    height: 16px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
}

.map-panel {
    position: relative;
    min-width: 0;
    height: 100%;
    overflow: hidden;
    background: #111;
}

#map {
    width: 100%;
    height: 100%;
    background: #111;
}

.object-layer {
    position: absolute;
    inset: 0;
    z-index: 30;
    pointer-events: none;
}

.map-object {
    position: absolute;
    transform: translate(-50%, -50%);
    pointer-events: auto;
    user-select: none;
}

.map-object.is-selected .map-object-marker {
    box-shadow: 0 0 0 3px rgba(255,255,255,.95), 0 0 0 6px rgba(13,110,253,.80);
}

.map-object.is-highlighted .map-object-marker {
    box-shadow: 0 0 0 3px rgba(255,255,255,.98), 0 0 0 7px rgba(250,204,21,.95);
    transform: scale(1.12);
}

.map-object-marker {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    border: 2px solid #ffffff;
    box-shadow: 0 3px 12px rgba(0,0,0,.35);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    line-height: 1;
    font-weight: 700;
    background: #ff3b30;
    transition: transform .15s ease, box-shadow .15s ease;
}

.map-object-marker:hover {
    transform: scale(1.08);
}

.map-object-marker svg {
    width: 16px;
    height: 16px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
}

.map-object-label {
    position: absolute;
    transform-origin: center center;
    white-space: nowrap;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(17,17,17,.78);
    border: 1px solid rgba(255,255,255,.12);
    box-shadow: 0 4px 14px rgba(0,0,0,.22);
    cursor: pointer;
    pointer-events: auto;
    user-select: none;
    font-weight: 700;
}

.map-object.is-selected .map-object-label {
    box-shadow: 0 0 0 2px rgba(255,255,255,.95), 0 0 0 5px rgba(13,110,253,.55);
}

.map-object.is-highlighted .map-object-label {
    box-shadow: 0 0 0 2px rgba(255,255,255,.98), 0 0 0 5px rgba(250,204,21,.85);
}

.mode-btn.active {
    background: #212529 !important;
    color: #fff !important;
    border-color: #212529 !important;
}

.openseadragon-container,
#map,
#map canvas,
#map .openseadragon-canvas {
    background: #111 !important;
}

@media (max-width: 992px) {
    body {
        overflow: auto;
    }

    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: 420px 1fr;
        height: calc(100vh - 56px);
    }

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid #dfe3e8;
    }
}


.legend-accordion {
    display: grid;
    gap: 10px;
}

.legend-accordion-item {
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
}

.legend-accordion-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: #f8fafc;
    border: 0;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #334155;
    cursor: pointer;
}

.legend-accordion-toggle:hover {
    background: #f1f5f9;
}

.legend-accordion-icon {
    font-size: 18px;
    line-height: 1;
    font-weight: 400;
}

.legend-accordion-panel {
    display: none;
    padding: 12px 14px 14px;
}

.legend-accordion-panel.is-open {
    display: block;
}

.diagram-shell {
    display: grid;
    grid-template-columns: 360px 1fr;
    height: calc(100vh - 56px);
}

.diagram-sidebar {
    background: #ffffff;
    border-right: 1px solid #dfe3e8;
    overflow-y: auto;
}

.diagram-sidebar-inner {
    padding: 24px 16px;
}

.diagram-main {
    position: relative;
    min-width: 0;
    height: 100%;
    overflow: auto;
    background: #0f172a;
}

.diagram-canvas {
    position: relative;
    min-width: 1600px;
    min-height: 1000px;
    width: 1600px;
    height: 1000px;
    background: #0f172a;
    background-image:
        linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
    background-size: 32px 32px;
}

.diagram-node {
    position: absolute;
    transform: translate(-50%, -50%);
    user-select: none;
}

.diagram-node-marker {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    border: 2px solid rgba(255,255,255,.9);
    box-shadow: 0 8px 20px rgba(0,0,0,.28);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: grab;
    background: #2563eb;
}

.diagram-node-marker:active {
    cursor: grabbing;
}

.diagram-node-marker svg {
    width: 28px;
    height: 28px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
}

.diagram-node-label {
    position: absolute;
    top: 72px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    background: rgba(15,23,42,.88);
    color: #fff;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 4px 14px rgba(0,0,0,.24);
}

@media (max-width: 992px) {
    .diagram-shell {
        grid-template-columns: 1fr;
        grid-template-rows: 360px 1fr;
    }

    .diagram-sidebar {
        border-right: 0;
        border-bottom: 1px solid #dfe3e8;
    }
}

.landing-page {
    min-height: calc(100vh - 56px);
    background:
        radial-gradient(circle at top left, rgba(37,99,235,.08), transparent 30%),
        radial-gradient(circle at bottom right, rgba(245,158,11,.08), transparent 30%),
        #f4f6f8;
    padding: 48px 24px;
}

.landing-hero {
    max-width: 1320px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1.3fr .8fr;
    gap: 28px;
    align-items: start;
}

.landing-hero-content,
.landing-login-card,
.auth-card {
    background: rgba(255,255,255,.92);
    border: 1px solid rgba(15,23,42,.08);
    border-radius: 24px;
    box-shadow: 0 18px 50px rgba(15,23,42,.08);
    backdrop-filter: blur(8px);
}

.landing-hero-content {
    padding: 40px;
}

.landing-badge {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 999px;
    background: #111827;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .03em;
    margin-bottom: 18px;
}

.landing-title {
    font-size: 56px;
    font-weight: 800;
    line-height: 1.02;
    margin-bottom: 18px;
    color: #0f172a;
}

.landing-subtitle {
    font-size: 18px;
    line-height: 1.7;
    color: #475569;
    max-width: 820px;
    margin-bottom: 28px;
}

.landing-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 30px;
}

.landing-feature-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
    gap: 16px;
}

.landing-feature-card {
    padding: 20px;
    border-radius: 20px;
    background: #fff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 8px 24px rgba(15,23,42,.04);
}

.landing-feature-title {
    font-weight: 700;
    margin-bottom: 8px;
    color: #0f172a;
}

.landing-feature-text {
    color: #64748b;
    line-height: 1.6;
}

.landing-login-card,
.auth-card {
    padding: 32px;
}

.landing-login-title,
.auth-title {
    font-size: 32px;
    font-weight: 800;
    color: #0f172a;
    margin-bottom: 8px;
}

.landing-login-subtitle,
.auth-subtitle {
    color: #64748b;
    margin-bottom: 24px;
}

.landing-login-links,
.auth-links {
    margin-top: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.landing-login-links a,
.auth-links a {
    color: #1d4ed8;
    text-decoration: none;
    font-weight: 600;
}

.auth-page {
    min-height: calc(100vh - 56px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    background:
        radial-gradient(circle at top left, rgba(37,99,235,.08), transparent 30%),
        radial-gradient(circle at bottom right, rgba(245,158,11,.08), transparent 30%),
        #f4f6f8;
}

.auth-card {
    width: 100%;
    max-width: 520px;
}

.auth-card-wide {
    max-width: 860px;
}

.auth-form ul.errorlist {
    padding-left: 18px;
    margin: 8px 0 0;
    color: #dc2626;
    font-size: 14px;
}

@media (max-width: 992px) {
    .landing-hero {
        grid-template-columns: 1fr;
    }

    .landing-title {
        font-size: 40px;
    }

    .landing-feature-grid {
        grid-template-columns: 1fr;
    }
}

.audit-page {
    padding: 32px 24px 48px;
    max-width: 1500px;
    margin: 0 auto;
}

.audit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.audit-title {
    font-size: 34px;
    font-weight: 800;
    margin: 0 0 8px;
    color: #0f172a;
}

.audit-subtitle {
    margin: 0;
    color: #64748b;
}

.audit-table th {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #475569;
    background: #f8fafc;
}

.audit-summary {
    cursor: pointer;
    color: #1d4ed8;
    font-weight: 600;
}

.audit-pre {
    margin-top: 10px;
    padding: 12px;
    border-radius: 12px;
    background: #0f172a;
    color: #e2e8f0;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}
