:root {
    color-scheme: dark;
    --bg: #020617;
    --panel: rgba(15, 23, 42, 0.88);
    --border: rgba(148, 163, 184, 0.2);
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --accent-strong: #0ea5e9;
    --success: #22c55e;
    --warning: #f59e0b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, Arial, sans-serif;
    background: radial-gradient(circle at top, #0f172a, var(--bg) 45%);
    color: var(--text);
}

button,
select {
    font: inherit;
}

.layout {
    display: grid;
    grid-template-columns: 360px 1fr;
    min-height: 100vh;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 28px;
    background: rgba(2, 6, 23, 0.82);
    border-right: 1px solid var(--border);
    backdrop-filter: blur(10px);
}

.workspace {
    padding: 24px;
    position: relative;
}

.workspace-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.user-menu {
    position: relative;
}

.user-menu-trigger {
    width: auto;
    min-width: 48px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(56, 189, 248, 0.35);
}

.user-menu-icon {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

.user-menu-name {
    font-weight: 600;
}

.user-menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    padding: 8px;
    background: rgba(2, 6, 23, 0.96);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 18px 36px rgba(15, 23, 42, 0.45);
    z-index: 5;
}

.user-menu-item {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text);
    text-decoration: none;
    text-align: left;
    background: transparent;
    border: none;
}

.user-menu-item:hover {
    background: rgba(56, 189, 248, 0.12);
}

.user-menu-logout-form {
    margin: 0;
}

.user-menu-logout {
    background: transparent;
    font-weight: 600;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(420px, 100%);
    padding: 28px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 20px;
}

.language-switcher {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.language-switcher-label {
    font-size: 0.8rem;
    color: var(--muted);
}

.language-switcher-select {
    width: 100%;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 10px;
    padding: 8px 10px;
    background: #0f172a;
    color: var(--text);
}

.auth-form {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.auth-form label {
    color: var(--muted);
    margin-top: 6px;
}

.auth-form input:not([type="checkbox"]) {
    width: 100%;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 12px;
    padding: 12px 14px;
    background: #0f172a;
    color: var(--text);
}

.auth-remember {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    color: var(--muted);
}

.auth-remember label {
    margin-top: 0;
    cursor: pointer;
}

.auth-remember input[type="checkbox"] {
    width: auto;
    margin: 0;
    accent-color: #38bdf8;
}

.auth-message {
    margin: 12px 0 0;
    padding: 10px 12px;
    border-radius: 10px;
}

.auth-message-error {
    color: #fecaca;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.35);
}

.auth-message-success {
    color: #bbf7d0;
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.35);
}

.instance-list {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.instance-option-form {
    margin: 0;
}

.instance-option {
    width: 100%;
    display: grid;
    gap: 4px;
    text-align: left;
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: #0f172a;
    color: var(--text);
    cursor: pointer;
}

.instance-option:hover {
    border-color: rgba(56, 189, 248, 0.7);
    background: rgba(56, 189, 248, 0.08);
}

.instance-option-meta {
    color: var(--muted);
    font-size: 0.9rem;
}

.auth-secondary-action {
    margin: 18px 0 0;
}

.link-button {
    background: transparent;
    border: none;
    color: var(--accent);
    padding: 0;
    cursor: pointer;
    font-weight: 600;
}

.users-layout {
    min-height: 100vh;
}

.users-workspace {
    display: grid;
    gap: 20px;
    align-content: start;
}

.nav-link {
    display: inline-block;
    margin-top: 12px;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.user-form {
    display: grid;
    gap: 10px;
}

.user-form input,
.user-form select {
    width: 100%;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 12px;
    padding: 12px 14px;
    background: #0f172a;
    color: var(--text);
}

.users-table {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.users-table-row {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr 1.2fr;
    gap: 12px;
    align-items: center;
    padding: 10px 12px;
    border-radius: 12px;
    background: #0f172a;
    border: 1px solid rgba(148, 163, 184, 0.18);
}

.users-table-header {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 0.9rem;
}

.users-table-actions {
    display: flex;
    gap: 8px;
}

.users-inline-button {
    width: auto;
    padding: 8px 12px;
}

.eyebrow {
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--accent);
    font-size: 0.76rem;
    font-weight: 700;
}

h1,
h2,
p {
    margin-top: 0;
}

.panel {
    padding: 18px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
}

.controls label,
.detail-grid span {
    display: block;
    color: var(--muted);
    margin-bottom: 8px;
}

.map-tabs-floating {
    position: absolute;
    top: 18px;
    left: 18px;
    right: 190px;
    z-index: 1100;
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    pointer-events: none;
}

.map-tabs-floating .map-tab {
    pointer-events: auto;
}

.map-tab {
    width: auto;
    padding: 10px 14px;
    background: #0f172a;
}

.map-tab.active {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #020617;
}

.device-explorer {
    display: grid;
    gap: 10px;
    max-height: 260px;
    overflow-y: auto;
}

.device-explorer-item {
    width: 100%;
    padding: 12px 14px;
    text-align: left;
    background: #0f172a;
    border: 1px solid rgba(148, 163, 184, 0.18);
    transition: border-color 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.device-explorer-item.active {
    border-color: rgba(56, 189, 248, 0.8);
    box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.3);
}

.device-explorer-item.connectivity-inactive {
    opacity: 0.72;
    border-color: rgba(148, 163, 184, 0.28);
}

.device-explorer-item.connectivity-online {
    border-color: rgba(34, 197, 94, 0.35);
}

.device-explorer-item.connectivity-offline {
    border-color: rgba(248, 113, 113, 0.35);
}

.device-explorer-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.device-explorer-item-header strong {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-explorer-item-status {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.92rem;
}

.device-connectivity {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex: 0 0 auto;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    line-height: 1;
    white-space: nowrap;
}

.device-connectivity-label {
    white-space: nowrap;
}

.device-connectivity-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 2px rgba(148, 163, 184, 0.15);
}

.device-connectivity.is-inactive {
    color: #94a3b8;
}

.device-connectivity.is-online {
    color: #4ade80;
}

.device-connectivity.is-online .device-connectivity-dot {
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.22);
    animation: device-online-pulse 2s ease-out infinite;
}

.device-connectivity.is-offline {
    color: #f87171;
}

.device-connectivity.is-offline .device-connectivity-dot {
    box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.18);
}

@keyframes device-online-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.55);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(74, 222, 128, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(74, 222, 128, 0);
    }
}

select,
button {
    width: 100%;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 12px 14px;
    background: #0f172a;
    color: var(--text);
}

button {
    cursor: pointer;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    font-weight: 700;
}

button.secondary {
    background: #1e293b;
}

button:hover,
select:hover {
    border-color: rgba(56, 189, 248, 0.5);
}

.button-row {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.canvas-shell {
    height: calc(100vh - 120px);
    position: relative;
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid var(--border);
    border-radius: 24px;
    overflow: auto;
}

.map-floating-controls {
    position: absolute;
    top: 18px;
    right: 18px;
    z-index: 3;
    display: flex;
    gap: 10px;
}

.map-control-button {
    width: 48px;
    height: 48px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(56, 189, 248, 0.35);
    box-shadow: 0 18px 36px rgba(15, 23, 42, 0.35);
}

.map-control-button-secondary {
    background: rgba(30, 41, 59, 0.92);
}

.map-control-button svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#mapCanvas {
    flex: 1 0 auto;
    align-self: stretch;
    width: 100%;
    height: 100%;
    min-width: 1200px;
    min-height: 760px;
    max-width: none;
    display: block;
    cursor: grab;
}

#mapCanvas.dragging {
    cursor: grabbing;
}

.muted {
    color: var(--muted);
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.detail-grid strong {
    word-break: break-word;
}

.device-action-popup {
    position: absolute;
    /* Above Leaflet panes/controls (~200–1000) and map tabs */
    z-index: 1200;
    pointer-events: auto;
    transform: translate(12px, -50%);
    background: rgba(2, 6, 23, 0.92);
    border: 1px solid rgba(56, 189, 248, 0.35);
    border-radius: 14px;
    padding: 8px;
    box-shadow: 0 18px 36px rgba(15, 23, 42, 0.45);
}

.device-switch {
    min-width: auto;
    width: 72px;
    padding: 6px;
    background: transparent;
    border: none;
    box-shadow: none;
}

.device-switch-track {
    display: flex;
    align-items: center;
    width: 60px;
    height: 32px;
    padding: 4px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.35);
    border: 1px solid rgba(148, 163, 184, 0.35);
    transition: background 0.2s ease, border-color 0.2s ease;
}

.device-switch-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #f8fafc;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.35);
    transition: transform 0.2s ease;
}

.device-switch.is-on .device-switch-track {
    background: rgba(34, 197, 94, 0.28);
    border-color: rgba(34, 197, 94, 0.55);
}

.device-switch.is-on .device-switch-thumb {
    transform: translateX(28px);
}

.device-switch:disabled {
    opacity: 0.65;
    cursor: default;
}

.status-on {
    color: var(--success);
}

.status-off {
    color: var(--warning);
}

.status-pending {
    color: var(--accent);
}

.status-error {
    color: #f87171;
}

@media (max-width: 980px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .workspace {
        padding-top: 0;
    }

    .canvas-shell {
        height: 70vh;
    }
}
