﻿        :root {
            /* Variables injected for Popup and Measuring Tools */
            --bg-panel: #242220; 
            --bg-panel-hover: #302E2B;
            --text-primary: #EAE6DF;
            --text-secondary: #9E9A94;
            --danger: #B56A5B;
            --warning: #C49153;
            --success: #748270;
            --border-light: #3A3734;
            --border-radius: 12px;
            --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.25), 0 1px 3px rgba(0, 0, 0, 0.15);
            --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.4);
            --font-family: 'Manrope', sans-serif;
        }

        /* --- GLOBAL APP THEME --- */
        body, html { 
            margin: 0; padding: 0; width: 100%; height: 100%; 
            font-family: var(--font-family); 
            overflow: hidden; 
            background-color: #F4F1EA; 
            color: #3E3832;
        }

        #map { position: fixed; inset: 0; width: 100%; height: 100dvh; touch-action: none; z-index: 1; }
        
        /* OVERLAYS & MODALS */
        .overlay-bg {
            position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(62, 56, 50, 0.6); z-index: 9999;
            display: flex; justify-content: center; align-items: center;
            backdrop-filter: blur(4px); transition: opacity 0.3s ease;
        }
        .modal-box {
            background: #FFFFFF; padding: 35px 25px; border-radius: 16px; width: 320px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.15); text-align: center; border: 1px solid #E8E2D9;
        }
        .modal-box h2 { color: #3E3832; margin: 0 0 10px 0; font-size: 22px; }
        .modal-box p { color: #8E867D; font-size: 13px; margin: 0 0 20px 0; }
        .modal-box input, .modal-box select, .modal-box textarea {
            width: 100%; padding: 12px; margin: 8px 0; border-radius: 8px;
            border: 1px solid #E8E2D9; box-sizing: border-box;
            background: #FCFAF6; color: #3E3832; outline: none; font-size: 14px; font-family: inherit;
        }
        .modal-btn-row { display: flex; gap: 10px; margin-top: 15px; }
        .modal-btn-row button { flex: 1; padding: 12px; border: none; border-radius: 8px; font-weight: bold; cursor: pointer; font-size: 15px; transition: background 0.2s; }
        .btn-primary { background: #6B705C; color: white; } .btn-primary:hover { background: #5a5f4d; }
        .btn-secondary { background: #F4F1EA; color: #8E867D; } .btn-secondary:hover { background: #E8E2D9; }
        .error-msg { color: #C46B63; font-size: 13px; margin-top: 10px; display: none; text-align: left; }

        /* MINIMAL TOP-LEFT CONTROL */
        #sidebar { 
            position: absolute; top: 20px; left: 20px; z-index: 10;
            display: flex; flex-direction: column; gap: 8px;
        }
        .compact-signout-btn { 
            background: #FFFFFF; color: #C46B63; border: 1px solid #E8E2D9; 
            padding: 8px 16px; border-radius: 20px; font-weight: 600; font-size: 13px; 
            cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.12); 
            transition: background 0.2s, border-color 0.2s; outline: none;
        }
        .compact-signout-btn:hover { background: #fff5f4; border-color: #f5d6d3; }

        /* FLOATING DRAWING TOOLBAR */
        #draw-toolbar, #edit-toolbar {
            position: absolute; bottom: 40px; left: 50%; transform: translateX(-50%);
            background: #FFFFFF; padding: 8px; border-radius: 40px; display: flex; gap: 8px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.15); z-index: 100; display: none; border: 1px solid #E8E2D9; pointer-events: auto;
        }
        .draw-btn {
            background: #F4F1EA; color: #3E3832; border: none; padding: 10px 16px;
            border-radius: 20px; cursor: pointer; font-size: 13px; font-weight: bold; display: flex; align-items: center; gap: 6px;
        }
        .draw-btn.active { background: #3E3832; color: #FFFFFF; }
        #cancel-draw-btn, #cancel-edit-btn { background: #ffebeb; color: #C46B63; }
        #finish-line-btn { display: none; background: #d4edda; color: #155724; }
        #save-edit-btn { background: #d4edda; color: #155724; }

        /* RIGHT SIDE CONTROLS */
        #custom-controls { position: absolute; top: 120px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 10; }
        .map-ui-btn { width: 44px; height: 44px; padding: 0; background: rgba(255,255,255,0.96); color: #28445f; border: 1px solid #d9e4ec; border-radius: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 5px 16px rgba(28,61,87,0.16); transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.2s, box-shadow 0.2s; }
        .map-ui-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
        .map-ui-btn.is-busy { opacity: 0.55; }
        .map-ui-btn:hover { background: #e9f7f6; border-color: #8ed8d2; color: #153d58; transform: translateY(-1px); box-shadow: 0 7px 18px rgba(28,61,87,0.2); }
        #edit-mode-btn.active { background: #e85d4a; border-color: #e85d4a; color: white; box-shadow: 0 6px 16px rgba(232,93,74,0.28); }
        #measure-btn.active { background: #188f9f; border-color: #188f9f; color: white; box-shadow: 0 6px 16px rgba(24,143,159,0.28); }
        #clear-btn { background: #fff5f3; color: #b74638; border-color: #f1c5be; }
        #clear-btn:hover { background: #e85d4a; border-color: #e85d4a; color: white; }
        
        /* MapLibre Modern Overrides */
        .maplibregl-ctrl-logo { display: none !important; }
        .maplibregl-popup-content { 
            background: var(--bg-panel); border: 1px solid var(--border-light);
            border-radius: var(--border-radius); box-shadow: var(--shadow-lg); 
            padding: 24px; color: var(--text-primary); font-family: var(--font-family);
            max-height: 80vh; overflow-y: auto;
        }
        .maplibregl-popup-content::-webkit-scrollbar, select::-webkit-scrollbar {
            width: 6px;
        }
        .maplibregl-popup-content::-webkit-scrollbar-thumb, select::-webkit-scrollbar-thumb {
            background: var(--border-light);
            border-radius: 3px;
        }
        .maplibregl-popup-close-button { 
            font-size: 22px; color: var(--text-secondary); padding: 8px 12px; outline: none; transition: color 0.3s;
        }
        .maplibregl-popup-close-button:hover { color: var(--danger); background: transparent; }
        .maplibregl-popup.fixed-screen-popup {
            position: fixed !important;
            top: 50% !important;
            left: 50% !important;
            right: auto !important;
            bottom: auto !important;
            z-index: 200;
            transform: translate(-50%, -50%) !important;
            max-width: calc(100vw - 32px) !important;
        }
        .fixed-screen-popup .maplibregl-popup-content {
            width: min(340px, calc(100vw - 32px));
            max-height: calc(100vh - 32px);
            box-sizing: border-box;
        }
        .fixed-screen-popup .maplibregl-popup-tip { display: none; }
        .maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--bg-panel); }
        .maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--bg-panel); }
        .maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--bg-panel); }
        .maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--bg-panel); }
        .popup-edit-btn { margin-top: 15px; width: 100%; padding: 8px; background: rgba(255,255,255,0.1); border: 1px solid var(--border-light); border-radius: 6px; cursor: pointer; font-weight: bold; color: var(--text-primary); }
            .paddock-card { width: 100%; max-width: 300px; box-sizing: border-box; color: #263746; font-family: var(--font-family); background: #FFFFFF; }
            .paddock-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid #E3E9ED; }
            .paddock-card-kicker, .paddock-card-label { color: #71808C; font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; }
            .paddock-card-kicker { margin-bottom: 4px; }
            .paddock-card-title { margin: 0; color: #203443; font-size: 19px; line-height: 1.2; font-weight: 800; overflow-wrap: anywhere; }
            .paddock-status-dot { width: 10px; height: 10px; margin-top: 5px; border: 2px solid #FFFFFF; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 0 1px #D8E0E5; }
            .paddock-card-field { margin-bottom: 14px; }
            .paddock-card-label { display: block; margin-bottom: 6px; }
            .paddock-status-list { display: grid; gap: 6px; max-height: 156px; overflow-y: auto; padding-right: 2px; }
            .paddock-status-option { display: flex; align-items: center; gap: 9px; width: 100%; box-sizing: border-box; padding: 8px 9px; border: 1px solid #D6E0E6; border-radius: 7px; background: #F7FAFB; color: #263746; font: inherit; font-size: 12px; text-align: left; cursor: pointer; }
            .paddock-status-option:hover { background: #EAF3F6; border-color: #A7C5D1; }
            .paddock-status-option.is-selected { background: #EAF3F6; border-color: #7AA6B8; font-weight: 700; }
            .paddock-status-swatch { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 0 1px rgba(32,52,67,0.16); }
            .paddock-card-area { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0 14px; border-top: 1px solid #E3E9ED; color: #71808C; font-size: 12px; }
            .paddock-card-area strong { color: #263746; font-weight: 700; }
            .paddock-card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
            .paddock-card-actions .popup-edit-btn { margin: 0; min-width: 0; padding: 9px 6px; background: #F7FAFB; border: 1px solid #D6E0E6; color: #355264; font-size: 12px; }
            .paddock-card-actions .popup-edit-btn:hover { background: #EAF3F6; border-color: #A7C5D1; }

        select option {
            background: var(--bg-panel);
            color: var(--text-primary);
            padding: 8px;
        }

        /* Measurement styling */
        .measure-point { 
            width: 9px; height: 9px; background-color: var(--bg-panel); 
            border: 2px solid var(--warning); border-radius: 50%; cursor: grab; box-shadow: 0 2px 6px rgba(0,0,0,0.28); 
        }
        .measure-point:active { cursor: grabbing; }
        .distance-label { 
            background: rgba(36,34,32,0.92); padding: 3px 6px; border-radius: 5px; font-weight: 500; 
            font-size: 10px; color: var(--text-primary); border: 1px solid var(--border-light); 
            pointer-events: none; white-space: nowrap; box-shadow: 0 2px 7px rgba(0,0,0,0.25); 
        }
