/* Table styles removed — will recreate table and styles from scratch. */
/* FLEX layout for chart and table side by side on wide screens (sensor.php) */
.main-flex-wrap {
    display: flex;
    flex-direction: row;
    gap: 0;
    align-items: stretch; /* make chart and table equal height */
    width: 100%;
    position: relative;
}

.main-flex-wrap .divider {
    width: 2px;
    background: var(--line);
    min-height: 420px;
    align-self: stretch;
    margin: 0 16px;
    border-radius: 2px;
}

#chartBox {
    flex: 0 1 60%;
    min-width: 320px;
    max-width: 100%;
}

#tableBox {
    flex: 1 1 40%;
    min-width: 0;
    width: 100%;
    margin-top: 0;
    display: flex;
    flex-direction: column;
}

/* Table layout removed — will recreate markup and styles later */

/* table styles consolidated at file top (cleaned) */

/* ===== Sensor data table (now re-created) ===== */
#tableBox .table-responsive {
    overflow: auto;
    width: 100%;
    flex: 1 1 auto;
    min-height: 400px;
    max-height: 600px;
}
#tableBox .sensor-data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
#tableBox .sensor-data-table th,
#tableBox .sensor-data-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
#tableBox .sensor-data-table th {
    background: #fbfdff;
    color: var(--muted);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 2;
}
#tableBox .sensor-data-table tbody tr:hover {
    background: #f8fbff;
}
#tableBox .sensor-data-table td:nth-child(1) { width: 56px; }
#tableBox .sensor-data-table td:nth-child(4) { width: 96px; }
#tableBox .sensor-data-table td:nth-child(5) { white-space: nowrap; }

/* Tables used in list views (devices.php, device.php) */
.table-wrap {
    overflow-x: auto;
}
.table-wrap table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}
.table-wrap th,
.table-wrap td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

/* Page-specific table overrides */
#devicesTableWrap table {
    /* devices list: full-width table, compact cells */
    width: 100%;
}
#sensorsTableWrap table {
    /* device -> sensors list: allow columns to size naturally but keep full width */
    width: 100%;
}
#manageNamesTableWrap table {
    /* manage names: ensure inputs fill cells */
    width: 100%;
}

/* manage_names.php: keep default table sizing (no global overrides here) */
#manageNamesTableWrap table {
    width: 100%;
}
#manageNamesTableWrap input[type="text"] {
    width: 100%;
    box-sizing: border-box;
}

/* make ID column fixed width in manage_names table */
#manageNamesTableWrap .col-id {
    width: 140px;
    min-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* make 'Inne' column wider to fit two buttons */
#manageNamesTableWrap th:nth-child(4),
#manageNamesTableWrap td:nth-child(4) {
    width: 220px;
    min-width: 220px;
    white-space: nowrap;
    text-align: center;
}

/* reduce horizontal gap for buttons inside the 'Inne' column */
#manageNamesTableWrap td:nth-child(4) .btn {
    margin-left: 6px;
    margin-right: 0;
    padding: 6px 10px;
}

/* red delete button styling inside manage_names */
#manageNamesTableWrap .btn-danger {
    background: #d32f2f;
    border-color: #d32f2f;
    color: #fff;
}
#manageNamesTableWrap .btn-danger:hover {
    background: #b71c1c;
    border-color: #b71c1c;
}

/* Small inputs / tighter spacing only inside popups (do not affect main lists) */
.map-modal-panel .table-wrap th,
.map-modal-panel .table-wrap td,
.device-info-popup .table-wrap th,
.device-info-popup .table-wrap td {
    padding: 4px 6px;
    font-size: 0.92rem;
}
.map-modal-panel input[type="text"],
.device-info-popup input[type="text"] {
    padding: 4px 6px;
    margin: 0;
    font-size: 0.92rem;
    box-sizing: border-box;
}

/* make popup tables size columns to content */
.map-modal-panel .table-wrap table,
.device-info-popup .table-wrap table {
    table-layout: auto;
    width: auto; /* allow columns to size to their content */
    max-width: 100%;
}
.map-modal-panel .table-wrap th,
.device-info-popup .table-wrap th {
    white-space: nowrap; /* keep headers compact and let columns expand */
}
.map-modal-panel .table-wrap td,
.device-info-popup .table-wrap td {
    white-space: nowrap;
}

/* Options popup: reduce spacing between edit fields and buttons */
#optionsOverlay .device-info-body > div {
    margin-bottom: 6px !important;
}
#optionsOverlay .device-info-body > div[style*="display:flex"] {
    gap: 6px !important;
    align-items: center !important;
}
#optionsOverlay .device-info-body > div[style*="flex-direction:column"] {
    gap: 6px !important;
}
#optionsOverlay .device-info-body input[type="number"],
#optionsOverlay .device-info-body select {
    padding: 6px !important;
    box-sizing: border-box !important;
}
#optionsOverlay .device-info-body .btn {
    padding: 6px 8px !important;
}
#optionsOverlay .device-info-body .muted {
    font-size: 0.82rem !important;
    margin-top: 2px !important;
}

/* avoid duplicate/invalid rules and ensure table layout is valid */
#chartBox {
    display: flex;
    flex-direction: column;
}

#chartBox .chart-box {
    flex: 1 1 auto;
    min-height: 400px;
    max-height: 600px;
}

@media (max-width: 1100px) {
    .main-flex-wrap {
        flex-direction: column;
        gap: 16px;
    }
    .main-flex-wrap .divider {
        width: 100%;
        height: 2px;
        min-height: unset;
        margin: 16px 0;
    }
    #chartBox, #tableBox {
        max-width: 100% !important;
        min-width: 0 !important;
    }
}
:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success-bg: #e8f7ef;
    --success-text: #166534;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text);
    background: var(--bg);
    position: relative;
    z-index: 0;
}

.container {
    width: 98vw !important;
    /* max-width i min-width usunięte, aby panel rozciągał się do krawędzi */
        margin: 10px !important;
    padding: 0 16px !important;
    box-sizing: border-box;
        width: calc(100vw - 20px) !important;
        height: calc(100vh - 20px) !important;
}

.card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    position: relative;
    max-width: 100%;
    width: 100%;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 5px;
    padding-top: 0;
    flex-wrap: wrap;
}

.topbar > .actions {
    margin-left: auto;
    align-self: flex-start;
    justify-content: flex-end;
}

@media (min-width: 769px) {
    .devices-page-card .topbar {
        margin-bottom: -24px;
    }

    .devices-page-card .subtitle-actions-row {
        margin-top: 0;
    }

    .devices-page-card .devices-view-toggle {
        margin-right: 28px;
    }

    .sensors-page-card .topbar {
        margin-bottom: -16px;
    }

    .sensors-page-card .devices-view-toggle {
        margin-right: 28px;
    }

    .sensors-page-card #manageSensorNamesWrap {
        margin-top: 0 !important;
    }
}

.logo {
    position: static;
    max-height: 120px;
    width: auto;
    height: auto;
    margin: 0;
    vertical-align: middle;
}

.header-with-logo {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 0;
    padding-top:0px;
    padding-left: 0px;
}

@media (max-width: 768px) {
    .logo {
    }
    .container {
        margin: 12px auto;
        padding: 0 10px;
    }
}

.header-with-logo {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Illustration next to header on device page */
.device-illustration {
    /* larger illustration on desktop */
    max-width: 320px;
    width: 220px;
    min-width: 160px;
    margin-left: 24px;
    display: inline-block;
    vertical-align: top;
}
.device-illustration img {
    width: 100%;
    height: auto;
    display: block;
}

/* hide illustration on small screens for cleaner layout */
@media (max-width: 768px) {
    .device-illustration { display: none !important; }
}

h1,
h2 {
    margin: 0;
}

h1 {
    font-size: 1.35rem;
}

h2 {
    font-size: 1.1rem;
    margin-bottom: 12px;
}

.subtitle {
    margin: 8px 0 0;
    color: var(--muted);
}

.sensor-page-identification {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    padding: 5px;
}

.sensor-switcher {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    color: var(--muted);
}

.device-switcher {
    margin-top: 8px;
}

.sensor-switcher-label {
    flex: 0 0 auto;
}

.sensor-switcher-current {
    min-width: 0;
    color: var(--text);
}

.sensor-switcher-controls {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 4px;
}

.sensor-switch-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    box-sizing: border-box;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
    background: #eff6ff;
    color: var(--primary);
    text-decoration: none;
    transition: background-color .15s ease, border-color .15s ease, transform .15s ease;
}

.sensor-switch-button:hover {
    border-color: var(--primary);
    background: #dbeafe;
    transform: translateY(-1px);
}

.sensor-switch-button:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .25);
    outline-offset: 2px;
}

.sensor-switch-button.is-disabled {
    border-color: #e2e8f0;
    background: #f8fafc;
    color: #cbd5e1;
}

.sensor-switch-button svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sensor-switcher-count {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: .78rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.sensor-central-label {
    margin: 4px 0 0;
}

.subtitle-actions-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 8px 0 0;
}

.subtitle-actions-row .subtitle {
    margin: 0;
}

.subtitle-actions {
    margin-left: auto;
    justify-content: flex-end;
}

.devices-sort-control {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font-size: 0.9rem;
    white-space: nowrap;
}

.devices-sort-control select {
    min-height: 36px;
    padding: 6px 32px 6px 10px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #fff;
    color: var(--text);
}

.devices-sort-control select:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

.device-list-actions {
    justify-content: flex-end;
    margin-left: auto;
}

.devices-view-toggle {
    display: inline-flex;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #fff;
}

.devices-view-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    padding: 6px 10px;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.devices-view-button + .devices-view-button {
    border-left: 1px solid var(--line);
}

.devices-view-button svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.devices-view-button[aria-pressed="true"] {
    background: var(--primary);
    color: #fff;
}

.devices-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
    gap: 14px;
    margin-top: 16px;
}

.devices-card-grid[hidden],
#devicesTableWrap[hidden],
#sensorsTableWrap[hidden] {
    display: none !important;
}

.device-list-card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    padding: 17px;
    border: 1px solid #bfdbfe;
    border-radius: 13px;
    background: linear-gradient(180deg, #fff 0%, #fbfdff 100%);
    box-shadow: 0 5px 17px rgba(37, 99, 235, 0.13);
}

.device-list-card::before {
    content: '';
    position: absolute;
    inset: 0 0 auto;
    height: 4px;
    background: var(--primary);
}

.device-list-card-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
}

.device-list-card-number {
    display: inline-grid;
    place-items: center;
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    border: 1px solid #bfdbfe;
    border-radius: 50%;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: .8rem;
    font-weight: 750;
}

.device-list-card-identity {
    flex: 1 1 auto;
    min-width: 0;
}

.device-list-card-title {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
}

.device-list-card-title h2 {
    margin: 2px 0;
    font-size: 1rem;
    overflow-wrap: anywhere;
}

.device-list-card-id-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 3px;
}

.device-list-card-id-row .device-status {
    margin-left: 0;
}

.device-list-card-id-row > .muted {
    font-size: .82rem;
    overflow-wrap: anywhere;
}

.device-list-card-identity p,
.device-list-card-identity > span {
    display: block;
    margin: 3px 0 0;
    font-size: .82rem;
    overflow-wrap: anywhere;
}

.device-list-card .btn-info-icon {
    flex: 0 0 auto;
    margin: -3px -5px 0 0;
}

.device-list-card-readings {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    margin-top: 14px;
}

.device-list-card-reading {
    min-width: 0;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 9px;
    background: #f8fafc;
}

.device-list-card-reading > span {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: .75rem;
}

.device-list-card-reading > strong {
    display: block;
    font-size: .95rem;
    overflow-wrap: anywhere;
}

.device-list-card-value {
    white-space: nowrap;
}

.device-list-card-value.is-high {
    color: #dc2626;
}

.device-list-card-value.is-low {
    color: #2563eb;
}

.device-list-card-last-seen {
    grid-column: 1 / -1;
}

.device-list-card-last-seen .is-stale {
    color: #d32f2f;
}

.device-list-card-action {
    margin-top: 12px;
    text-align: center;
}

.sensor-list-card {
    border-color: #c7d2fe;
    box-shadow: 0 5px 17px rgba(99, 102, 241, 0.14);
}

.sensor-list-card::before {
    background: #6366f1;
}

.sensor-list-card .device-list-card-number {
    border-color: #c7d2fe;
    background: #eef2ff;
    color: #4f46e5;
}

.sensor-list-card .stale-data-badge {
    margin-left: 0;
}

.sensor-list-card .device-list-card-action {
    border-color: #6366f1;
    background: #6366f1;
}

.sensor-list-card .device-list-card-action:hover {
    border-color: #4f46e5;
    background: #4f46e5;
}

.device-list-card-value.is-battery-good {
    color: #15803d;
}

.device-list-card-value.is-battery-mid {
    color: #d97706;
}

.device-list-card-value.is-battery-low,
.device-list-card-reading .is-stale {
    color: #d32f2f;
}

.btn.btn-with-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

.btn.btn-with-icon svg {
    width: 17px;
    height: 17px;
    flex: 0 0 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

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

.user-menu-wrap {
    position: relative;
    display: inline-flex;
}

.user-menu-toggle {
    min-width: 42px;
    padding: 8px 10px;
    line-height: 1;
}

.user-menu-toggle svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.user-menu-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 150px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14);
    z-index: 8800;
    overflow: hidden;
}

.user-menu-wrap.open .user-menu-dropdown {
    display: block;
}

.user-menu-item {
    display: block;
    padding: 9px 12px;
    text-decoration: none;
    color: #0f172a;
    font-size: 0.9rem;
}

.user-menu-item:hover {
    background: #f8fafc;
}

.user-menu-item-danger {
    color: #b91c1c;
}

.user-menu-item-danger:hover {
    background: #fef2f2;
    color: #991b1b;
}

.btn {
    display: inline-block;
    text-decoration: none;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.92rem;
    cursor: pointer;
}

.btn:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn.btn-light {
    background: #fff;
    color: var(--primary);
}

.btn.btn-light:hover {
    background: #f0f0f0;
}

/* Informational icon button used in devices table */
.btn-info-icon {
    background: transparent;
    border: none;
    color: var(--primary);
    padding: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ===== Auth pages (login / register / reset) ===== */
body.auth-page { position: relative; min-height: 100vh; }
body.auth-page::before {
    content: "";
    position: fixed;
    inset: 0;
    background: url('img/Background.webp') no-repeat center/cover;
    background-attachment: fixed;
    opacity: 0.5; /* 50% transparency */
    z-index: 0;
    pointer-events: none;
}

.auth-form {
    position: relative; /* ensure z-index applies */
    z-index: 2;
    max-width: 420px;
    margin: 40px auto;
    padding: 22px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.auth-form h1 { font-size: 1.35rem; margin-bottom: 14px; text-align: center; }
.form-group { margin-bottom: 14px; }
.form-group label { display:block; margin-bottom:6px; font-weight:500; color:var(--text); }
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"] {
    width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 1rem; box-sizing: border-box; background: #fff; color: var(--text);
}
.form-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.08); }
.form-actions { text-align: center; }
.muted-center { text-align:center; color:var(--muted); font-size:0.95rem; margin-top:8px; }

.error { color: #dc2626; background: #fee2e2; padding: 12px; border-radius: 8px; margin-bottom: 16px; border-left: 4px solid #dc2626; }
.success { color: var(--success-text); background: var(--success-bg); padding: 12px; border-radius: 8px; margin-bottom: 16px; border-left: 4px solid #16a34a; }
.info { color: #1e40af; background: #dbeafe; padding: 12px; border-radius: 8px; margin-bottom: 16px; border-left: 4px solid #2563eb; font-size: 0.95rem; }
.password-requirements { background: #f3f4f6; padding: 12px; border-radius: 8px; margin-bottom: 16px; font-size: 0.85rem; color: var(--muted); }
.password-requirements ul { margin: 8px 0 0 0; padding-left: 20px; }
.code-info { background: #dbeafe; padding: 12px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; color: #1e40af; }
.code-info .test-code { font-family: monospace; font-weight: bold; color: #dc2626; }
.auth-link { text-align: center; margin-top: 12px; color: var(--muted); }
.auth-link a { color: var(--primary); text-decoration: none; }
.auth-link a:hover { text-decoration: underline; }
.auth-link .auth-mobile-inline-link { display: inline-block; margin-top: 10px; }

@media (max-width: 480px) {
    .auth-form { margin: 18px 12px; padding: 16px; }
}
.btn-info-icon svg {
    width: 22px;
    height: 22px;
    display: block;
}
.btn-info-icon:focus {
    outline: 2px solid rgba(37,99,235,0.25);
    outline-offset: 2px;
}

/* Simple fallback icon (rendered as text inside a circle) to avoid SVG render issues after innerHTML replace */
.btn-info-icon {
    /* ensure button layout is stable and not overridden */
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 28px !important;
    min-height: 28px !important;
    padding: 4px !important;
    background: transparent !important;
    border: none !important;
    color: var(--primary) !important;
}

.btn-info-icon .info-mark,
.btn-info-icon svg {
    width: 22px !important;
    height: 22px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.btn-info-icon .info-mark {
    border: 2px solid var(--primary) !important;
    border-radius: 50% !important;
    font-weight: 700 !important;
    font-size: 12px !important;
    line-height: 1 !important;
    color: var(--primary) !important;
    background: #fff !important;
}

.btn-info-icon svg { fill: none !important; stroke: var(--primary) !important; }

input,
select,
button {
    font: inherit;
}

input[type="date"] {
    border: 1px solid var(--line) !important;
    border-radius: 10px !important;
    padding: 8px 10px;
    background: #fff;
    color: var(--text);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    outline: none;
}

input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.7;
}

input[type="date"]::-webkit-datetime-edit-fields-wrapper {
    padding: 0;
}

input[type="date"]:focus {
    border-color: var(--primary) !important;
    outline: none;
}

/* Controls used for period/date selection (match sensor.php styling) */
.range-control,
select.range-control,
input.range-control {
    border: 1px solid var(--primary) !important;
    border-radius: 10px !important;
    color: var(--primary);
    padding: 6px 10px; /* increased padding to match sensor.php controls */
    font-size: 0.9em;
    line-height: 1.2;
    background: #fff;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    box-sizing: border-box;
    min-height: 34px; /* ensure visual height matches sensor.php */
}

/* when focused, use primary outline similar to other inputs */
select.range-control:focus,
input.range-control:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.08);
}

/* Table-related global rules removed — will recreate table-specific styles later */

tbody tr:hover {
    background: #f8fbff;
}

.btn, input.btn, button.btn {
    display: inline-block;
    text-decoration: none;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.92rem;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    line-height: 1.2;
}
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--success-bg);
    color: var(--success-text);
    font-size: 0.9rem;
}

.muted {
    color: var(--muted);
}

.section {
    margin-top: 18px;
}

.chart-box {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px;
}

/* Loader overlay for charts */
.chart-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(255,255,255,0.9);
    z-index: 50;
    flex-direction: row;
}
.chart-loader .chart-spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 4px solid rgba(0,0,0,0.08);
    border-top-color: var(--primary);
    animation: spin 1s linear infinite;
}
.chart-loader-text { color: var(--muted); font-weight: 600; }

@keyframes spin { to { transform: rotate(360deg); } }

.chart-box canvas {
    width: 100% !important;
    height: auto !important;
    display: block;
}

/* Floating illustration overlay (desktop only) */
.floating-illustration {
    position: absolute;
    top: 28px;
    right: 28px;
    width: 300px;
    max-width: 34%;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 8px 24px rgba(15,23,42,0.08);
    z-index: 120;
    display: none;
    align-items: center;
    justify-content: center;
}
.floating-illustration .floating-illustration-body img {
    width: 100%;
    height: auto;
    display: block;
}
.floating-illustration .floating-illustration-thumb {
    border: none;
    background: transparent;
    padding: 0;
    display: block;
    cursor: zoom-in;
}
.floating-illustration .floating-illustration-thumb img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
}
.floating-illustration-close {
    position: absolute;
    top: 6px;
    right: 8px;
    border: none;
    background: transparent;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
}

/* Image lightbox */
.image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1400;
    display: flex;
    align-items: center;
    justify-content: center;
}
.image-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
}
.image-lightbox-panel {
    position: relative;
    z-index: 1410;
    max-width: 90vw;
    max-height: 90vh;
    background: transparent;
    border-radius: 8px;
    overflow: hidden;
    display:flex;
    align-items:center;
    justify-content:center;
}

/* Anchored lightbox (appear near a trigger button instead of center) */
.image-lightbox.anchored {
    display: block; /* we position panel absolutely */
}
.image-lightbox.anchored .image-lightbox-backdrop {
    display: none; /* hide full-screen backdrop when anchored */
}
.image-lightbox.anchored .image-lightbox-panel {
    /* size to image while respecting viewport limits */
    width: auto;
    height: auto;
    max-width: 80vw;
    max-height: 80vh;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 18px 42px rgba(0,0,0,0.36);
    padding: 0; /* header + image will define padding */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.image-lightbox-body img {
    width: auto;
    height: auto;
    max-width: calc(80vw - 32px);
    max-height: calc(80vh - 64px);
    display: block;
    border-radius: 0 0 8px 8px;
    object-fit: contain;
}
.image-lightbox-close {
    position: absolute;
    top: 10px;
    right: 12px;
    z-index: 1420;
    background: #fff;
    border: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0,0,0,0.12);
}

/* smaller thumbnail on narrow screens, and hidden overlay */
@media (max-width: 1024px) {
    .floating-illustration { width: 220px; max-width: 38%; }
}
@media (max-width: 768px) {
    .floating-illustration { display: none !important; }
}

/* hide floating illustration on small screens */
@media (max-width: 768px) {
    .floating-illustration { display: none !important; }
}

/* Floating Action Button (FAB) - bottom right */
.floating-action-button {
    position: absolute; /* positioned inside .card near the table */
    left: 24px; /* align left above the table */
    top: 220px; /* adjust vertical position as needed */
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1500;
    box-shadow: 0 8px 20px rgba(15,23,42,0.14);
    border: none;
    cursor: pointer;
    font-size: 18px;
}
.floating-action-button:active { transform: translateY(1px); }
.floating-action-button:focus { outline: none; box-shadow: 0 12px 24px rgba(15,23,42,0.22), 0 0 0 4px rgba(37,99,235,0.08); }

/* Inline illustration/info button styled as blue circular icon with white 'i' */
#openIllustrationInline,
.btn-info-icon.inline-illustration,
.btn-info-icon.icon-circle {
    background: var(--primary) !important;
    color: #fff !important;
    border-radius: 50% !important;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: none !important;
    font-weight: 700 !important;
    font-size: 16px !important;
    box-shadow: 0 6px 14px rgba(15,23,42,0.12);
}
.btn-info-icon.inline-illustration .info-mark { border: none !important; background: transparent !important; color: #fff !important; }

@media (max-width: 768px) {
    .floating-action-button { display: none !important; }
}

body.mobile-device .container {
    margin: 12px auto;
    padding: 0 10px;
}

/* --- Custom: inline illustration button and anchored popup header --- */
/* Anchored panel header (show a small top bar with close button) */
.image-lightbox.anchored .image-lightbox-panel {
    padding: 0 !important; /* panel uses header + image sizing */
}
.image-lightbox.anchored .image-lightbox-header {
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, #ffffff, #fbfdff);
}
.image-lightbox.anchored .image-lightbox-close {
    margin: 0;
    top: auto !important;
    right: auto !important;
    position: relative !important;
}
.image-lightbox.anchored .image-lightbox-panel > * { position: relative; z-index: 1420; }

/* Illustration button base appearance. Its floating placement is defined below. */
#openIllustrationInline {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    line-height: 1;
    border: 1px solid var(--primary);
    background: #fff;
    color: var(--primary);
}
#openIllustrationInline:hover { background: #f8fbff; }

#openIllustrationInline.sensor-illustration-fab {
    position: fixed;
    right: 26px;
    bottom: 24px;
    z-index: 8500;
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    margin: 0;
    border: 0 !important;
    background: var(--primary) !important;
    color: #fff !important;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.32);
    transition: transform .16s ease, box-shadow .16s ease, background-color .16s ease;
}

#openIllustrationInline.sensor-illustration-fab:hover {
    background: #1d4ed8 !important;
    box-shadow: 0 13px 28px rgba(37, 99, 235, 0.4);
    transform: translateY(-2px);
}

#openIllustrationInline.sensor-illustration-fab:active {
    transform: translateY(0);
}

@media (max-width: 768px) {
    #openIllustrationInline.sensor-illustration-fab {
        right: 16px;
        bottom: 16px;
    }
}

/* Ensure anchored panel content has some top-padding for header overlap */
.image-lightbox.anchored .image-lightbox-body { padding-top: 6px; }

body.mobile-device .card {
    border-radius: 12px;
    padding: 12px;
}

body.mobile-device h1 {
    font-size: 1.15rem;
}

body.mobile-device h2 {
    font-size: 1rem;
}

body.mobile-device .subtitle {
    font-size: 0.92rem;
}

body.mobile-device .actions {
    width: 100%;
}

body.mobile-device .actions .btn,
body.mobile-device .actions input[type="date"],
body.mobile-device .btn {
    width: 100%;
    text-align: center;
}

body.mobile-device .btn {
    padding: 10px 12px;
}

/* mobile table styles removed */

@media (max-width: 768px) {
    .container {
        margin: 12px auto;
        padding: 0 10px;
    }

    .card {
        border-radius: 12px;
        padding: 12px;
    }

    h1 {
        font-size: 1.15rem;
    }

    h2 {
        font-size: 1rem;
    }

    .subtitle {
        font-size: 0.92rem;
    }

    .subtitle-actions-row {
        align-items: stretch;
    }

    .subtitle-actions {
        width: 100%;
        margin-left: 0;
    }

    .devices-sort-control {
        width: 100%;
    }

    .devices-sort-control select {
        flex: 1;
        min-width: 0;
    }

    .device-list-actions {
        width: 100%;
        margin-left: 0;
    }

    .devices-view-toggle {
        width: 100%;
    }

    .devices-view-button {
        flex: 1 1 50%;
    }

    .actions {
        width: 100%;
    }

    .actions .btn,
    .actions input[type="date"] {
        width: 100%;
        text-align: center;
    }

    .btn {
        width: 100%;
        text-align: center;
        padding: 10px 12px;
    }

    /* removed table styles in this media query */
}

@media (max-width: 420px) {
    .container {
        padding: 0 8px;
    }

    .card {
        padding: 10px;
    }

    h1 {
        font-size: 1.02rem;
    }

    .subtitle,
    .muted {
        font-size: 0.82rem;
    }

    .btn,
    input[type="date"] {
        padding: 8px 10px;
    }
}

body.modal-open {
    overflow: hidden;
}

/* Trend arrow styling — make arrows more visible */
.trend-arrow {
    font-weight: 700;
    font-size: 1.25em;
    margin-left: 6px;
    vertical-align: middle;
    line-height: 1;
}

.map-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
}

.map-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
}

.map-modal-panel {
    position: relative;
    z-index: 1;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0;
    background: var(--card);
    border: 0;
    border-radius: 0;
    padding: 14px;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.28);
}

.map-layout {
    position: relative;
    display: block;
    flex: 1;
    min-height: 0;
}

.map-editor-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 20;
    width: min(22vw, 280px);
    min-width: 180px;
    max-width: calc(100% - 20px);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.2);
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    overflow: auto;
    transform: translateX(calc(-100% - 14px));
    transition: transform 0.2s ease;
}

.map-layout.sidebar-open .map-editor-sidebar {
    transform: translateX(0);
}

.map-sidebar-overlay {
    display: none !important;
    pointer-events: none;
}

.map-splitter {
    display: none !important;
}

.map-splitter:hover {
    background: #cbd5e1;
}

.map-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.map-close {
    min-width: 130px;
}

.map-panel-toggle {
    min-width: 120px;
}

.sensor-heatmap-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    padding: 5px 7px;
    border: 1px solid #dbe3ee;
    border-radius: 10px;
    background: #f8fafc;
}

.sensor-heatmap-toggle {
    min-width: 142px;
    white-space: nowrap;
}

.map-averages-toggle {
    min-width: 142px;
    white-space: nowrap;
}

.map-averages-toggle.is-active {
    border-color: #1d4ed8;
    background: #2563eb;
    color: #fff;
}

.sensor-heatmap-toggle.is-active {
    border-color: #dc2626;
    background: linear-gradient(90deg, #2563eb, #06b6d4, #22c55e, #facc15, #dc2626);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

.sensor-heatmap-field {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: #475569;
    font-size: .78rem;
    font-weight: 600;
    white-space: nowrap;
}

.sensor-heatmap-field select {
    width: 82px;
    min-width: 82px;
    padding: 5px 6px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    background: #fff;
}

.sensor-heatmap-simulation {
    position: absolute;
    right: 20px;
    bottom: 150px;
    z-index: 4;
    display: grid;
    gap: 8px;
    width: 280px;
    max-height: calc(100% - 175px);
    overflow: auto;
    padding: 9px 11px;
    border: 1px solid rgba(148, 163, 184, .7);
    border-radius: 10px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 7px 20px rgba(15, 23, 42, .14);
    backdrop-filter: blur(5px);
}

.sensor-heatmap-simulation-settings,
.sensor-heatmap-playback {
    display: grid;
    gap: 9px;
    min-width: 0;
}

.sensor-heatmap-simulation-settings > strong {
    color: #0f172a;
    font-size: .8rem;
    white-space: nowrap;
}

.sensor-heatmap-simulation label,
.sensor-heatmap-date-range {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    color: #475569;
    font-size: .77rem;
    font-weight: 600;
    white-space: nowrap;
}

.sensor-heatmap-date-range {
    display: grid;
    gap: 9px;
}

.sensor-heatmap-simulation select,
.sensor-heatmap-simulation input[type="date"] {
    height: 32px;
    margin: 0;
    padding: 4px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    background: #fff;
    color: #1e293b;
    font: inherit;
}

.sensor-heatmap-simulation-settings > label > select {
    width: 145px;
}

.sensor-heatmap-date-range input[type="date"] {
    width: 170px;
}

.sensor-heatmap-marker-visibility {
    justify-content: flex-start !important;
    padding: 6px 8px;
    border: 1px solid #dbe3ee;
    border-radius: 7px;
    background: #f8fafc;
    cursor: pointer;
}

.sensor-heatmap-marker-visibility input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: #2563eb;
}

.sensor-heatmap-start,
.sensor-heatmap-play,
.sensor-heatmap-live {
    min-height: 32px;
    padding: 5px 11px;
    font-size: .8rem;
    white-space: nowrap;
}

.sensor-heatmap-start {
    width: 100%;
    border-color: #2563eb;
    color: #1d4ed8;
}

.sensor-heatmap-simulation-status {
    color: #64748b;
    font-size: .74rem;
    line-height: 1.3;
}

.sensor-heatmap-simulation-status.is-error {
    color: #b91c1c;
    font-weight: 600;
}

.sensor-heatmap-playback {
    padding-top: 8px;
    border-top: 1px solid #dbe3ee;
}

.sensor-heatmap-playback input[type="range"] {
    width: 100%;
    min-width: 0;
    accent-color: #2563eb;
}

.sensor-heatmap-playback output {
    min-width: 0;
    color: #0f172a;
    font-size: .8rem;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
}

.sensor-heatmap-live {
    width: 100%;
}

.map-controls {
    display: grid;
    gap: 7px;
    margin: 0;
}

.map-controls .btn {
    border-color: #d6dee8;
    border-radius: 8px;
    background: #f8fafc;
    color: #475569;
    padding: 4px 9px;
    font-size: 0.84rem;
    font-weight: 500;
    line-height: 1.15;
    box-shadow: none;
}

.map-controls .btn:hover {
    border-color: #b8c5d4;
    background: #eef2f7;
    color: #1e293b;
}

.map-controls .btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.map-controls input[type="file"]::file-selector-button {
    margin-right: 8px;
    border: 1px solid #d6dee8;
    border-radius: 7px;
    background: #f8fafc;
    color: #475569;
    padding: 4px 8px;
    font-size: 0.84rem;
    cursor: pointer;
}

.map-view-actions {
    margin: 10px 0 0;
}

#toggleMapEdit,
#toggleSensorMapEdit {
    display: block;
    width: 100%;
}

.map-modal [hidden] {
    display: none !important;
}

.map-import-confirm {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: grid;
    place-items: center;
    padding: 20px;
}

.map-import-confirm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.58);
    backdrop-filter: blur(3px);
}

.map-import-confirm-panel {
    position: relative;
    width: min(470px, 100%);
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.38);
    border-radius: 18px;
    background: var(--card);
    box-shadow: 0 28px 70px rgba(15, 23, 42, 0.32);
    animation: mapConfirmIn 0.18s ease-out;
}

@keyframes mapConfirmIn {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.map-import-confirm-content {
    display: flex;
    align-items: flex-start;
    gap: 15px;
    padding: 24px 24px 20px;
}

.map-import-confirm-icon {
    display: grid;
    place-items: center;
    flex: 0 0 48px;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: #e0f2fe;
    color: #0369a1;
}

.map-import-confirm-icon svg {
    width: 27px;
    height: 27px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.map-import-confirm-copy h3 {
    margin: 1px 0 8px;
    color: var(--text);
    font-size: 1.12rem;
    line-height: 1.3;
}

.map-import-confirm-copy p {
    margin: 0;
    color: var(--muted);
    font-size: 0.94rem;
    line-height: 1.55;
}

.map-import-confirm-note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 14px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #ecfdf5;
    color: #166534;
    font-size: 0.88rem;
    line-height: 1.4;
}

.map-import-confirm-note span {
    display: grid;
    place-items: center;
    flex: 0 0 19px;
    width: 19px;
    height: 19px;
    border-radius: 50%;
    background: #bbf7d0;
    font-size: 0.75rem;
    font-weight: 800;
}

.map-import-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 9px;
    padding: 14px 24px;
    border-top: 1px solid var(--line);
    background: #f8fafc;
}

.map-import-confirm-actions .btn {
    min-width: 112px;
    padding: 9px 16px;
    font-weight: 600;
}

.map-import-confirm-primary {
    box-shadow: 0 5px 14px rgba(37, 99, 235, 0.2);
}

@media (max-width: 520px) {
    .map-import-confirm {
        padding: 14px;
    }

    .map-import-confirm-content {
        padding: 20px 18px 16px;
    }

    .map-import-confirm-icon {
        flex-basis: 42px;
        width: 42px;
        height: 42px;
        border-radius: 12px;
    }

    .map-import-confirm-actions {
        padding: 12px 18px;
    }

    .map-import-confirm-actions .btn {
        flex: 1;
        min-width: 0;
    }
}

.map-controls label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.map-controls input[type="file"],
.map-controls select {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px 10px;
    background: #fff;
    color: var(--text);
}

.map-controls input[type="range"] {
    width: 100%;
}

.map-controls input[type="color"] {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 4px;
    background: #fff;
    width: 72px;
    height: 40px;
}

.map-tool-section {
    display: grid;
    gap: 7px;
    margin: 0;
    padding: 9px;
    border: 1px solid #d6dee8;
    border-left: 3px solid var(--map-section-accent, #94a3b8);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.68);
}

.map-tool-section legend {
    padding: 0 6px;
    font-weight: 700;
    color: #334155;
    font-size: 0.88rem;
}

.map-background-tools {
    --map-section-accent: #64748b;
}

.map-label-tools {
    --map-section-accent: #2563eb;
}

.map-drawing-tools {
    --map-section-accent: #d97706;
}

.map-tool-divider {
    height: 1px;
    margin: 3px 2px;
    background: #b8c3d1;
}

.map-tool-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
}

.map-drawing-color-row,
.map-drawing-size-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.map-drawing-size-row > label {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.map-drawing-tools input[type="number"] {
    width: 100%;
}

.map-canvas-wrap {
    position: relative;
    min-height: 0;
    border: 1px dashed var(--line);
    border-radius: 12px;
    padding: 8px;
    background: #f8fafc;
    overflow: auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.map-canvas-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    flex: 0 0 auto;
}

.map-canvas-stage > img {
    position: relative;
    z-index: 0;
}

.map-heatmap-layer {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 8px;
    pointer-events: none;
    mix-blend-mode: normal;
    image-rendering: auto;
}

.map-heatmap-tooltip {
    position: absolute;
    z-index: 40;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-width: max-content;
    padding: 6px 9px;
    border: 1px solid rgba(15, 23, 42, .22);
    border-radius: 8px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 5px 16px rgba(15, 23, 42, .2);
    color: #0f172a;
    font-size: .76rem;
    font-weight: 700;
    line-height: 1.15;
    white-space: nowrap;
    pointer-events: none;
    transform: translate(12px, 12px);
}

.map-heatmap-tooltip[hidden] {
    display: none;
}

.map-heatmap-tooltip::before {
    content: '';
    flex: 0 0 11px;
    width: 11px;
    height: 11px;
    border: 1px solid rgba(15, 23, 42, .2);
    border-radius: 50%;
    background: var(--heatmap-tooltip-color, #94a3b8);
}

.map-markers .map-marker-sensor {
    z-index: 20;
}

.map-markers .map-marker {
    transition: filter .18s ease;
}

.map-markers.is-heatmap-active .map-marker {
    z-index: 20;
    filter: opacity(.62);
}

.map-markers.is-heatmap-markers-hidden .map-marker {
    visibility: hidden;
    pointer-events: none;
}

.map-canvas-stage.is-blank {
    width: min(1200px, 100%);
    height: min(760px, 100%);
    min-width: 600px;
    min-height: 460px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background-color: #fff;
    background-image:
        linear-gradient(#eef2f7 1px, transparent 1px),
        linear-gradient(90deg, #eef2f7 1px, transparent 1px);
    background-size: 25px 25px;
}

.map-placeholder {
    position: absolute;
    z-index: 3;
    pointer-events: none;
    color: var(--muted);
    text-align: center;
    padding: 30px 10px;
}

.map-loading {
    position: absolute;
    inset: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(248, 250, 252, 0.88);
    color: var(--muted);
    border-radius: 8px;
    z-index: 4;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 600ms ease, visibility 600ms ease;
}

.map-loading.is-visible {
    opacity: 1;
    visibility: visible;
}

.map-loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #dbeafe;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: map-loading-spin 0.8s linear infinite;
}

@keyframes map-loading-spin {
    to {
        transform: rotate(360deg);
    }
}

#mapImage {
    display: block;
    width: auto;
    max-width: none;
    height: auto;
    border-radius: 8px;
    user-select: none;
}

.map-markers {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.sensor-heatmap-legend {
    position: absolute;
    right: 20px;
    bottom: 20px;
    z-index: 3;
    width: 280px;
    padding: 10px 12px;
    border: 1px solid rgba(148, 163, 184, .7);
    border-radius: 10px;
    background: rgba(255, 255, 255, .92);
    box-shadow: 0 7px 20px rgba(15, 23, 42, .14);
    color: #0f172a;
    pointer-events: none;
    backdrop-filter: blur(5px);
}

.sensor-heatmap-legend-title {
    margin-bottom: 6px;
    font-size: .8rem;
    font-weight: 700;
}

.sensor-heatmap-legend-scale {
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(90deg, #2563eb 0%, #06b6d4 25%, #22c55e 50%, #facc15 75%, #dc2626 100%);
}

.sensor-heatmap-legend-values {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: .75rem;
    font-weight: 700;
}

.sensor-heatmap-legend-note {
    margin-top: 4px;
    color: #64748b;
    font-size: .68rem;
    line-height: 1.25;
}

@media (max-width: 900px) {
    .sensor-heatmap-controls {
        order: 4;
        width: 100%;
        margin-left: 0;
        flex-wrap: wrap;
    }

    .sensor-heatmap-simulation {
        right: 14px;
        bottom: 138px;
        width: min(260px, calc(100% - 28px));
        max-height: calc(100% - 158px);
        padding: 8px;
    }

    .sensor-heatmap-simulation-settings > strong,
    .sensor-heatmap-simulation-status {
        width: auto;
    }

    .sensor-heatmap-date-range {
        width: 100%;
        flex-wrap: wrap;
    }

    .sensor-heatmap-playback input[type="range"] {
        width: 100%;
    }

    .sensor-heatmap-live {
        width: 100%;
    }

    .sensor-heatmap-legend {
        right: 14px;
        bottom: 14px;
        width: min(260px, calc(100% - 28px));
    }
}

.map-drawing-shape {
    position: absolute;
    z-index: 0;
    box-sizing: border-box;
    transform: translate(-50%, -50%);
    border-style: solid;
    border-width: 2px;
    pointer-events: auto;
    cursor: move;
    touch-action: none;
}

.map-drawing-shape.shape-rectangle {
    border-radius: 3px;
}

.map-drawing-shape.shape-circle {
    border-radius: 50%;
}

.map-drawing-shape.shape-text {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    padding: 0;
    border: 0;
    background: transparent !important;
}

.map-plan-text {
    max-width: 100%;
    font-size: clamp(13px, 1.15rem, 24px);
    font-weight: 700;
    line-height: 1.2;
    overflow-wrap: anywhere;
    text-align: center;
}

.map-drawing-shape.shape-triangle,
.map-drawing-shape.shape-line {
    overflow: visible;
    border: 0;
    background: transparent !important;
}

.map-cad-symbol {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.map-cad-symbol path,
.map-cad-symbol circle {
    fill: none;
    stroke: currentColor;
    vector-effect: non-scaling-stroke;
}

.map-cad-symbol .cad-line {
    stroke-width: 3;
}

.map-cad-symbol .map-shape-polygon {
    stroke-width: 2;
}

.map-drawing-shape.is-selected {
    outline: 3px dashed #0f172a;
    outline-offset: 3px;
}

.map-drawing-resize-handle {
    position: absolute;
    right: -17px;
    bottom: -12px;
    z-index: 2;
    display: none;
    width: 34px;
    height: 24px;
    border: 0;
    background: transparent;
    cursor: nwse-resize;
    touch-action: none;
}

.map-drawing-resize-handle::before {
    content: '↖↘';
    display: block;
    color: #0f172a;
    font-size: 19px;
    font-weight: 900;
    line-height: 24px;
    letter-spacing: -4px;
    text-align: center;
    text-shadow:
        -1px -1px 0 #fff,
        1px -1px 0 #fff,
        -1px 1px 0 #fff,
        1px 1px 0 #fff;
}

.map-canvas-stage.is-edit-mode .map-drawing-shape.is-selected .map-drawing-resize-handle {
    display: block;
}

.map-canvas-stage:not(.is-edit-mode) .map-drawing-shape {
    pointer-events: none;
}

.map-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    border: 1px solid var(--primary);
    background: rgba(37, 99, 235, 0.92);
    color: #fff;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 0.78rem;
    white-space: nowrap;
    pointer-events: auto;
    cursor: grab;
    touch-action: none;
    z-index: 2;
}

.map-marker.is-dragging {
    cursor: grabbing;
    opacity: 0.9;
}

.map-marker-sensor {
    z-index: 1;
    border-radius: 12px;
    min-width: 0;
    max-width: none;
    padding: 8px 10px;
    text-align: center;
    white-space: normal;
    line-height: 1.2;
    box-sizing: border-box;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.map-marker-object.has-temperature-averages {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
    box-sizing: border-box;
    overflow: hidden;
    text-align: center;
    white-space: normal;
}

.map-object-marker-title {
    display: block;
    max-width: 100%;
    overflow: hidden;
    font-size: .9em;
    font-weight: 700;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.map-object-marker-averages {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
}

.map-object-marker-average {
    display: grid;
    gap: 3px;
    min-width: 0;
    line-height: 1;
}

.map-object-marker-average + .map-object-marker-average {
    border-left: 1px solid rgba(255, 255, 255, .4);
}

.map-object-marker-average > span {
    font-size: .68em;
    font-weight: 700;
    letter-spacing: .06em;
    opacity: .82;
}

.map-object-marker-average > strong {
    overflow: hidden;
    font-size: 1.05em;
    font-weight: 800;
    letter-spacing: -.02em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.map-marker[class*="shape-cloud-"] {
    overflow: visible;
    border-radius: 16px !important;
    z-index: 1;
    isolation: isolate;
}

.map-marker[class*="shape-cloud-"]::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: inherit;
    pointer-events: none;
    z-index: -1;
}

.map-marker.shape-cloud-bottom::after {
    left: 50%;
    bottom: -10px;
    transform: translateX(-50%) rotate(45deg);
    border-left: inherit;
    border-bottom: inherit;
    border-top: 0;
    border-right: 0;
}

.map-marker.shape-cloud-top::after {
    left: 50%;
    top: -10px;
    transform: translateX(-50%) rotate(45deg);
    border-right: inherit;
    border-top: inherit;
    border-left: 0;
    border-bottom: 0;
}

.map-marker.shape-cloud-left::after {
    left: -10px;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
    border-left: inherit;
    border-top: inherit;
    border-right: 0;
    border-bottom: 0;
}

.map-marker.shape-cloud-right::after {
    right: -10px;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
    border-right: inherit;
    border-bottom: inherit;
    border-left: 0;
    border-top: 0;
}

.map-marker.map-marker-sensor[class*="shape-cloud-"] {
    overflow: visible;
}

.map-marker.map-marker-sensor.shape-pin {
    overflow: visible;
    isolation: isolate;
    border-width: 1px;
    border-radius: 14px !important;
    transform-origin: 50% calc(100% + 31px);
    box-shadow: 0 8px 20px rgba(15, 23, 42, .22), inset 0 1px 0 rgba(255, 255, 255, .2);
}

.map-marker.map-marker-sensor.shape-pin::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -28px;
    z-index: -1;
    width: 3px;
    height: 28px;
    border-radius: 0 0 999px 999px;
    background: #475569;
    box-shadow: 0 1px 2px rgba(255, 255, 255, .55);
    pointer-events: none;
    transform: translateX(-50%);
}

.map-marker.map-marker-sensor.shape-pin::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -36px;
    z-index: 1;
    box-sizing: border-box;
    width: 11px;
    height: 11px;
    border: 3px solid rgba(255, 255, 255, .96);
    border-radius: 50%;
    background: inherit;
    box-shadow: 0 0 0 2px #475569, 0 3px 7px rgba(15, 23, 42, .3);
    pointer-events: none;
    transform: translateX(-50%);
}

.sensor-pin-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    min-width: 0;
    font-size: .9em;
    font-weight: 700;
}

.sensor-pin-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sensor-pin-status {
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    border: 2px solid rgba(255, 255, 255, .85);
    border-radius: 50%;
    background: #94a3b8;
    box-shadow: 0 0 0 2px rgba(15, 23, 42, .14);
}

.sensor-pin-status.is-active {
    background: #22c55e;
}

.sensor-pin-temperatures {
    display: grid;
    gap: 2px;
    width: 100%;
    margin: 4px 0 3px;
}

.sensor-pin-temperature {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    font-size: 1.45em;
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -.02em;
    white-space: nowrap;
}

.sensor-pin-channel {
    font-size: .58em;
    font-weight: 800;
    letter-spacing: .02em;
    opacity: .82;
}

.sensor-pin-value {
    white-space: nowrap;
}

.map-marker.map-marker-sensor .trend-arrow {
    color: #fff !important;
}

.sensor-pin-battery {
    display: block;
    width: 100%;
    font-size: .72em;
    line-height: 1.1;
    white-space: nowrap;
}

.sensor-pin-meta {
    position: absolute;
    left: 50%;
    top: -8px;
    z-index: 3;
    padding: 5px 8px;
    border: 1px solid rgba(148, 163, 184, .55);
    border-radius: 7px;
    background: rgba(255, 255, 255, .97);
    box-shadow: 0 6px 16px rgba(15, 23, 42, .18);
    color: #0f172a;
    font-size: .72em;
    font-weight: 700;
    line-height: 1;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, calc(-100% + 4px));
    transition: opacity .16s ease, transform .16s ease;
    white-space: nowrap;
}

.map-marker.map-marker-sensor.shape-pin:hover .sensor-pin-meta,
.map-marker.map-marker-sensor.shape-pin:focus-visible .sensor-pin-meta {
    opacity: 1;
    transform: translate(-50%, -100%);
}

.map-marker.map-marker-sensor.shape-capsule {
    flex-direction: row;
    justify-content: center;
    gap: 8px;
    overflow: hidden;
    border-radius: 999px !important;
    padding-left: 16px !important;
    padding-right: 16px !important;
    line-height: 1;
    white-space: nowrap;
    box-shadow: 0 7px 18px rgba(15, 23, 42, .2), inset 0 1px 0 rgba(255, 255, 255, .2);
}

.sensor-capsule-status {
    width: 9px;
    height: 9px;
}

.sensor-capsule-title {
    min-width: 0;
    max-width: 86px;
    overflow: hidden;
    font-size: .78em;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sensor-capsule-divider {
    align-self: stretch;
    width: 1px;
    min-height: 24px;
    background: rgba(255, 255, 255, .42);
}

.sensor-capsule-reading {
    font-size: 1.02em;
    font-weight: 800;
    letter-spacing: -.02em;
}

.sensor-capsule-channel {
    font-size: .62em;
    opacity: .78;
}

.sensor-capsule-battery {
    font-size: .68em;
    opacity: .92;
}

.map-marker[class*="shape-flag-"] {
    overflow: visible;
    z-index: 1;
    isolation: isolate;
    border-radius: 2px !important;
}

.map-marker[class*="shape-flag-"]::before {
    content: '';
    position: absolute;
    pointer-events: none;
    z-index: -1;
    top: 0;
    width: 4px;
    height: calc(100% + 56px);
    background: #374151;
    border-radius: 2px;
}

.map-marker[class*="shape-flag-"]::after {
    content: '';
    position: absolute;
    pointer-events: none;
    z-index: -1;
    width: 8px;
    height: 8px;
    background: #374151;
    border-radius: 50%;
    top: calc(100% + 54px);
}

.map-marker.shape-flag-right::before {
    left: -4px;
}

.map-marker.shape-flag-right::after {
    left: -6px;
}

.map-marker.shape-flag-left::before {
    right: -4px;
}

.map-marker.shape-flag-left::after {
    right: -6px;
}

.sensor-marker-title {
    display: block;
    font-weight: 700;
    font-size: 1.02em;
    margin-bottom: 2px;
}

.sensor-marker-row {
    display: block;
    font-size: 0.9em;
    word-break: break-word;
}

.sensor-marker-time {
    font-size: 0.86em;
    opacity: 0.9;
    margin-top: 2px;
}

.marker-context-menu {
    position: fixed;
    z-index: 1200;
    min-width: 150px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.22);
    padding: 6px;
}

.marker-context-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--muted);
    padding: 6px 8px 8px;
    cursor: move;
    user-select: none;
}

.marker-context-close {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    border-radius: 8px;
    width: 24px;
    height: 24px;
    line-height: 1;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

.marker-context-close:hover {
    background: #f1f5f9;
}

.marker-menu-fields {
    display: grid;
    grid-template-columns: auto auto;
    gap: 6px;
    margin-bottom: 6px;
}

.marker-menu-fields label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--muted);
}

.marker-menu-fields input[type="color"],
.marker-menu-fields select,
.marker-menu-fields input[type="number"] {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
}

.marker-menu-fields input[type="color"] {
    width: 46px;
    height: 28px;
    padding: 2px;
}

.marker-menu-fields select {
    padding: 5px 8px;
}

.marker-menu-fields input[type="number"] {
    padding: 4px 6px;
    width: 62px;
}

.marker-menu-item {
    width: 100%;
    text-align: left;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
}

.marker-menu-item:hover {
    background: #f1f5f9;
}

.marker-menu-item.danger {
    color: #b91c1c;
}

#markerContextMenu {
    min-width: 0;
    width: 250px;
}

#markerContextMenu .marker-menu-fields {
    gap: 5px;
}

#markerContextMenu .marker-menu-fields label {
    font-size: 0.76rem;
}

#markerContextMenu .marker-menu-fields input[type="number"] {
    width: 58px;
}

#sensorMarkerContextMenu {
    min-width: 0;
    width: 250px;
}

#sensorMarkerContextMenu .marker-menu-fields {
    gap: 5px;
}

#sensorMarkerContextMenu .marker-menu-fields label {
    font-size: 0.76rem;
}

#sensorMarkerContextMenu .marker-menu-fields input[type="number"] {
    width: 58px;
}

@media (max-width: 768px) {
    .map-layout {
        display: block;
    }

    .map-splitter {
        display: none;
    }

    .map-editor-sidebar {
        width: min(80vw, 300px);
        min-width: 0;
    }

    .map-controls {
        gap: 8px;
    }

    .map-controls label,
    .map-close {
        width: 100%;
    }

    .map-modal-panel {
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        max-height: 100vh;
        margin: 0;
        padding: 12px;
    }
}

/* ===== Info icon button ===== */
.btn-info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--primary);
    padding: 4px;
    border-radius: 50%;
    vertical-align: middle;
    margin-left: 6px;
    transition: background 0.15s, color 0.15s;
}

.btn-info-icon:hover {
    background: var(--primary);
    color: #fff;
}

/* ===== Device info popup ===== */
.device-info-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.device-info-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.device-info-popup {
    position: relative;
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    width: min(420px, 92vw);
    max-height: 80vh;
    overflow-y: auto;
    animation: diPopIn 0.2s ease-out;
}

@keyframes diPopIn {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

.device-info-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--line);
}

.device-info-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text);
}

.device-info-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--muted);
    line-height: 1;
    padding: 0 4px;
}

.device-info-close:hover {
    color: var(--text);
}

.device-info-body {
    padding: 16px 20px 20px;
}

/* Fullscreen override for combined chart modal */
#combinedChartOverlay {
    align-items: stretch;
    justify-content: stretch;
}
#combinedChartOverlay .device-info-popup {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    padding: 0;
    margin: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    background: var(--card);
}
#combinedChartOverlay .device-info-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}
#combinedChartOverlay .device-info-body {
    padding: 10px;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* chart will manage its own scrolling/resizing */
}

/* Ensure chart-box inside fullscreen modal fills remaining space */
#combinedChartOverlay .chart-box {
    flex: 1 1 auto;
    padding: 8px;
    min-height: 0; /* allow flex child to shrink to available space */
}

/* Make canvas fill its container height */
#combinedChartOverlay .chart-box canvas,
#combinedChartOverlay canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.device-info-table {
    width: 100%;
    border-collapse: collapse;
}

.device-info-table th,
.device-info-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    font-size: 0.95rem;
}

.device-info-table th {
    color: var(--muted);
    font-weight: 500;
    width: 45%;
    white-space: nowrap;
}

.device-info-table td {
    color: var(--text);
    word-break: break-word;
}

.device-info-table tr:last-child th,
.device-info-table tr:last-child td {
    border-bottom: none;
}

/* Table header / cloned header styles removed. */

/* Compact temperature summary boxes and position period selector to their right */
/* Target the grid of small temp boxes (the first grid after an hr) */
hr + div[style*="display: grid"] {
    display: flex !important;
    flex-wrap: wrap;
    gap: 10px;
    padding: 0 15px;
    align-items: center; /* vertically center boxes */
    justify-content: flex-start; /* keep boxes aligned side-by-side */
}
hr + div[style*="display: grid"] > div {
    padding: 8px 10px !important;
    font-size: 0.88rem !important;
    border-radius: 8px !important;
    flex: 0 0 auto;
    min-width: 120px;
    max-width: 220px;
}

/* Place the moved period form to the right inside the .temp-controls-row */
#periodForm {
    margin-left: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 12px;
    justify-content: flex-end; /* align form to right on wide screens */
}
/* ensure the date controls inside the form align nicely */
#dateRangeControls {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Slightly reduce input sizes inside the small boxes */
hr + div[style*="display: grid"] strong {
    font-size: 0.98rem;
}
hr + div[style*="display: grid"] div {
    font-size: 0.88rem;
}

/* Temp box grid layout (2 columns x 2 rows) */
.temp-box {
    box-sizing: border-box;
}
.temp-box .temp-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    align-items: center;
}
.temp-box .temp-grid div {
    white-space: nowrap;
}
.temp-box.temp1 { /* optional fine-tuning */ }
.temp-box.temp2 { /* optional fine-tuning */ }

/* Responsiveness: on small screens, restore normal flow */
@media (max-width: 800px) {
    #periodForm {
        margin-left: 0;
        justify-content: flex-start;
        padding: 0 15px;
    }
    hr + div[style*="display: grid"] {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }
}
@media (max-width: 1100px) {
    /* keep selector inline on narrower layouts */
    #periodSelect,
    #dateRangeControls {
        position: static;
        right: auto;
        top: auto;
    }
}

/* Generic modal used for addDeviceModal */
.modal {
    position: fixed;
    inset: 0;
    display: none; /* JS toggles inline style */
    align-items: center;
    justify-content: center;
    z-index: 1200;
}
.modal .modal-content {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 18px 50px rgba(15,23,42,0.28);
    width: 100%;
    max-width: 520px;
    margin: 16px;
    border: 1px solid var(--line);
    overflow: hidden;
}
.modal .modal-header {
    display:flex;
    align-items:center;
    justify-content:space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}
.modal .modal-body { padding: 14px 16px; }
.modal .modal-footer { padding: 12px 16px; display:flex; justify-content:flex-end; gap:8px; border-top:1px solid var(--line); }
.modal .modal-close { background: none; border: none; font-size: 20px; cursor: pointer; }




.device-status {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    margin-left: 0.45em;
    padding: 0.16em 0.55em;
    border-radius: 999px;
    font-size: 0.78em;
    font-weight: 700;
    line-height: 1.4;
    vertical-align: middle;
    background: #f1f5f9;
    color: #64748b;
}

.device-status-dot {
    width: 0.58em;
    height: 0.58em;
    border-radius: 50%;
    background: currentColor;
}

.device-status--online {
    background: #dcfce7;
    color: #15803d;
}

.device-status--offline {
    background: #fee2e2;
    color: #b91c1c;
}

.device-status--never {
    background: #f1f5f9;
    color: #64748b;
}

.stale-data-badge {
    display: inline-flex;
    align-items: center;
    margin-left: 0.45em;
    padding: 0.16em 0.55em;
    border-radius: 999px;
    background: #fff2d5;
    color: #a16207;
    font-size: 0.78em;
    font-weight: 600;
    line-height: 1.4;
    vertical-align: middle;
    white-space: nowrap;
}
