:root {
    --app-bg: #060b1a;
    --app-bg-2: #0b1530;
    --text-main: #d7e8ff;
    --text-sub: #8ea8cc;
    --line: rgba(111, 157, 255, 0.22);
    --card-bg: rgba(10, 20, 44, 0.78);
    --card-shadow: 0 20px 48px rgba(2, 8, 30, 0.45);
    --accent: #53a4ff;
    --accent-2: #6b7bff;
}

html,
body {
    color: var(--text-main);
    background: radial-gradient(circle at 12% 10%, #11396f 0%, transparent 30%),
                radial-gradient(circle at 82% 18%, #2c2b7a 0%, transparent 32%),
                linear-gradient(145deg, var(--app-bg) 0%, var(--app-bg-2) 70%);
    min-height: 100%;
}

body {
    position: relative;
    overflow-x: hidden;
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-main {
    flex: 1 0 auto;
}

.app-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--line);
    background: rgba(8, 19, 42, 0.72);
    backdrop-filter: blur(10px);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: linear-gradient(rgba(83, 164, 255, 0.05) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(83, 164, 255, 0.05) 1px, transparent 1px);
    background-size: 36px 36px;
    pointer-events: none;
    z-index: 0;
}

main,
.navbar {
    position: relative;
    z-index: 1;
}

.app-navbar {
    backdrop-filter: blur(14px);
    background: linear-gradient(90deg, rgba(8, 22, 52, 0.92), rgba(13, 33, 73, 0.92)) !important;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

.app-brand {
    font-weight: 700;
    letter-spacing: 0.6px;
    color: #e8f1ff !important;
}

.nav-link {
    color: #bdd6ff !important;
}

.nav-link.active {
    color: #ffffff !important;
    text-shadow: 0 0 12px rgba(83, 164, 255, 0.8);
}

.app-card {
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    box-shadow: var(--card-shadow);
}

.app-card .card-header {
    background: linear-gradient(90deg, rgba(83, 164, 255, 0.16), rgba(107, 123, 255, 0.12));
    border-bottom: 1px solid var(--line);
    font-weight: 600;
    color: #e6f2ff;
}

.page-wrap {
    max-width: 1320px;
}

.badge-soft {
    background: rgba(83, 164, 255, 0.22);
    color: #e0ecff;
    border: 1px solid rgba(83, 164, 255, 0.45);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 12px;
}

.form-label,
.small {
    color: #a8c4e4 !important;
}

.text-secondary {
    color: #90afd0 !important;
}

.form-control,
.form-select {
    background: rgba(8, 19, 42, 0.85);
    color: #e0ecff;
    border: 1px solid rgba(83, 164, 255, 0.35);
}

.form-control::placeholder {
    color: rgba(160, 190, 230, 0.5);
}

.form-control:focus,
.form-select:focus {
    background: rgba(10, 25, 56, 0.95);
    color: #eef4ff;
    border-color: rgba(83, 164, 255, 0.85);
    box-shadow: 0 0 0 0.2rem rgba(83, 164, 255, 0.25);
}

.form-control:disabled,
.form-control[readonly] {
    background: rgba(8, 19, 42, 0.6);
    color: #a0bce6;
}

.btn-primary {
    border: none;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    box-shadow: 0 8px 20px rgba(83, 164, 255, 0.35);
}

.btn-outline-primary,
.btn-outline-light,
.btn-outline-danger {
    border-width: 1px;
}

.btn-outline-primary {
    color: #9ec8ff;
    border-color: rgba(83, 164, 255, 0.7);
}

.btn-outline-primary:hover {
    color: #ffffff;
    background: rgba(83, 164, 255, 0.22);
    border-color: rgba(83, 164, 255, 0.9);
}

.table {
    color: #e0ecff;
    margin-bottom: 0;
    --bs-table-bg: transparent;
    --bs-table-color: #e0ecff;
    --bs-table-hover-bg: rgba(83, 164, 255, 0.10);
    --bs-table-hover-color: #e8f2ff;
}

.table > :not(caption) > * > * {
    background-color: rgba(8, 18, 42, 0.65);
    color: #e0ecff;
    border-bottom-color: rgba(83, 164, 255, 0.18);
}

.table thead th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #a3c4e8;
    background: rgba(11, 27, 58, 0.95) !important;
    border-bottom: 1px solid var(--line);
}

.code-cell {
    max-width: 640px;
    white-space: normal;
    word-break: break-all;
    font-size: 12px;
    color: #b6d3ff;
}

.alert-warning {
    color: #fff0c8;
    background: rgba(100, 70, 10, 0.62);
    border-color: rgba(255, 197, 84, 0.4);
}

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 460px;
}

.device-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-right: 12px;
    margin-bottom: 8px;
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid rgba(83, 164, 255, 0.25);
    background: rgba(10, 24, 52, 0.55);
    color: #e0ecff;
}

.device-item span {
    color: #e0ecff;
}

.device-item .text-secondary {
    color: #90b8e0 !important;
}

.form-check-label {
    color: #e0ecff;
}

.column-checkbox + span,
.device-checkbox + span {
    color: #e0ecff;
}

.table-responsive,
canvas {
    border-radius: 12px;
}

.export-col-item {
    border: 1px solid rgba(83, 164, 255, 0.25);
    border-radius: 8px;
    padding: 8px 10px;
    background: rgba(10, 24, 52, 0.55);
    color: #e0ecff;
    cursor: pointer;
}

.export-col-item:hover {
    background: rgba(83, 164, 255, 0.12);
    border-color: rgba(83, 164, 255, 0.5);
}

@media (max-width: 768px) {
    .page-wrap {
        padding: 0 8px;
    }

    .stat-time-value {
        font-size: 24px;
    }
}

.stat-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px 20px;
    background: rgba(15, 30, 60, 0.7);
}

.stat-label {
    font-size: 13px;
    color: var(--text-sub);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
}

.stat-value.online-value {
    color: #34d399;
}

.stat-time-value {
    font-size: 32px;
    font-weight: 700;
    line-height: 1.2;
    color: #cfe3ff;
}

.dashboard-hero {
    overflow: hidden;
}

.map-stage-wrap {
    position: relative;
}

.map-stage {
    width: 100%;
    min-height: 620px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: radial-gradient(circle at top, rgba(83, 164, 255, 0.15), rgba(8, 18, 42, 0.92));
}

.map-reset-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10;
    backdrop-filter: blur(6px);
    background: rgba(8, 19, 42, 0.6);
    border-color: rgba(160, 190, 230, 0.6);
}

.map-reset-btn:hover {
    background: rgba(83, 164, 255, 0.22);
}

.map-device-menu {
    position: absolute;
    z-index: 20;
    min-width: 220px;
    max-width: 320px;
    background: rgba(8, 19, 42, 0.95);
    border: 1px solid rgba(160, 190, 230, 0.45);
    border-radius: 10px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.38);
    padding: 10px;
}

.map-device-menu-title {
    font-size: 12px;
    color: #c6daf7;
}

.map-device-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.map-device-menu-close {
    border: 1px solid rgba(160, 190, 230, 0.45);
    background: rgba(255, 255, 255, 0.06);
    color: #e8f2ff;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    line-height: 1;
    font-size: 16px;
    padding: 0;
}

.map-device-menu-close:hover {
    background: rgba(83, 164, 255, 0.22);
}

.map-device-menu-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.map-device-menu-item {
    width: 100%;
    border: 1px solid rgba(83, 164, 255, 0.45);
    border-radius: 8px;
    background: rgba(83, 164, 255, 0.12);
    color: #ffffff;
    padding: 6px 8px;
    text-align: left;
    font-size: 13px;
}

.map-device-menu-item:hover {
    background: rgba(83, 164, 255, 0.25);
}

.device-detail-panel {
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(10, 20, 44, 0.62);
    padding: 18px;
    box-shadow: var(--card-shadow);
}

.device-detail-panel,
.device-detail-panel .small,
.device-detail-panel .text-secondary,
.device-detail-panel .detail-item,
.device-detail-panel .detail-item span:first-child,
.device-detail-panel .detail-item span:last-child,
.device-detail-panel .form-check-label,
.device-detail-panel .h4,
.device-detail-panel .h6 {
    color: #ffffff !important;
}

.detail-notes-block {
    align-items: flex-start;
}

.detail-notes-wrap {
    padding: 10px 0;
}

.device-notes-modal .modal-content {
    background: rgba(8, 19, 42, 0.98);
    border: 1px solid rgba(83, 164, 255, 0.28);
    box-shadow: var(--card-shadow);
    color: #ffffff;
}

.device-notes-modal .modal-header,
.device-notes-modal .modal-footer {
    border-color: rgba(83, 164, 255, 0.16);
}

.device-notes-modal .btn-close {
    filter: invert(1) grayscale(100%);
    opacity: 0.8;
}

.device-metric-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.metric-card {
    border: 1px solid rgba(83, 164, 255, 0.22);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(10, 24, 52, 0.9), rgba(8, 18, 42, 0.7));
    padding: 14px 16px;
    min-height: 88px;
}

.metric-label {
    font-size: 13px;
    color: #9cb8db;
    margin-bottom: 10px;
}

.metric-value-wrap {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.metric-value {
    font-size: 28px;
    font-weight: 700;
    color: #ffffff;
    line-height: 1;
}

.metric-unit {
    font-size: 13px;
    color: #9cb8db;
}

.detail-notes-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.detail-note-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.16);
}

.detail-note-row:last-child {
    border-bottom: none;
}

.detail-note-row span:first-child {
    color: #d8e7fb;
    flex-shrink: 0;
}

.detail-note-row span:last-child {
    text-align: right;
    word-break: break-word;
    color: #ffffff;
}

.trend-chart-wrap {
    min-height: 320px;
}

.trend-chart-wrap canvas {
    width: 100% !important;
    height: 320px !important;
}

.trend-metric-select {
    min-width: 160px;
    max-width: 240px;
}

.device-filter-scroll {
    max-height: 280px;
    overflow-y: auto;
    padding-right: 4px;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px dashed rgba(83, 164, 255, 0.14);
}

.detail-notes-block {
    align-items: center;
}

.detail-item span:first-child {
    color: var(--text-sub);
    flex-shrink: 0;
}

.detail-relay-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.relay-switch-item {
    border: 1px solid rgba(83, 164, 255, 0.24);
    border-radius: 12px;
    background: rgba(8, 18, 42, 0.68);
    padding: 10px 12px;
}

.relay-switch-item .form-check-input {
    cursor: pointer;
}

.relay-switch-item .form-check-input:disabled {
    cursor: not-allowed;
}

.device-location-card {
    background: rgba(10, 20, 44, 0.56);
    border: 1px solid rgba(83, 164, 255, 0.22);
}

.map-stage .echarts-tooltip {
    max-width: 320px;
}

@media (max-width: 991px) {
    .device-metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 576px) {
    .device-metric-grid {
        grid-template-columns: 1fr;
    }

    .metric-value {
        font-size: 24px;
    }
}

.device-item-wrap {
    margin-bottom: 8px;
}

/* Device notes tooltip */
.device-item-wrap {
    position: relative;
    display: inline-block;
}

.device-notes-tooltip {
    display: none;
    position: absolute;
    left: 0;
    bottom: 100%;
    z-index: 9999;
    min-width: 320px;
    max-width: 420px;
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: rgba(8, 18, 42, 0.96);
    backdrop-filter: blur(16px);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
    color: var(--text-main);
    font-size: 13px;
    line-height: 1.7;
}

.device-item-wrap:hover .device-notes-tooltip {
    display: block;
}

.notes-tooltip-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--line);
}

.notes-tooltip-header strong {
    color: #e6f2ff;
}

.notes-tooltip-body .notes-row {
    padding: 1px 0;
}

.notes-label {
    color: var(--text-sub);
    margin-right: 4px;
}
