/* =========================================================
   Pegelmeter Companion Portal Theme
   Corporate / Standalone Branding:
     - Blue:   #001E95
     - Dark:   #00125C
     - Green:  #78C750
   ========================================================= */

:root {
    --kc-connect-blue: #001E95;
    --kc-connect-green: #78C750;
    --kc-connect-green-hover: #68b542;
    --kc-connect-green-active: #599d37;
    --kc-connect-dark-bg: #00125C;
    --kc-card-bg: rgba(0, 24, 115, 0.78);
    --kc-card-bg-header: rgba(0, 20, 95, 0.9);
    --kc-input-bg: rgba(0, 14, 70, 0.88);
    --kc-input-border: #1e3a9c;
    --kc-text-primary: #FFFFFF;
    --kc-text-secondary: #94A3B8;
    --kc-text-muted: #64748B;
    --kc-error-bg: rgba(239, 68, 68, 0.18);
    --kc-error-border: #EF4444;
    --kc-error-text: #FCA5A5;
    --kc-success-bg: rgba(120, 199, 80, 0.18);
    --kc-success-border: #78C750;
    --kc-success-text: #86EFAC;
    --kc-card-radius: 14px;
    --kc-input-radius: 8px;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: radial-gradient(circle at 50% 15%, #001E95 0%, #00125C 58%, #000a33 100%) no-repeat center center fixed;
    background-size: cover;
    color: var(--kc-text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* App Container */
.portal-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 24px 20px 48px 20px;
}

/* Landing Page Wrapper (index.html) */
.landing-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 32px 16px;
}

.landing-card {
    width: 100%;
    max-width: 500px;
    background: var(--kc-card-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(120, 199, 80, 0.35);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
    padding: 40px 32px;
    text-align: center;
}

.landing-logo {
    width: 250px;
    height: auto;
    max-height: 48px;
    margin: 0 auto 16px auto;
    display: block;
    filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.45));
}

.landing-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: #FFFFFF;
    margin: 0 0 8px 0;
}

.landing-desc {
    color: var(--kc-text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
    margin: 0 0 28px 0;
}

.landing-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Navigation Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--kc-card-bg-header);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(120, 199, 80, 0.3);
    border-radius: var(--kc-card-radius);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
    padding: 12px 22px;
    margin-bottom: 24px;
    position: relative;
    gap: 16px;
}

.brand-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-width: 0;
}

.brand-identity,
.brand-section {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.brand-logo-img {
    height: 34px;
    width: auto;
    display: block;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
    flex-shrink: 0;
}

.brand-title,
.header h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    color: #FFFFFF;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

/* Nav Menu Container (links + user info) */
.nav-menu {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    margin-left: 16px;
    gap: 16px;
}

/* Nav Links */
.nav-links {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-links a {
    text-decoration: none;
    color: var(--kc-text-secondary);
    font-weight: 600;
    font-size: 0.92rem;
    padding: 7px 14px;
    border-radius: 8px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.nav-links a:hover {
    color: #FFFFFF;
    background: rgba(120, 199, 80, 0.12);
}

.nav-links a.active, .nav-links a[style*="underline"] {
    color: #FFFFFF !important;
    background: rgba(120, 199, 80, 0.22) !important;
    border: 1px solid rgba(120, 199, 80, 0.5) !important;
    text-decoration: none !important;
}

/* User Info Section */
.user-info {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-left: auto;
    flex-wrap: wrap;
}

.user-chip {
    font-size: 0.88rem;
    color: var(--kc-text-secondary);
    white-space: nowrap;
}

.user-chip strong {
    color: #FFFFFF;
}

/* Hamburger Toggle Button */
.nav-toggle {
    display: none;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(120, 199, 80, 0.35);
    border-radius: 8px;
    padding: 8px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.nav-toggle:hover,
.nav-toggle:focus-visible {
    background: rgba(120, 199, 80, 0.15);
    border-color: var(--kc-connect-green);
    outline: none;
}

.hamburger-line {
    display: block;
    width: 20px;
    height: 2px;
    background: #FFFFFF;
    border-radius: 2px;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

/* Active hamburger animation -> X */
.nav-toggle.is-active .hamburger-line:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.nav-toggle.is-active .hamburger-line:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.nav-toggle.is-active .hamburger-line:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* Standard Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--kc-input-radius);
    cursor: pointer;
    font-weight: 700;
    font-size: 0.88rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease-in-out;
    box-sizing: border-box;
}

.btn-primary, .btn-download, .btn-success {
    background-color: var(--kc-connect-green);
    color: #FFFFFF !important;
    box-shadow: 0 4px 14px rgba(120, 199, 80, 0.35);
}

.btn-primary:hover, .btn-download:hover, .btn-success:hover {
    background-color: var(--kc-connect-green-hover);
    box-shadow: 0 6px 18px rgba(120, 199, 80, 0.5);
    transform: translateY(-1px);
}

.btn-secondary, .btn-apk {
    background-color: #0284c7;
    color: #FFFFFF !important;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
}

.btn-secondary:hover, .btn-apk:hover {
    background-color: #0369a1;
    transform: translateY(-1px);
}

.btn-license {
    background-color: #d97706;
    color: #FFFFFF !important;
    box-shadow: 0 4px 12px rgba(217, 119, 6, 0.3);
}

.btn-license:hover {
    background-color: #b45309;
    transform: translateY(-1px);
}

.btn-report, .btn-info {
    background-color: #0ea5e9;
    color: #FFFFFF !important;
}

.btn-report:hover, .btn-info:hover {
    background-color: #0284c7;
}

.btn-kml, .btn-warning {
    background-color: #f59e0b;
    color: #0f172a !important;
    font-weight: 700;
}

.btn-kml:hover, .btn-warning:hover {
    background-color: #d97706;
}

.btn-logout, .btn-danger {
    background-color: rgba(239, 68, 68, 0.15);
    border: 1px solid #ef4444;
    color: #fca5a5 !important;
}

.btn-logout:hover, .btn-danger:hover {
    background-color: #ef4444;
    color: #FFFFFF !important;
}

/* Card Containers */
.card {
    background: var(--kc-card-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(120, 199, 80, 0.3);
    border-radius: var(--kc-card-radius);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
    padding: 24px;
    margin-bottom: 24px;
    color: var(--kc-text-primary);
}

.card h2, .card h3 {
    margin-top: 0;
    color: #FFFFFF;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 12px;
    margin-bottom: 20px;
}

/* Grid Containers */
.grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

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

@media (max-width: 860px) {
    .portal-container {
        padding: 12px 12px 36px 12px;
    }

    .header {
        flex-direction: column;
        align-items: stretch;
        padding: 12px 16px;
        gap: 0;
    }

    .brand-bar {
        width: 100%;
        justify-content: space-between;
    }

    .brand-identity,
    .brand-section {
        gap: 8px;
        min-width: 0;
        flex: 1;
        overflow: hidden;
        display: flex;
        align-items: center;
    }

    .brand-logo-img {
        height: 20px;
        max-width: 118px;
        width: auto;
        object-fit: contain;
        flex-shrink: 0;
    }

    .brand-title,
    .header h1 {
        font-size: 0.90rem;
        font-weight: 700;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin: 0;
        flex-shrink: 1;
        letter-spacing: 0;
    }

    .nav-toggle {
        display: flex;
        width: 36px;
        height: 36px;
        padding: 6px;
    }

    .nav-menu {
        display: none;
        flex-direction: column;
        width: 100%;
        margin-left: 0;
        margin-top: 12px;
        padding-top: 14px;
        border-top: 1px solid rgba(255, 255, 255, 0.12);
        gap: 12px;
    }

    .nav-menu.is-open {
        display: flex;
        animation: navSlideDown 0.22s ease-out;
    }

    .nav-links {
        flex-direction: column;
        width: 100%;
        gap: 6px;
    }

    .nav-links a {
        display: block;
        width: 100%;
        padding: 10px 14px;
        font-size: 0.95rem;
        border-radius: 8px;
        text-align: left;
    }

    .user-info {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        margin-left: 0;
        margin-top: 6px;
        padding-top: 12px;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        gap: 8px;
    }

    .user-chip {
        text-align: center;
        margin-bottom: 2px;
        white-space: normal;
        word-break: break-word;
    }

    .user-info .btn {
        width: 100%;
        padding: 10px 14px;
        justify-content: center;
    }
}

@keyframes navSlideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tables */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 0.92rem;
}

th, td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

th {
    background-color: rgba(0, 18, 92, 0.9);
    color: var(--kc-text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.6px;
    border-bottom: 1px solid rgba(120, 199, 80, 0.35);
}

tbody tr {
    transition: background-color 0.15s ease;
}

tbody tr:hover {
    background-color: rgba(120, 199, 80, 0.08);
}

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

/* KPI Cards (Speedtest / Jitter) */
.kpi-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: rgba(0, 24, 115, 0.78);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(120, 199, 80, 0.3);
    border-radius: var(--kc-card-radius);
    padding: 20px;
    text-align: center;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

.kpi-label {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--kc-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 1.9rem;
    font-weight: 800;
    color: #FFFFFF;
    margin-bottom: 4px;
}

.kpi-sub {
    font-size: 0.8rem;
    color: var(--kc-text-muted);
}

.kpi-download { color: var(--kc-connect-green); }
.kpi-upload { color: #38bdf8; }
.kpi-latency { color: #a78bfa; }
.kpi-jitter { color: #c084fc; }
.kpi-loss { color: #f87171; }

/* Forms & Inputs */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.88rem;
    color: #E2E8F0;
}

.form-group input, .form-group textarea, .form-group select {
    width: 100%;
    padding: 10px 14px;
    background-color: var(--kc-input-bg);
    border: 1px solid var(--kc-input-border);
    border-radius: var(--kc-input-radius);
    color: #FFFFFF;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
    border-color: var(--kc-connect-green);
    box-shadow: 0 0 0 3px rgba(120, 199, 80, 0.3);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-mbtiles {
    background-color: rgba(56, 189, 248, 0.2);
    border: 1px solid #38bdf8;
    color: #38bdf8;
}

.badge-map {
    background-color: rgba(245, 158, 11, 0.2);
    border: 1px solid #f59e0b;
    color: #fbbf24;
}

.badge-speedtest, .badge-green {
    background-color: rgba(120, 199, 80, 0.2);
    border: 1px solid var(--kc-connect-green);
    color: var(--kc-connect-green);
}

.badge-yellow {
    background-color: rgba(245, 158, 11, 0.2);
    border: 1px solid #f59e0b;
    color: #fbbf24;
}

.badge-red {
    background-color: rgba(239, 68, 68, 0.2);
    border: 1px solid #ef4444;
    color: #fca5a5;
}

/* Tier Badges */
.badge-tier-expert {
    background-color: rgba(168, 85, 247, 0.25);
    border: 1px solid #a855f7;
    color: #d8b4fe;
}

.badge-tier-standard {
    background-color: rgba(56, 189, 248, 0.25);
    border: 1px solid #38bdf8;
    color: #7dd3fc;
}

.badge-tier-lite {
    background-color: rgba(148, 163, 184, 0.25);
    border: 1px solid #94a3b8;
    color: #cbd5e1;
}

/* Lists */
.stats-list, .info-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.stats-list li, .info-list li {
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.92rem;
}

.info-label {
    color: var(--kc-text-secondary);
}

.info-value {
    color: #FFFFFF;
    font-weight: 600;
}

/* Info Box / Alert */
.info-box {
    background-color: rgba(120, 199, 80, 0.12);
    border-left: 4px solid var(--kc-connect-green);
    padding: 14px 18px;
    margin-bottom: 24px;
    border-radius: 6px;
    color: #86efac;
    font-size: 0.92rem;
}

/* Map Containers */
#map {
    height: 420px;
    width: 100%;
    border-radius: var(--kc-input-radius);
    border: 1px solid rgba(120, 199, 80, 0.35);
}

#overviewMap {
    height: 640px;
    width: 100%;
    border-radius: var(--kc-input-radius);
    border: 1px solid rgba(120, 199, 80, 0.35);
    background: #000c3b;
    z-index: 1;
}

@media (max-height: 800px) {
    #overviewMap {
        height: 520px;
    }
}

/* Filter Toolbar */
.filter-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding: 14px 18px;
    background: rgba(0, 18, 92, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--kc-card-radius);
}

.filter-toolbar .search-box {
    flex: 2 1 240px;
    position: relative;
}

.filter-toolbar input,
.filter-toolbar select {
    background-color: var(--kc-input-bg);
    border: 1px solid var(--kc-input-border);
    border-radius: var(--kc-input-radius);
    color: var(--kc-text-primary);
    padding: 9px 14px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
}

.filter-toolbar .filter-group {
    flex: 1 1 150px;
}

.filter-toolbar input:focus,
.filter-toolbar select:focus {
    border-color: var(--kc-connect-green);
    box-shadow: 0 0 0 2px rgba(120, 199, 80, 0.25);
}

.filter-toolbar select option {
    background: #00125C;
    color: #FFFFFF;
}

.filter-toolbar .filter-counter {
    font-size: 0.88rem;
    color: var(--kc-text-secondary);
    white-space: nowrap;
    margin-left: auto;
    font-weight: 500;
}

/* Leaflet Dark Popups */
.leaflet-popup-content-wrapper {
    background: #001550 !important;
    color: #FFFFFF !important;
    border: 1px solid rgba(120, 199, 80, 0.5) !important;
    border-radius: 10px !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6) !important;
}

.leaflet-popup-tip {
    background: #001550 !important;
}

.leaflet-popup-content {
    color: #FFFFFF !important;
    margin: 14px 18px !important;
    line-height: 1.5 !important;
    font-size: 0.88rem !important;
}

.leaflet-popup-content * {
    color: #FFFFFF;
}

.leaflet-popup-content strong,
.leaflet-popup-content b {
    color: #FFFFFF !important;
    font-weight: 700 !important;
}

.leaflet-popup-content p {
    color: #FFFFFF !important;
    margin: 4px 0 !important;
}

.leaflet-popup-content a.btn-primary,
.leaflet-popup-content .btn-primary {
    color: #FFFFFF !important;
    background-color: var(--kc-connect-green) !important;
}

.leaflet-container a.leaflet-popup-close-button {
    color: #94A3B8 !important;
    padding: 6px !important;
}

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

/* Map Legend */
.map-legend {
    background: rgba(0, 16, 80, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    font-size: 0.8rem;
    color: #FFFFFF;
    box-shadow: 0 4px 14px rgba(0,0,0,0.5);
    line-height: 1.4;
    max-width: 220px;
}

.map-legend-title {
    font-weight: 700;
    margin-bottom: 6px;
    color: #FFFFFF;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    padding-bottom: 4px;
}

.map-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 3px 0;
}

.map-legend-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,0.4);
}

.empty {
    text-align: center;
    color: var(--kc-text-muted);
    padding: 36px 20px;
    font-size: 1rem;
}

/* Footer */
.portal-footer {
    text-align: center;
    margin-top: 40px;
    font-size: 0.8rem;
    color: var(--kc-text-muted);
    letter-spacing: 0.5px;
}

/* Modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 8, 30, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.modal-card {
    background: #001242;
    border: 1px solid rgba(120, 199, 80, 0.4);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 540px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
    color: var(--kc-text-primary);
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

/* Switch toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #334155;
    transition: .3s;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #78C750;
    border-color: #78C750;
}

input:focus + .slider {
    box-shadow: 0 0 1px #78C750;
}

input:checked + .slider:before {
    transform: translateX(20px);
}

