:root {
    --bg-dark: #f0f4f8;
    --bg-light: #ffffff;
    --accent-blue: #2563eb;
    --accent-glow: rgba(37, 99, 235, 0.3);
    --accent-green: #059669;
    --accent-red: #dc2626;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(0, 0, 0, 0.08);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --font-family: 'Outfit', system-ui, -apple-system, sans-serif;
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color-scheme: light;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-dark);
    background-image:
        radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.06), transparent 30%),
        radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.06), transparent 30%);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    flex-direction: column;
}

/* Glassmorphism Classes */
.glass-header {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.05);
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.05);
}

/* Header */
.header-content {
    padding: 16px 24px;
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

header h1 span {
    color: var(--accent-blue);
    font-weight: 400;
}

#location-display {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    background: rgba(0, 0, 0, 0.05);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--glass-border);
}

/* Fix Places Autocomplete Dropdown z-index */
.pac-container {
    z-index: 1000 !important;
}

/* Main Layout */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    gap: 24px;
}

/* Search Bar */
.search-wrapper {
    display: flex;
    justify-content: center;
    width: 100%;
    position: relative;
    z-index: 100;
}

.search-container {
    display: flex;
    width: 100%;
    max-width: 600px;
    padding: 8px;
    gap: 8px;
    align-items: center;
}

#address-container {
    flex: 1;
    min-width: 0;
}

.custom-search-input {
    width: 100% !important;
    height: 48px !important;
    background: transparent !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    font-family: inherit;
    font-size: 16px;
    padding: 0 16px !important;
    margin: 0 !important;
    color: var(--text-primary) !important;
    box-sizing: border-box !important;
    color-scheme: light !important;
}

.custom-search-input::placeholder {
    color: var(--text-muted);
}

.pac-results {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    margin-top: 8px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    padding: 8px 0;
}

.pac-item {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 15px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--glass-border);
    transition: var(--transition);
    text-align: left;
}

.pac-item:last-child {
    border-bottom: none;
}

.pac-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.gps-btn {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--accent-blue), #2563eb);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.gps-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--accent-glow);
}

.gps-btn:active {
    transform: translateY(0);
}

/* Utility */
.hidden {
    display: none !important;
}

/* Status Messages */
.status-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    text-align: center;
    animation: fadeIn 0.5s ease;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.55, 0.15, 0.45, 0.85) infinite;
    margin-bottom: 16px;
}

.empty-icon {
    color: var(--text-muted);
    margin-bottom: 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Main Content Area */
#main-content {
    display: flex;
    flex: 1;
    gap: 24px;
    align-items: flex-start;
    min-height: 0;
}

/* Matrix */
#matrix-section {
    flex: 1 1 50%;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.matrix-wrapper {
    overflow: auto;
    padding: 24px;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-blue) rgba(255, 255, 255, 0.02);
}

.matrix-wrapper::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.matrix-wrapper::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 4px;
}

.matrix-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.matrix-wrapper::-webkit-scrollbar-corner {
    background: transparent;
}

#matrix-container table {
    border-collapse: separate;
    border-spacing: 4px;
    width: max-content;
    margin: 0 auto;
}

#matrix-container th {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 13px;
    padding: 8px 12px;
    text-align: center;
}

#matrix-container thead th {
    position: sticky;
    top: -24px;
    background: var(--bg-dark);
    z-index: 10;
}

#matrix-container tbody th {
    position: sticky;
    left: -24px;
    background: var(--bg-dark);
    z-index: 5;
    text-align: right;
    padding-right: 16px;
}

#matrix-container thead th:first-child {
    z-index: 15;
    left: -24px;
}

.site-distance {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Matrix Cells */
#matrix-container td {
    padding: 14px 10px;
    text-align: center;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 15px;
    min-width: 72px;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.print-ssid-list {
    display: none;
}

#matrix-container td:not(.empty):hover {
    z-index: 20;
    filter: brightness(1.1);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}

#matrix-container td:active {
    opacity: 0.8;
}

#matrix-container td.empty {
    background: rgba(0, 0, 0, 0.03) !important;
    color: var(--text-muted);
    font-weight: 400;
    cursor: default;
    box-shadow: none;
}

/* Detail Overlay / Modal */
.detail-overlay {
    flex: 1 1 50%;
    display: flex;
    flex-direction: column;
}

.detail-content-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--glass-border);
}

.detail-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.close-btn {
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.close-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-primary);
    transform: rotate(90deg);
}

.map-container {
    height: 250px;
    width: 100%;
    background: #e2e8f0;
    border-bottom: 1px solid var(--glass-border);
}

.ssid-list {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ssid-card {
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 16px;
    transition: var(--transition);
}

.ssid-card:hover {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.ssid-card h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-blue);
    margin-bottom: 12px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px dashed rgba(0, 0, 0, 0.1);
    font-size: 14px;
}

.detail-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

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

.detail-value {
    color: var(--text-primary);
    font-weight: 500;
}

.detail-distance {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-align: right;
}

/* Responsive Desktop vs Mobile */
@media (max-width: 900px) {
    #main-content {
        flex-direction: column;
    }

    #matrix-section {
        width: 100%;
    }

    .detail-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100;
        padding: 0;
        background: rgba(0, 0, 0, 0.8);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        display: flex;
        align-items: flex-end;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .detail-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }

    .detail-content-wrapper {
        width: 100%;
        height: 85vh;
        border-radius: 24px 24px 0 0;
        transform: translateY(100%);
        transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
        border: 1px solid var(--glass-border);
        border-bottom: none;
    }

    .detail-overlay.active .detail-content-wrapper {
        transform: translateY(0);
    }
}

@media (min-width: 901px) {
    .detail-overlay {
        display: none;
    }

    .detail-overlay.active {
        display: flex;
        animation: slideInRight 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    }

    @keyframes slideInRight {
        from {
            opacity: 0;
            transform: translateX(20px);
        }

        to {
            opacity: 1;
            transform: translateX(0);
        }
    }
}

@media print {
    @page {
        size: landscape;
        margin: 10mm;
    }

    body,
    main,
    #main-content,
    #matrix-section,
    .matrix-wrapper {
        display: block !important;
        height: auto !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    body {
        background: #fff;
        color: #000;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .glass-header {
        position: static !important;
        background: none !important;
        border: none !important;
        backdrop-filter: none !important;
        box-shadow: none !important;
        padding: 0 0 16px 0 !important;
        page-break-after: avoid;
    }

    .glass-panel {
        background: none !important;
        border: none !important;
        backdrop-filter: none !important;
        box-shadow: none !important;
        padding: 0 !important;
    }

    .search-wrapper,
    .detail-overlay,
    #loading {
        display: none !important;
    }

    #matrix-section {
        overflow: visible !important;
    }

    .matrix-wrapper {
        overflow: visible !important;
        padding: 0 !important;
    }

    #matrix-container {
        overflow: visible !important;
    }

    #matrix-container table {
        width: 100% !important;
        page-break-inside: auto;
        border-collapse: separate !important;
        border-spacing: 4px !important;
    }

    #matrix-container thead th,
    #matrix-container tbody th {
        position: static !important;
        background: transparent !important;
        color: #000 !important;
        border-bottom: 2px solid #ccc;
        padding: 8px !important;
    }

    #matrix-container thead th:first-child {
        position: static !important;
    }

    #matrix-container td {
        color: #000 !important;
        text-shadow: none !important;
        border-radius: 0 !important;
        padding: 8px 4px !important;
        border: 4px solid var(--print-color, #ddd) !important;
        background: none !important;
    }

    #matrix-container td.empty {
        color: #999 !important;
        background: none !important;
        border: 1px dashed #ddd !important;
    }

    .print-ssid-list {
        display: block !important;
        margin-top: 8px;
        font-size: 11px;
        font-weight: 500;
        color: #444;
        text-align: center;
    }

    .print-ssid-list div {
        white-space: nowrap;
        background: #f0f0f0;
        padding: 2px 6px;
        border-radius: 4px;
        margin-bottom: 3px;
    }
}