/**
 * MeshCore Hub - Custom Application Styles
 *
 * This file contains all custom CSS that extends the Tailwind/DaisyUI framework.
 * Organized in sections:
 * - Color palette
 * - Navbar styling
 * - Scrollbar styling
 * - Table styling
 * - Text utilities
 * - Prose (markdown content) styling
 * - Leaflet map theming
 */

/* ==========================================================================
   Color Palette
   Single source of truth for page/section colors used across nav, charts,
   and page content. All values are OKLCH.
   ========================================================================== */

:root {
    --color-dashboard: oklch(0.75 0.15 210);   /* cyan */
    --color-nodes: oklch(0.65 0.24 265);       /* violet */
    --color-adverts: oklch(0.7 0.17 330);      /* magenta */
    --color-messages: oklch(0.75 0.18 180);    /* teal */
    --color-channels: oklch(0.72 0.15 300);    /* purple */
    --color-routes: oklch(0.72 0.17 30);       /* orange-red */
    --color-packets: oklch(0.72 0.17 145);     /* green */
    --color-map: oklch(0.8471 0.199 83.87);      /* yellow (matches btn-warning) */
    --color-members: oklch(0.72 0.17 50);      /* orange */
    --color-neutral: oklch(0.3 0.01 250);     /* subtle dark grey */
    --color-radio: oklch(0.75 0.15 210);     /* cyan — radio tile icons */

    /* Panel tint defaults — overridden per theme below */
    --panel-tint-strength: 8%;
    --panel-tint-bg: var(--color-base-100);

    /* Map marker colors — theme-independent, chosen for contrast on map tiles */
    --color-marker-infra: #3b82f6;
    --color-marker-infra-border: #1e40af;
    --color-marker-public: #22c55e;
    --color-marker-public-border: #15803d;
}

/* Light mode: darker section colors for contrast on light backgrounds */
[data-theme="light"] {
    --color-dashboard: oklch(0.55 0.15 210);
    --color-nodes: oklch(0.50 0.24 265);
    --color-adverts: oklch(0.55 0.17 330);
    --color-messages: oklch(0.55 0.18 180);
    --color-channels: oklch(0.55 0.15 300);
    --color-routes: oklch(0.55 0.17 30);
    --color-packets: oklch(0.52 0.17 145);
    --color-map: oklch(0.58 0.16 45);
    --color-members: oklch(0.55 0.18 25);
    --color-neutral: oklch(0.85 0.01 250);
    --color-radio: oklch(0.55 0.15 210);

    /* Panel fill — neutral grey; colored left border carries section identity */
    --panel-tint-strength: 0%;
    --panel-tint-bg: oklch(97% 0 0);
}

/* ==========================================================================
   Navbar Styling
   ========================================================================== */

/* Spacing between horizontal nav items */
.menu-horizontal { gap: 0.125rem; }

/* Invert monochrome logos to dark for light mode */
[data-theme="light"] .theme-logo--invert-light {
    filter: brightness(0.15);
}

/* Ensure hero heading is pure black/white per theme */
.hero-title {
    color: #fff;
    letter-spacing: -0.01em;
}
[data-theme="light"] .hero-title {
    color: #000;
}

/* Nav icon colors */
.nav-icon-dashboard { color: var(--color-dashboard); }
.nav-icon-nodes { color: var(--color-nodes); }
.nav-icon-adverts { color: var(--color-adverts); }
.nav-icon-channels { color: var(--color-channels); }
.nav-icon-routes { color: var(--color-routes); }
.nav-icon-messages { color: var(--color-messages); }
.nav-icon-packets { color: var(--color-packets); }
.nav-icon-map { color: var(--color-map); }
.nav-icon-members { color: var(--color-members); }

/* Propagate section color to parent li for hover/active backgrounds */
.navbar .menu li:has(.nav-icon-dashboard) { --nav-color: var(--color-dashboard); }
.navbar .menu li:has(.nav-icon-nodes) { --nav-color: var(--color-nodes); }
.navbar .menu li:has(.nav-icon-adverts) { --nav-color: var(--color-adverts); }
.navbar .menu li:has(.nav-icon-channels) { --nav-color: var(--color-channels); }
.navbar .menu li:has(.nav-icon-routes) { --nav-color: var(--color-routes); }
.navbar .menu li:has(.nav-icon-messages) { --nav-color: var(--color-messages); }
.navbar .menu li:has(.nav-icon-packets) { --nav-color: var(--color-packets); }
.navbar .menu li:has(.nav-icon-map) { --nav-color: var(--color-map); }
.navbar .menu li:has(.nav-icon-members) { --nav-color: var(--color-members); }

/* Section-tinted hover and active backgrounds (!important to override DaisyUI) */
.navbar .menu li > a:hover {
    background-color: color-mix(in oklch, var(--nav-color, var(--color-base-content)) 12%, transparent) !important;
}
.navbar .menu li > a.active {
    background-color: color-mix(in oklch, var(--nav-color, var(--color-base-content)) 20%, transparent) !important;
    color: inherit !important;
}

/* ==========================================================================
   Panel Tint & Accent
   Subtle flat color tint plus a colored left accent border for section
   identity. Set --panel-color on the element for the section color.
   ========================================================================== */

.panel-accent {
    background-color: color-mix(in oklch, var(--panel-color, transparent) var(--panel-tint-strength), var(--panel-tint-bg));
    border-left: 5px solid color-mix(in oklch, var(--panel-color, transparent) 55%, transparent);
}

.panel-solid {
    background-color: color-mix(in oklch, var(--panel-color, transparent) var(--panel-tint-strength), var(--panel-tint-bg));
    border-left: 5px solid color-mix(in oklch, var(--panel-color, transparent) 55%, transparent);
}

/* Route-health strip grid (dashboard widget).
   Each cell is a fixed-width colored square; the row flexes so long
   route labels truncate while the strip stays compact. */
.route-health-cell {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    display: inline-block;
}

.radio-tile-icon {
    color: var(--color-radio);
}

/* ==========================================================================
   Scrollbar Styling
   ========================================================================== */

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-base-200);
}

::-webkit-scrollbar-thumb {
    background: color-mix(in oklch, var(--color-base-content) 30%, transparent);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: color-mix(in oklch, var(--color-base-content) 50%, transparent);
}

/* ==========================================================================
   Table Styling
   ========================================================================== */

.table-sm td,
.table-sm th {
    padding: 0.5rem 0.75rem;
}

/* ==========================================================================
   Text Utilities
   ========================================================================== */

.truncate-cell {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================================================
   Prose Styling (Custom Markdown Pages)
   ========================================================================== */

.prose h1 {
    font-size: 2.25rem;
    font-weight: 700;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    scroll-margin-top: 6rem;
}

.prose h2 {
    font-size: 1.875rem;
    font-weight: 600;
    margin-top: 1.25rem;
    margin-bottom: 0.75rem;
    scroll-margin-top: 6rem;
}

.prose h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    scroll-margin-top: 6rem;
}

.prose h4 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    scroll-margin-top: 6rem;
}

.prose p {
    margin-bottom: 1rem;
    line-height: 1.75;
}

.prose ul,
.prose ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.prose ul {
    list-style-type: disc;
}

.prose ol {
    list-style-type: decimal;
}

.prose li {
    margin-bottom: 0.25rem;
}

.prose ul ul { list-style-type: circle; }
.prose ul ul ul { list-style-type: square; }
.prose ol ol { list-style-type: lower-alpha; }
.prose ol ol ol { list-style-type: lower-roman; }
.prose ul ul, .prose ul ol,
.prose ol ul, .prose ol ol { margin-top: 0.25rem; margin-bottom: 0; }

.prose a {
    color: var(--color-primary);
    text-decoration: underline;
}

.prose a:hover {
    color: color-mix(in oklab, var(--color-primary) 70%, var(--color-base-content));
}

/* Heading anchor wrappers (rehype-autolink-headings, behavior: "wrap"):
   inherit the heading color instead of the link color, and only underline on hover. */
.prose :is(h1, h2, h3, h4, h5, h6) > a {
    color: inherit;
    text-decoration: none;
}
.prose :is(h1, h2, h3, h4, h5, h6) > a:hover {
    text-decoration: underline;
}

.prose code {
    background: var(--color-base-200);
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
}

.prose pre {
    background: var(--color-base-200);
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin-bottom: 1rem;
}

.prose pre code {
    background: none;
    padding: 0;
}

.prose blockquote {
    border-left: 4px solid var(--tw-prose-quote-borders);
    padding-left: 1rem;
    margin: 1rem 0;
    font-style: italic;
}

.prose {
    overflow-wrap: break-word;
    word-break: break-word;
}

.prose > :first-child {
    margin-top: 0;
}

.prose table {
    width: 100%;
    margin-bottom: 1rem;
    border-collapse: collapse;
    display: block;
    overflow-x: auto;
}

.prose th,
.prose td {
    border: 1px solid var(--tw-prose-td-borders);
    padding: 0.5rem;
    text-align: left;
}

.prose th {
    border-color: var(--tw-prose-th-borders);
    background: var(--color-base-200);
    font-weight: 600;
}

.prose hr {
    border: none;
    border-top: 1px solid var(--tw-prose-hr);
    margin: 2rem 0;
}

.prose img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    margin: 1rem 0;
}


/* ==========================================================================
   Leaflet Map Theming (Dark Mode)
   ========================================================================== */

/* Popup styling */
.leaflet-popup-content-wrapper {
    background: var(--color-base-100);
    color: var(--color-base-content);
}

.leaflet-popup-tip {
    background: var(--color-base-100);
}

/* Map container defaults */
#map,
#node-map {
    border-radius: var(--radius-box);
}

#map {
    height: calc(100vh - 350px);
    min-height: 400px;
}

#node-map {
    height: 300px;
}

/* Map label visibility */
.map-label {
    opacity: 0;
    transition: opacity 0.15s ease-in-out;
}

.map-marker:hover .map-label {
    opacity: 1;
}

.show-labels .map-label {
    opacity: 1;
}

/* Bring hovered marker to front */
.leaflet-marker-icon:hover {
    z-index: 10000 !important;
}

/* ==========================================================================
   Node Header Hero Map Background
   ========================================================================== */

#header-map {
    height: 100%;
    width: 100%;
    z-index: 0;
}

/* Ensure Leaflet elements stay within the map layer */
#header-map .leaflet-pane,
#header-map .leaflet-control {
    z-index: auto !important;
}

/* ==========================================================================
   Observer Detail Rows
   Expandable sub-table showing per-observer signal/path data.
   ========================================================================== */

.observer-detail .observer-detail-content {
    padding: 0.5rem 1rem 0.5rem 2rem;
}

.observer-detail table {
    margin: 0;
}

.observer-badge {
    transition: background-color 0.15s ease;
}

.observer-badge:hover {
    background-color: color-mix(in oklch, var(--color-base-content) 15%, transparent);
}

.observer-badge-group {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

/* Mobile card observer details */
.observer-detail-card {
    padding: 0.5rem 0.75rem;
    margin-top: 0.25rem;
}

.observer-detail-card table {
    margin: 0;
    font-size: 0.8rem;
}

/* ==========================================================================
   Mobile Dropdown Tap Targets
   Larger touch targets and text for mobile dropdown menus.
   ========================================================================== */

@media (max-width: 1023px) {
    .navbar .dropdown .menu li > a {
        padding-top: 0.625rem;
        padding-bottom: 0.625rem;
        font-size: 0.9375rem;
    }

    .dropdown.dropdown-open #mobile-nav,
    .dropdown:focus-within #mobile-nav {
        display: block;
        column-count: 2;
        column-gap: 0.25rem;
        width: min(90vw, 20rem);
    }

    #mobile-nav > li {
        break-inside: avoid;
    }
}

/* ==========================================================================
   Footer Two-Column Layout
   ========================================================================== */

footer.footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}

@media (min-width: 1024px) {
    footer.footer {
        gap: 3rem;
    }
}

/* ==========================================================================
   Flash Banner
   ========================================================================== */

#flash-banner,
#system-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Light mode: soften the network announcement (alert-warning) banner */
[data-theme="light"] #flash-banner {
    --alert-color: oklch(0.95 0.06 70);
    --alert-border-color: oklch(0.82 0.12 70);
    color: oklch(0.33 0.07 46);
}

/* Light mode: boost stat label contrast on tinted panels */
[data-theme="light"] .stat-title,
[data-theme="light"] .stat-desc {
    color: color-mix(in oklab, var(--color-base-content) 80%, transparent);
}

.flash-banner-content {
    display: inline;
}

.flash-banner-content a {
    text-decoration: underline;
    font-weight: 600;
}

.flash-banner-content a:hover {
    opacity: 0.8;
}

.flash-banner-content code {
    font-size: 0.875rem;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    background: oklch(var(--b3) / 0.5);
}

.flash-banner-content p {
    display: inline;
    margin: 0;
}

.flash-banner-content p + p {
    display: block;
    margin-top: 0.25rem;
}
