@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
    --primary-color: #0f766e;
    --secondary-color: #0b4f6c;
    --success-color: #1d9a6c;
    --warning-color: #d97706;
    --danger-color: #cc3f2f;
    --info-color: #1c7ed6;
    --dark-bg: #11181f;
    --darker-bg: #0b1118;
    --card-bg: rgba(17, 24, 33, 0.88);
    --border-color: rgba(138, 155, 173, 0.22);
    --text-primary: #f6f8fb;
    --text-secondary: #dce3eb;
    --text-muted: #a0adba;
    --sidebar-width: 292px;
    --header-height: 68px;
    --border-radius: 14px;
    --shadow-sm: 0 3px 10px rgba(0, 0, 0, 0.22);
    --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.26);
}

html,
body {
    font-family: "Manrope", "Segoe UI", sans-serif;
    text-rendering: geometricPrecision;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background:
        radial-gradient(1100px 600px at 95% -10%, rgba(28, 126, 214, 0.2) 0%, rgba(28, 126, 214, 0) 55%),
        radial-gradient(900px 540px at 0% 100%, rgba(15, 118, 110, 0.24) 0%, rgba(15, 118, 110, 0) 60%),
        linear-gradient(180deg, #0b1118 0%, #0f171f 55%, #0b1118 100%);
}

.admin-layout {
    background: transparent;
}

.sidebar {
    width: var(--sidebar-width);
    border-right: 1px solid var(--border-color);
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.3);
}

.sidebar.collapsed {
    width: 76px;
}

.sidebar.collapsed .sidebar-header {
    padding: 0.75rem 0.4rem;
    justify-content: center;
    position: relative;
}

.sidebar.collapsed .sidebar-brand {
    justify-content: center;
}

.sidebar.collapsed .sidebar-brand i {
    margin-right: 0 !important;
}

.sidebar.collapsed .sidebar-toggle.d-none.d-md-flex {
    position: absolute;
    top: 50%;
    right: 0.3rem;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0.35rem;
}

.sidebar-header {
    min-height: 84px;
}

.sidebar-brand {
    letter-spacing: 0.2px;
}

.nav-item {
    margin: 0.2rem 0;
}

.nav-link {
    margin-right: 0.65rem;
    border-radius: 0 12px 12px 0;
    min-height: 46px;
}

.nav-link:hover {
    background: rgba(28, 126, 214, 0.16);
    color: var(--text-primary);
    transform: translateX(3px);
}

.nav-link.active {
    color: #7dd3fc;
    background: linear-gradient(90deg, rgba(28, 126, 214, 0.24), rgba(15, 118, 110, 0.16));
    border-right: 3px solid #38bdf8;
}

/* Keep collapsed sidebar compact and prevent footer/action overflow */
.sidebar,
.sidebar-content,
.sidebar-menu,
.sidebar-footer {
    overflow-x: hidden;
}

.sidebar.collapsed .nav-link {
    margin: 0.22rem 0.35rem;
    border-radius: 10px;
    justify-content: center;
    padding-left: 0.55rem;
    padding-right: 0.55rem;
}

.sidebar.collapsed .nav-link:hover {
    transform: none;
}

.sidebar.collapsed .nav-link.active {
    border-right: 0;
    border: 1px solid rgba(56, 189, 248, 0.45);
}

.sidebar.collapsed .nav-link.active::before {
    display: none;
}

.sidebar.collapsed .sidebar-footer {
    padding: 0.5rem 0.35rem;
}

.sidebar.collapsed .user-menu {
    padding: 0.45rem;
    gap: 0.4rem;
    align-items: center;
}

.sidebar.collapsed .user-info {
    justify-content: center;
}

.sidebar.collapsed .user-avatar {
    margin-right: 0;
}

.sidebar.collapsed .user-actions {
    margin-left: 0;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.35rem;
    justify-items: center;
}

.sidebar.collapsed .action-btn {
    min-width: 36px;
    min-height: 36px;
    width: 36px;
    height: 36px;
}

.sidebar.collapsed .login-prompt .btn {
    width: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
}

.sidebar.collapsed .login-prompt .btn i {
    margin: 0 !important;
    font-size: 1rem;
}

.main-content {
    margin-left: var(--sidebar-width);
    background: transparent;
}

.sidebar-collapsed .main-content {
    margin-left: 76px;
}

.content-wrapper {
    width: min(1500px, 100%);
    margin: 0 auto;
    padding: clamp(1rem, 1.1vw + 0.7rem, 2.5rem);
    overflow: visible;
}

.page-header {
    border: 1px solid rgba(28, 126, 214, 0.24);
    background: linear-gradient(120deg, rgba(28, 126, 214, 0.14), rgba(15, 118, 110, 0.1));
}

.page-title {
    letter-spacing: -0.02em;
}

.card {
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.card:hover {
    transform: translateY(-1px);
    border-color: rgba(28, 126, 214, 0.35);
    box-shadow: var(--shadow-md);
}

.btn {
    min-height: 42px;
    border-radius: 12px;
    font-weight: 600;
}

.btn-primary {
    background: linear-gradient(135deg, #0f766e, #0b4f6c);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0d695f, #094661);
}

.btn-outline-dark {
    color: #e5edf7;
    border-color: rgba(148, 163, 184, 0.55);
    background: rgba(30, 41, 59, 0.28);
}

.btn-outline-dark:hover,
.btn-outline-dark:focus,
.btn-outline-dark:active {
    color: #f8fafc;
    border-color: rgba(56, 189, 248, 0.75);
    background: rgba(30, 41, 59, 0.5);
}

.table {
    border-radius: 12px;
    overflow: hidden;
}

.table th {
    position: sticky;
    top: 0;
    z-index: 1;
}

.table-responsive {
    border-radius: 12px;
    border: 1px solid rgba(138, 155, 173, 0.16);
}

.form-control,
.form-select {
    border-radius: 12px;
    min-height: 42px;
}

.form-control:focus,
.form-select:focus {
    box-shadow: 0 0 0 3px rgba(28, 126, 214, 0.18);
    border-color: rgba(28, 126, 214, 0.75);
}

.mobile-header {
    min-height: calc(var(--header-height) + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    border-bottom: 1px solid var(--border-color);
}

.mobile-menu-toggle,
.sidebar-toggle,
.action-btn {
    min-width: 44px;
    min-height: 44px;
}

.sidebar-overlay {
    backdrop-filter: blur(4px);
}

.leaflet-popup-content-wrapper {
    background: rgba(13, 19, 29, 0.96);
    color: #f3f7fc;
    border: 1px solid rgba(56, 189, 248, 0.35);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.leaflet-popup-tip {
    background: rgba(13, 19, 29, 0.96);
}

.leaflet-popup-content {
    color: #f3f7fc;
    line-height: 1.45;
}

.leaflet-popup-content strong {
    color: #7dd3fc;
    font-weight: 700;
}

.leaflet-container a.leaflet-popup-close-button {
    color: #dbeafe !important;
}

.leaflet-container a.leaflet-popup-close-button:hover {
    color: #ffffff !important;
}

@media (max-width: 992px) {
    .content-wrapper {
        width: min(100%, 1100px);
        padding: 1rem;
    }
}

@media (max-width: 768px) {
    .main-content {
        margin-left: 0 !important;
        margin-top: var(--header-height);
        min-height: calc(100dvh - var(--header-height));
    }

    .sidebar {
        width: min(88vw, 340px);
        max-width: 340px;
    }

    .sidebar.mobile-open {
        box-shadow: 18px 0 42px rgba(0, 0, 0, 0.42);
    }

    .content-wrapper {
        padding: 0.875rem;
    }

    .btn {
        width: auto;
        min-height: 44px;
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .d-grid .btn,
    .btn.w-100 {
        width: 100%;
    }

    .card {
        border-radius: 12px;
    }

    #map-container,
    #realtime-map-container,
    #mqttMap,
    #realtimeMap,
    #mapid {
        min-height: 320px;
        height: 52vh;
    }

    .toast-container {
        left: 0.65rem;
        right: 0.65rem;
        top: calc(var(--header-height) + 0.5rem);
    }
}

@media (max-width: 420px) {
    .mobile-brand span {
        font-size: 1rem;
    }

    .page-title {
        font-size: 1.35rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
