/* ========================================
   DARK MODE STYLES
   Anycast Network Dashboard
   ======================================== */

/* CSS Custom Properties for theme colors */
:root {
    /* Light mode (default) */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-panel: rgba(255, 255, 255, 0.95);
    --bg-hover: #f3f4f6;

    --text-primary: #111827;
    --text-secondary: #374151;
    --text-muted: #6b7280;
    --text-light: #9ca3af;

    --border-primary: rgba(0, 0, 0, 0.05);
    --border-secondary: #e5e7eb;
    --border-light: #f3f4f6;

    --shadow-panel: 0 20px 50px rgba(0, 0, 0, 0.15), 0 10px 20px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 25px 60px rgba(0, 0, 0, 0.2), 0 15px 25px rgba(0, 0, 0, 0.15);

    --map-filter: saturate(0.3) brightness(1.1);
    --loading-bg: rgba(255, 255, 255, 0.8);
    --backdrop-blur: rgba(255, 255, 255, 0.95);
}

/* Dark mode variables */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-panel: rgba(30, 41, 59, 0.95);
    --bg-hover: #374151;

    --text-primary: #f1f5f9;
    --text-secondary: #e2e8f0;
    --text-muted: #94a3b8;
    --text-light: #64748b;

    --border-primary: rgba(255, 255, 255, 0.1);
    --border-secondary: #475569;
    --border-light: #334155;

    --shadow-panel: 0 20px 50px rgba(0, 0, 0, 0.5), 0 10px 20px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 25px 60px rgba(0, 0, 0, 0.6), 0 15px 25px rgba(0, 0, 0, 0.4);

    --map-filter: saturate(0.4) brightness(0.7) contrast(1.1);
    --loading-bg: rgba(15, 23, 42, 0.9);
    --backdrop-blur: rgba(30, 41, 59, 0.95);
}

/* ========================================
   BODY & BASE ELEMENTS
   ======================================== */
[data-theme="dark"] body {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary);
}

[data-theme="dark"] .bg-gray-50 {
    background-color: var(--bg-secondary) !important;
}

[data-theme="dark"] .bg-white {
    background-color: var(--bg-secondary) !important;
}

/* ========================================
   MAP STYLES - DARK MODE
   ======================================== */
[data-theme="dark"] .leaflet-tile-pane {
    filter: var(--map-filter);
}

[data-theme="dark"] .leaflet-container {
    background: var(--bg-primary);
}

/* ========================================
   HEADER BAR - DARK MODE
   ======================================== */
[data-theme="dark"] .header-bar {
    background: var(--backdrop-blur) !important;
    border-bottom-color: var(--border-primary) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .header-bar h1 {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .header-bar p {
    color: var(--text-muted) !important;
}

[data-theme="dark"] .header-bar .h-8.w-px {
    background-color: var(--border-secondary) !important;
}

/* ========================================
   FLOATING PANELS - DARK MODE
   ======================================== */
[data-theme="dark"] .floating-panel {
    background: var(--bg-panel) !important;
    border-color: var(--border-primary) !important;
    box-shadow: var(--shadow-panel);
}

[data-theme="dark"] .floating-panel:hover {
    box-shadow: var(--shadow-hover);
}

[data-theme="dark"] .floating-panel h3 {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] .floating-panel span,
[data-theme="dark"] .floating-panel .text-gray-600 {
    color: var(--text-muted) !important;
}

[data-theme="dark"] .floating-panel .border-t {
    border-color: var(--border-secondary) !important;
}

/* ========================================
   NODE DETAIL PANEL - DARK MODE
   ======================================== */
[data-theme="dark"] .node-detail-panel {
    background: var(--backdrop-blur) !important;
    border-left-color: var(--border-primary) !important;
}

[data-theme="dark"] .node-detail-panel .border-b {
    border-color: var(--border-secondary) !important;
}

[data-theme="dark"] .node-detail-panel h2,
[data-theme="dark"] .node-detail-panel .text-gray-900 {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .node-detail-panel .text-gray-500 {
    color: var(--text-muted) !important;
}

[data-theme="dark"] .node-detail-panel .text-gray-400 {
    color: var(--text-light) !important;
}

[data-theme="dark"] .node-detail-panel .bg-gray-50 {
    background-color: var(--bg-tertiary) !important;
}

[data-theme="dark"] .node-detail-panel .bg-gray-100 {
    background-color: var(--bg-tertiary) !important;
}

[data-theme="dark"] .node-detail-panel .close-btn {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-muted) !important;
}

[data-theme="dark"] .node-detail-panel .close-btn:hover {
    background-color: rgba(239, 68, 68, 0.2) !important;
    color: #ef4444 !important;
}

/* Footer */
[data-theme="dark"] .node-detail-panel .bg-gray-50.border-t {
    background-color: var(--bg-tertiary) !important;
    border-color: var(--border-secondary) !important;
}

/* ========================================
   PROBE DRAWER - DARK MODE
   ======================================== */
[data-theme="dark"] #probeDrawer {
    background-color: var(--bg-secondary) !important;
}

[data-theme="dark"] #probeDrawer .border-b {
    border-color: var(--border-secondary) !important;
}

[data-theme="dark"] #probeDrawer h2,
[data-theme="dark"] #probeDrawer .text-gray-900 {
    color: var(--text-primary) !important;
}

[data-theme="dark"] #probeDrawer .text-gray-500 {
    color: var(--text-muted) !important;
}

[data-theme="dark"] #probeDrawer .text-gray-400 {
    color: var(--text-light) !important;
}

[data-theme="dark"] #probeDrawer .bg-gray-100 {
    background-color: var(--bg-tertiary) !important;
}

[data-theme="dark"] #probeDrawer .bg-gray-50 {
    background-color: var(--bg-tertiary) !important;
}

[data-theme="dark"] #probeDrawer .bg-blue-50 {
    background-color: rgba(59, 130, 246, 0.15) !important;
    border-color: rgba(59, 130, 246, 0.3) !important;
}

[data-theme="dark"] #probeDrawer .text-blue-600 {
    color: #60a5fa !important;
}

/* Table styling */
[data-theme="dark"] #probeDrawer table {
    background-color: var(--bg-tertiary) !important;
}

[data-theme="dark"] #probeDrawer tbody tr:hover {
    background-color: var(--bg-hover) !important;
}

[data-theme="dark"] #probeDrawer .divide-y>* {
    border-color: var(--border-secondary) !important;
}

[data-theme="dark"] #probeDrawer .border-gray-200 {
    border-color: var(--border-secondary) !important;
}

[data-theme="dark"] #probeDrawer .border-gray-100 {
    border-color: var(--border-light) !important;
}

/* ========================================
   DRAWER BACKDROP - DARK MODE
   ======================================== */
[data-theme="dark"] #drawerBackdrop {
    background-color: rgba(0, 0, 0, 0.6) !important;
}

[data-theme="dark"] .drawer-backdrop {
    background: rgba(0, 0, 0, 0.5) !important;
}

/* ========================================
   REPORTS DRAWER - DARK MODE
   ======================================== */
[data-theme="dark"] .reports-drawer .drawer-content {
    background-color: var(--bg-secondary) !important;
}

[data-theme="dark"] .reports-drawer .border-b {
    border-color: var(--border-secondary) !important;
}

[data-theme="dark"] .reports-drawer .border-t {
    border-color: var(--border-secondary) !important;
}

[data-theme="dark"] .reports-drawer h2,
[data-theme="dark"] .reports-drawer .text-gray-900 {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .reports-drawer .text-gray-500 {
    color: var(--text-muted) !important;
}

[data-theme="dark"] .reports-drawer .text-gray-700 {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] .reports-drawer input {
    background-color: var(--bg-tertiary) !important;
    border-color: var(--border-secondary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .reports-drawer input::placeholder {
    color: var(--text-light) !important;
}

[data-theme="dark"] .reports-drawer button {
    border-color: var(--border-secondary) !important;
    color: var(--text-secondary) !important;
}

[data-theme="dark"] .reports-drawer button:hover {
    background-color: var(--bg-tertiary) !important;
}

/* Table */
[data-theme="dark"] .reports-drawer table {
    background-color: var(--bg-tertiary) !important;
}

[data-theme="dark"] .reports-drawer thead tr {
    background-color: var(--bg-tertiary) !important;
}

[data-theme="dark"] .reports-drawer th {
    color: var(--text-muted) !important;
}

[data-theme="dark"] .reports-drawer tbody tr:hover {
    background-color: var(--bg-hover) !important;
}

[data-theme="dark"] .reports-drawer .border-gray-200 {
    border-color: var(--border-secondary) !important;
}

[data-theme="dark"] .reports-drawer .divide-y>* {
    border-color: var(--border-light) !important;
}

/* Pagination */
[data-theme="dark"] .pagination-btn {
    background-color: var(--bg-tertiary) !important;
    border-color: var(--border-secondary) !important;
    color: var(--text-secondary) !important;
}

[data-theme="dark"] .pagination-btn:hover {
    background-color: var(--bg-hover) !important;
}

[data-theme="dark"] .pagination-btn.active {
    background-color: #2563eb !important;
    border-color: #2563eb !important;
    color: white !important;
}

/* ========================================
   LOADING OVERLAY - DARK MODE
   ======================================== */
[data-theme="dark"] #loading,
[data-theme="dark"] #loadingOverlay {
    background: var(--loading-bg) !important;
}

[data-theme="dark"] #loading .text-gray-800,
[data-theme="dark"] #loadingOverlay .text-gray-600 {
    color: var(--text-primary) !important;
}

/* ========================================
   RIPE ATLAS REFERENCE - DARK MODE
   ======================================== */
[data-theme="dark"] .fixed.bottom-4.left-4 a,
[data-theme="dark"] [class*="bottom-4"][class*="left-4"] a {
    background-color: var(--bg-panel) !important;
    border-color: var(--border-secondary) !important;
    color: var(--text-muted) !important;
}

[data-theme="dark"] .fixed.bottom-4.left-4 a:hover,
[data-theme="dark"] [class*="bottom-4"][class*="left-4"] a:hover {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

/* ========================================
   LEAFLET CONTROLS - DARK MODE
   ======================================== */
[data-theme="dark"] .leaflet-control-zoom a {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-secondary) !important;
}

[data-theme="dark"] .leaflet-control-zoom a:hover {
    background-color: var(--bg-tertiary) !important;
}

[data-theme="dark"] .leaflet-control-attribution {
    background-color: var(--bg-panel) !important;
    color: var(--text-muted) !important;
}

[data-theme="dark"] .leaflet-control-attribution a {
    color: var(--text-secondary) !important;
}

/* ========================================
   LEAFLET TOOLTIP - DARK MODE
   ======================================== */
[data-theme="dark"] .leaflet-tooltip {
    background: var(--bg-panel) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-secondary) !important;
}

/* ========================================
   SCROLLBAR - DARK MODE
   ======================================== */
[data-theme="dark"] ::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: var(--border-secondary);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}

/* ========================================
   DARK MODE TOGGLE BUTTON
   ======================================== */
.dark-mode-toggle {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1060;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.dark-mode-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.dark-mode-toggle svg {
    width: 22px;
    height: 22px;
    transition: all 0.3s ease;
}

.dark-mode-toggle .sun-icon {
    color: #f59e0b;
    display: none;
}

.dark-mode-toggle .moon-icon {
    color: #6366f1;
    display: block;
}

[data-theme="dark"] .dark-mode-toggle {
    background: rgba(30, 41, 59, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .dark-mode-toggle .sun-icon {
    display: block;
}

[data-theme="dark"] .dark-mode-toggle .moon-icon {
    display: none;
}

/* Position adjustment when header is present */
.header-bar~.dark-mode-toggle,
.header-bar+.dark-mode-toggle {
    top: 80px;
}

/* Desktop: position next to CTA button */
@media (min-width: 769px) {
    .dark-mode-toggle {
        top: 16px;
        right: 280px;
    }

    .header-bar~.dark-mode-toggle {
        top: 16px;
        right: 280px;
    }
}

/* Mobile adjustments - position above RIPE Atlas reference (bottom-left) */
@media (max-width: 768px) {

    .dark-mode-toggle,
    .header-bar~.dark-mode-toggle,
    .header-bar+.dark-mode-toggle,
    .dark-mode-toggle.embed-position {
        top: auto !important;
        bottom: 50px !important;
        left: 8px !important;
        right: auto !important;
        width: 36px !important;
        height: 36px !important;
        border-radius: 10px !important;
    }

    .dark-mode-toggle svg {
        width: 18px;
        height: 18px;
    }
}

/* ========================================
   LEGEND ITEMS - DARK MODE
   ======================================== */
[data-theme="dark"] .legend-item:hover {
    background-color: var(--bg-tertiary) !important;
}

/* ========================================
   CHARTS - DARK MODE (ApexCharts)
   ======================================== */
[data-theme="dark"] .apexcharts-text,
[data-theme="dark"] .apexcharts-title-text {
    fill: var(--text-primary) !important;
}

[data-theme="dark"] .apexcharts-legend-text {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] .apexcharts-gridline {
    stroke: var(--border-secondary) !important;
}

[data-theme="dark"] .apexcharts-xaxis-label,
[data-theme="dark"] .apexcharts-yaxis-label {
    fill: var(--text-muted) !important;
}

[data-theme="dark"] .apexcharts-tooltip {
    background: var(--bg-secondary) !important;
    border-color: var(--border-secondary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .apexcharts-tooltip-title {
    background: var(--bg-tertiary) !important;
    border-color: var(--border-secondary) !important;
}

/* ========================================
   STATUS BADGES - DARK MODE
   ======================================== */
[data-theme="dark"] .status-badge.complete {
    background: rgba(16, 185, 129, 0.2) !important;
    color: #34d399 !important;
}

[data-theme="dark"] .status-badge.pending {
    background: rgba(245, 158, 11, 0.2) !important;
    color: #fbbf24 !important;
}

[data-theme="dark"] .status-badge.partial {
    background: rgba(59, 130, 246, 0.2) !important;
    color: #60a5fa !important;
}

/* ========================================
   INPUT FIELDS - DARK MODE
   ======================================== */
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="search"],
[data-theme="dark"] input[type="checkbox"] {
    background-color: var(--bg-tertiary) !important;
    border-color: var(--border-secondary) !important;
    color: var(--text-primary) !important;
}

/* ========================================
   TRANSITION ANIMATION
   ======================================== */
body,
.header-bar,
.floating-panel,
.node-detail-panel,
#probeDrawer,
.reports-drawer .drawer-content,
.dark-mode-toggle,
.leaflet-tile-pane {
    transition: background-color 0.3s ease,
        border-color 0.3s ease,
        color 0.3s ease,
        filter 0.5s ease;
}