/* Tailwind CSS - Include via CDN in index.html */
/* This file contains custom overrides and utility classes */

/* ════════════════════════════════════════════════════════════════════════
   DESIGN TOKENS — single source of truth (see .claude/ui-redesign-plan.md)

   Surfaces (dark):  page slate-900 #0f172a · panel/card slate-800 #1e293b
                     nested well/hover slate-700/50 · border subtle slate-700
                     #334155 · border strong slate-600 #475569
   Text (dark):      primary slate-100 #f1f5f9 · secondary slate-400 #94a3b8
                     muted slate-500 #64748b — muted ONLY for disabled/
                     decorative, never body text (≈3:1 on slate-800, fails AA)
   Semantic:         success green-500 · danger red-500 · warning amber-500
                     info sky-500 · brand teal-500 #14b8a6
   Type scale:       11px uppercase section labels (tracking-wider) · 12px
                     captions/counts · 13px dense rows (tree, info rows) ·
                     14px default UI · 16px panel titles · 18–24px headings.
                     Telemetry numbers always tabular-nums.
   Spacing:          4px grid. Rows: tree 28px · nav 36px · info ~32px ·
                     inputs/buttons 36px.
   Radius:           rounded-md 6px small controls · rounded-lg 8px buttons/
                     cards/overlays · rounded-xl 12px page-level panels only.
   z-index:          10 in-card dropdowns · 50 app header/user menu · map
                     chrome 500 / move editor + loading 700 (Leaflet's own
                     controls are z 800 inside the map — never share their
                     corner) · 999/1000 mobile scrim + sidebar · 9999 error UI.
   ════════════════════════════════════════════════════════════════════════ */

/* Root variables for theming */
:root {
    --color-primary: #14b8a6;
    --color-primary-hover: #0d9488;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
}

/* Dark mode background */
.dark {
    color-scheme: dark;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Input field styles */
.input-field {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    background-color: white;
    font-size: 0.875rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.input-field:focus {
    outline: none;
    border-color: #14b8a6;
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.1);
}

.dark .input-field {
    background-color: #1e293b;
    border-color: #475569;
    color: #f1f5f9;
}

.dark .input-field:focus {
    border-color: #14b8a6;
}

/* Button styles */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 2.25rem;
    padding: 0 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: white;
    cursor: pointer;
    background-color: #14b8a6;
    border-radius: 0.5rem;
    transition: background-color 0.15s;
}

.btn-primary:hover {
    background-color: #0d9488;
}

.btn-primary:active {
    background-color: #0f766e;
}

.btn-primary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.4);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 2.25rem;
    padding: 0 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    background-color: #f3f4f6;
    border-radius: 0.5rem;
    transition: background-color 0.15s;
}

.btn-secondary:hover {
    background-color: #e5e7eb;
}

.btn-secondary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.4);
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.dark .btn-secondary {
    color: #e5e7eb;
    background-color: #374151;
}

.dark .btn-secondary:hover {
    background-color: #4b5563;
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 2.25rem;
    padding: 0 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    background-color: transparent;
    border-radius: 0.5rem;
    transition: background-color 0.15s, color 0.15s;
}

.btn-ghost:hover {
    background-color: #f3f4f6;
    color: #111827;
}

.dark .btn-ghost {
    color: #94a3b8;
}

.dark .btn-ghost:hover {
    background-color: rgba(51, 65, 85, 0.5);
    color: #f1f5f9;
}

.btn-ghost:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.4);
}

.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 2.25rem;
    padding: 0 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: white;
    cursor: pointer;
    background-color: #ef4444;
    border-radius: 0.5rem;
    transition: background-color 0.15s;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-danger:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.4);
}

.btn-danger:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Dark basemap (class toggled by leaflet-interop setBasemap):
   - container background matches tiles so sub-pixel tile seams (Windows
     display scaling) don't show as a grey grid
   - brightness filter lifts CARTO Dark Matter to a readable mid-dark grey */
.dark-basemap {
    background: #0e1114 !important;
}

.dark-basemap .leaflet-tile {
    filter: brightness(1.7) contrast(0.95) saturate(1.1);
}

/* Map chrome — shared style for all map-corner overlays (filter, reposition,
   legend, move editor). Keep corners clear of Leaflet's own controls (z 800). */
.map-chrome {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.dark .map-chrome {
    background: rgba(30, 41, 59, 0.95);
    border-color: #334155;
}

/* Leaflet map overrides */
.leaflet-container {
    font-family: inherit;
}

.leaflet-popup-content-wrapper {
    border-radius: 0.5rem;
}

.leaflet-popup-content {
    margin: 0.75rem 0.875rem;
    font-size: 13px;
    line-height: 1.5;
}

.dark .leaflet-popup-content-wrapper {
    background: #1e293b;
    color: #f1f5f9;
    border: 1px solid #334155;
}

.dark .leaflet-popup-tip {
    background: #1e293b;
}

.dark .leaflet-container a.leaflet-popup-close-button {
    color: #94a3b8;
}

/* Popup typography (markup built in leaflet-interop.js) */
.popup-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 2px;
}

.popup-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    margin-bottom: 4px;
}

.popup-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 9999px;
    flex: none;
}

.popup-meta {
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    color: #6b7280;
    line-height: 1.5;
}

.dark .popup-meta {
    color: #94a3b8;
}

/* Popup details button (markup built in leaflet-interop.js) */
.popup-details-btn {
    display: block;
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.375rem 0.75rem;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    color: white;
    cursor: pointer;
    background-color: #14b8a6;
    border: none;
    border-radius: 0.375rem;
    transition: background-color 0.15s;
}

.popup-details-btn:hover {
    background-color: #0d9488;
}

/* Custom marker styles */
.custom-marker {
    background: transparent !important;
    border: none !important;
}

/* Marker cluster bubbles — replace the library's lime green with brand teal;
   muted variant on the dark basemap */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
    background-color: rgba(20, 184, 166, 0.25) !important;
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
    background-color: #14b8a6 !important;
    color: #ffffff !important;
    font-family: 'Inter', system-ui, sans-serif !important;
    font-weight: 600;
}

.dark-basemap .marker-cluster-small,
.dark-basemap .marker-cluster-medium,
.dark-basemap .marker-cluster-large {
    background-color: rgba(58, 169, 156, 0.25) !important;
}

.dark-basemap .marker-cluster-small div,
.dark-basemap .marker-cluster-medium div,
.dark-basemap .marker-cluster-large div {
    background-color: #2d8a7f !important;
}

/* ── Stat cards ─────────────────────────────────────────────────────────────
   Subtle hover lift for KPI cards (StatCard + page-local stat panels).
   Transform-only (no layout shift); transparent border reserves the 1px so
   the brighten-on-hover doesn't nudge content. */
.stat-card {
    border: 1px solid transparent;
    transition: transform 0.18s ease-out, border-color 0.18s ease-out, box-shadow 0.18s ease-out;
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: rgba(20, 184, 166, 0.35);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

.dark .stat-card:hover {
    border-color: rgba(20, 184, 166, 0.30);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

/* ── ApexCharts tooltip polish (default box is flat + Helvetica-grey) ──────── */
.apexcharts-tooltip {
    border-radius: 0.5rem !important;
    border: 1px solid #e5e7eb !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16) !important;
}

.apexcharts-tooltip.apexcharts-theme-dark {
    background: rgba(30, 41, 59, 0.97) !important;   /* slate-800 */
    border: 1px solid #334155 !important;            /* slate-700 */
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45) !important;
}

.apexcharts-tooltip-title {
    font-weight: 600 !important;
}

.apexcharts-tooltip.apexcharts-theme-dark .apexcharts-tooltip-title {
    background: rgba(15, 23, 42, 0.55) !important;   /* slate-900 strip */
    border-bottom: 1px solid #334155 !important;
}

.apexcharts-tooltip-marker {
    border-radius: 9999px;
}

/* Animation utilities */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.animate-spin {
    animation: spin 1s linear infinite;
}

/* Transition utilities */
.transition-all {
    transition-property: all;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 150ms;
}

/* Focus ring */
.focus-ring:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.5);
}

/* Visible keyboard focus for plain interactive elements (tree rows, tabs,
   segmented controls, icon buttons) without affecting mouse clicks */
.focus-ring-kb:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.6);
}

/* Reduced motion: drop decorative animation, keep loading spinners */
@media (prefers-reduced-motion: reduce) {
    .animate-pulse {
        animation: none;
    }

    .stat-card,
    .stat-card:hover {
        transform: none;
        transition: none;
    }
}

/* ── Flatpickr dark-mode overrides (app toggles .dark on <html>) ───────────── */
html.dark .flatpickr-calendar {
    background: #1e293b;            /* slate-800 */
    border: 1px solid #334155;     /* slate-700 */
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    color: #e2e8f0;                /* slate-200 */
}

/* the little arrow pointing at the input */
html.dark .flatpickr-calendar.arrowTop:before,
html.dark .flatpickr-calendar.arrowTop:after { border-bottom-color: #334155; }
html.dark .flatpickr-calendar.arrowBottom:before,
html.dark .flatpickr-calendar.arrowBottom:after { border-top-color: #334155; }

html.dark .flatpickr-months .flatpickr-month,
html.dark .flatpickr-current-month,
html.dark .flatpickr-current-month input.cur-year { color: #e2e8f0; }

html.dark .flatpickr-monthDropdown-months { background: #1e293b; color: #e2e8f0; }
html.dark .flatpickr-weekday { color: #94a3b8; }   /* slate-400 */

html.dark .flatpickr-prev-month svg,
html.dark .flatpickr-next-month svg { fill: #cbd5e1; }
html.dark .flatpickr-prev-month:hover svg,
html.dark .flatpickr-next-month:hover svg { fill: #14b8a6; }

html.dark .flatpickr-day { color: #e2e8f0; }
html.dark .flatpickr-day:hover { background: #334155; border-color: #334155; }
html.dark .flatpickr-day.today { border-color: #14b8a6; }
html.dark .flatpickr-day.flatpickr-disabled,
html.dark .flatpickr-day.prevMonthDay,
html.dark .flatpickr-day.nextMonthDay { color: #64748b; }   /* slate-500 */

/* selection + range highlight (teal to match the app accent) */
html.dark .flatpickr-day.selected,
html.dark .flatpickr-day.startRange,
html.dark .flatpickr-day.endRange,
html.dark .flatpickr-day.selected:hover,
html.dark .flatpickr-day.startRange:hover,
html.dark .flatpickr-day.endRange:hover {
    background: #14b8a6;
    border-color: #14b8a6;
    color: #ffffff;
}
html.dark .flatpickr-day.inRange {
    background: #134e4a;            /* deep teal */
    border-color: #134e4a;
    box-shadow: -5px 0 0 #134e4a, 5px 0 0 #134e4a;
}
