*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    background: #0f1b2d;
    color: #eee;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ==================== TOOLBAR ==================== */
#dashboard-toolbar {
    height: 48px;
    min-height: 48px;
    background: #0a1628;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 0.6rem;
    z-index: 1000;
    flex-shrink: 0;
}

.toolbar-back {
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    font-size: 0.8rem;
    white-space: nowrap;
    transition: color 0.15s;
    flex-shrink: 0;
}
.toolbar-back:hover { color: #fff; }

.toolbar-title {
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
    white-space: nowrap;
    flex-shrink: 0;
}

.toolbar-badge {
    background: #ff8c00;
    color: #000;
    font-size: 0.58rem;
    font-weight: 800;
    padding: 2px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.toolbar-spacer { flex: 1; }

.toolbar-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #eee;
    padding: 0.28rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.78rem;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
    flex-shrink: 0;
}
.toolbar-btn:hover { background: rgba(255, 255, 255, 0.16); border-color: rgba(255,255,255,0.3); }
.toolbar-btn.primary {
    background: rgba(0, 102, 204, 0.3);
    border-color: rgba(0, 102, 204, 0.6);
    color: #7dc3ff;
}
.toolbar-btn.primary:hover {
    background: rgba(0, 102, 204, 0.5);
    border-color: rgba(0, 102, 204, 0.9);
}

.toolbar-select {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #eee;
    padding: 0.28rem 0.5rem;
    border-radius: 4px;
    font-size: 0.78rem;
    cursor: pointer;
    max-width: 160px;
    flex-shrink: 0;
}
.toolbar-select option { background: #0d1f35; color: #eee; }

/* ==================== GRID CANVAS ==================== */
#dashboard-grid {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem;
    min-height: 0;
}

/* Gridstack item content wrapper */
.grid-stack-item-content {
    background: #0d1f35;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ==================== WIDGET ==================== */
.widget-header {
    height: 32px;
    min-height: 32px;
    background: #091525;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    padding: 0 8px;
    gap: 8px;
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
    position: relative;
}
.widget-header:active { cursor: grabbing; }

/* Title + settings gear — absolutely centered as a group */
.widget-title-group {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    pointer-events: all;
    z-index: 1;
}

.widget-title {
    font-size: 0.72rem;
    font-weight: 600;
    color: #b8d4ef;
    white-space: nowrap;
}

.widget-settings-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.35);
    cursor: pointer;
    font-size: 0.8rem;
    line-height: 1;
    padding: 0 2px;
    transition: color 0.15s;
}
.widget-settings-btn:hover { color: rgba(255, 255, 255, 0.85); }

.widget-close-btn { margin-left: auto; }

/* ==================== SETTINGS PANEL ==================== */
.widget-settings-panel {
    position: absolute;
    top: 32px;       /* sits just below the header */
    right: 0;
    width: 264px;
    background: #0a1628;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-top: none;
    border-radius: 0 0 6px 6px;
    z-index: 1000;
    overflow-y: auto;
    max-height: calc(100% - 36px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.widget-settings-panel.hidden { display: none; }

.sp-section {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.sp-section:last-child { border-bottom: none; }

.sp-section-title {
    font-size: 0.65rem;
    font-weight: 700;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.45rem;
}

.sp-check, .sp-radio {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: #cde;
    cursor: pointer;
    padding: 2px 0;
}
.sp-check input, .sp-radio input { cursor: pointer; accent-color: #4d96ff; }

/* ── Overlay style controls (gear icon per overlay) ── */
.sp-overlay-item {
    margin-bottom: 2px;
}
.sp-overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sp-overlay-gear {
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.35);
    cursor: pointer;
    font-size: 0.7rem;
    width: 20px;
    height: 20px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    flex-shrink: 0;
}
.sp-overlay-gear:hover {
    color: rgba(255,255,255,0.85);
    border-color: rgba(77,150,255,0.5);
    background: rgba(77,150,255,0.15);
}
.sp-overlay-settings {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 5px 0 5px 22px;
}
.sp-overlay-settings.hidden { display: none; }

.sp-setting-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.68rem;
    color: #9bb;
}
.sp-setting-row > span:first-child {
    min-width: 40px;
}
.sp-setting-row input[type="range"] {
    flex: 1;
    height: 3px;
    accent-color: #4d96ff;
    cursor: pointer;
}
.sp-setting-row input[type="color"] {
    width: 24px;
    height: 18px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 3px;
    background: transparent;
    cursor: pointer;
    padding: 0;
}
.sp-setting-value {
    min-width: 30px;
    text-align: right;
    color: #6ddc6d;
    font-size: 0.65rem;
}

.sp-basemap-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.sp-unit-row {
    display: flex;
    gap: 1rem;
}

.widget-timestamp {
    font-size: 0.65rem;
    color: #5b8ab5;
    white-space: nowrap;
    flex-shrink: 0;
}

.widget-refresh-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #0CFC20;
    flex-shrink: 0;
    transition: background 0.3s;
    position: relative;
    cursor: default;
}
.widget-refresh-dot.loading { background: #ff8c00; }
.widget-refresh-dot::after {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(5, 15, 30, 0.95);
    color: #9ec8e0;
    font-size: 0.68rem;
    font-weight: 400;
    white-space: nowrap;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid rgba(77, 150, 255, 0.25);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 9999;
}
.widget-refresh-dot[data-tooltip]:hover::after { opacity: 1; }

.widget-close-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.3);
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    padding: 0 2px;
    flex-shrink: 0;
    transition: color 0.15s;
}
.widget-close-btn:hover { color: #f55; }

.widget-body {
    flex: 1;
    position: relative;
    min-height: 0;
}

.widget-body > div {
    position: absolute;
    inset: 0;
}

/* Leaflet container fills widget body */
.widget-body .leaflet-container {
    height: 100%;
    width: 100%;
}

/* ==================== SPC WATCH WIDGET ==================== */

.spc-watch-controls { margin-left: auto; }
.spc-watch-controls ~ .widget-close-btn { margin-left: 0; }

.spc-watch-select {
    background: rgba(255, 255, 255, 0.08);
    color: #9ec8e0;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 3px;
    font-size: 0.7rem;
    padding: 2px 5px;
    cursor: pointer;
    outline: none;
}
.spc-watch-select:hover { border-color: rgba(77, 150, 255, 0.5); }

/* Empty-state message layered over the map */
.spc-watch-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.85rem;
    pointer-events: none;
    z-index: 900;
}
.spc-watch-empty.hidden { display: none; }

/* Pointer cursor on clickable watch/MD polygons */
.spc-watch-polygon { cursor: pointer; }

/* ==================== OVERLAYS / MODALS ==================== */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.overlay.hidden { display: none; }

.overlay-box {
    background: #0d1f35;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    width: 420px;
    max-width: 95vw;
    max-height: 85vh;
    overflow-y: auto;
}

.overlay-header {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
}
.overlay-header h3 {
    margin: 0;
    flex: 1;
    font-size: 1rem;
    color: #cde;
}
.overlay-sub {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.5);
    margin: 0 0 1rem;
}

.overlay-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.4);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.15s;
}
.overlay-close:hover { color: #f55; }

/* Widget type picker grid */
.widget-type-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
}

.widget-type-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    padding: 0.85rem 0.75rem;
    cursor: pointer;
    text-align: left;
    color: #eee;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: background 0.15s, border-color 0.15s;
}
.widget-type-btn:hover:not(.disabled) {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 140, 0, 0.55);
}
.widget-type-btn.disabled {
    opacity: 0.38;
    cursor: not-allowed;
}
.wt-icon { font-size: 1.4rem; line-height: 1; }
.wt-label { font-weight: 600; font-size: 0.82rem; color: #cde; }
.wt-sub { font-size: 0.63rem; color: rgba(255,255,255,0.45); }

/* Save modal */
.save-form { margin-bottom: 1.25rem; }
.save-form label { font-size: 0.78rem; color: rgba(255,255,255,0.6); display: block; margin-bottom: 0.4rem; }
.save-input-row { display: flex; gap: 0.5rem; }
.save-input-row input[type="text"] {
    flex: 1;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #eee;
    padding: 0.35rem 0.6rem;
    border-radius: 4px;
    font-size: 0.82rem;
}
.save-input-row input[type="text"]:focus {
    outline: none;
    border-color: rgba(0, 102, 204, 0.7);
}

.btn-primary {
    background: #0066cc;
    border: none;
    color: #fff;
    padding: 0.35rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.82rem;
    white-space: nowrap;
    transition: background 0.15s;
}
.btn-primary:hover { background: #0077ee; }

.saved-layouts-section h4 {
    margin: 0 0 0.5rem;
    font-size: 0.82rem;
    color: rgba(255,255,255,0.55);
    font-weight: 500;
    border-top: 1px solid rgba(255,255,255,0.07);
    padding-top: 1rem;
}

#saved-layouts-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 200px;
    overflow-y: auto;
}
#saved-layouts-list li {
    display: flex;
    align-items: center;
    padding: 0.35rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    gap: 0.4rem;
    font-size: 0.8rem;
}
#saved-layouts-list li .layout-name { flex: 1; color: #cde; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#saved-layouts-list li .layout-ts { font-size: 0.65rem; color: rgba(255,255,255,0.35); white-space: nowrap; }
.layout-load-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    color: #eee;
    padding: 2px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.72rem;
    white-space: nowrap;
}
.layout-load-btn:hover { background: rgba(255,255,255,0.2); }
.layout-delete-btn {
    background: none;
    border: none;
    color: rgba(255, 80, 80, 0.5);
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0 3px;
    transition: color 0.15s;
}
.layout-delete-btn:hover { color: #f55; }

#saved-layouts-list .no-layouts {
    color: rgba(255,255,255,0.35);
    font-size: 0.75rem;
    padding: 0.5rem 0;
    font-style: italic;
}

/* ==================== EMPTY STATE ==================== */
#empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    pointer-events: none;
    z-index: 1;
}
#empty-state.hidden { display: none; }
#empty-state .empty-icon { font-size: 3rem; opacity: 0.25; }
#empty-state .empty-title { font-size: 1rem; color: rgba(255,255,255,0.3); font-weight: 600; }
#empty-state .empty-sub { font-size: 0.8rem; color: rgba(255,255,255,0.2); }

/* ==================== GRIDSTACK OVERRIDES ==================== */
.grid-stack-item > .grid-stack-item-content {
    inset: 4px;
}

/* Resize handles — bottom-left and bottom-right */
.grid-stack-item > .ui-resizable-sw,
.grid-stack-item > .ui-resizable-se {
    background: rgba(255, 140, 0, 0.4);
}

/* ==================== WIDGET LEGEND ==================== */
.widget-legend {
    position: absolute;
    top: 32px; /* just below the 32px widget header */
    left: 0;
    right: 0;
    z-index: 500;
    background: rgba(8, 18, 32, 0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px 14px;
    padding: 4px 10px;
    pointer-events: none;
}
.widget-legend.hidden { display: none; }

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.63rem;
    color: #dde;
    white-space: nowrap;
}

.legend-swatch {
    width: 14px;
    height: 10px;
    border-radius: 2px;
    border: 1px solid rgba(255,255,255,0.25);
    flex-shrink: 0;
}

/* ==================== SPC PLAYBACK CONTROLS ==================== */
.spc-playback {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    margin-left: auto;
}

/* When playback controls are present, the close button no longer needs to push itself right */
.spc-playback ~ .widget-close-btn {
    margin-left: 0;
}

.spc-pb-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #cde;
    padding: 0 5px;
    height: 20px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.65rem;
    line-height: 1;
    transition: background 0.15s;
    flex-shrink: 0;
}
.spc-pb-btn:hover { background: rgba(255, 255, 255, 0.2); }

/* ==================== SPC PROBABILITY LABELS ==================== */
.spc-prob-label {
    background: transparent;
    border: none;
    box-shadow: none;
    font-size: 0.72rem;
    font-weight: 700;
    color: #000;
    text-shadow: 0 0 3px #fff, 0 0 3px #fff;
    white-space: nowrap;
    pointer-events: none;
}

/* ==================== ALERT ME BUTTON ==================== */

.toolbar-btn.alert-me-btn {
    background: rgba(204, 80, 0, 0.3);
    border-color: rgba(204, 80, 0, 0.6);
    color: #ffb366;
}
.toolbar-btn.alert-me-btn:hover {
    background: rgba(204, 80, 0, 0.5);
    border-color: rgba(204, 80, 0, 0.9);
}

/* ==================== LEGAL BUTTON ==================== */

.toolbar-btn.legal-btn {
    background: #4a5568;
}
.toolbar-btn.legal-btn:hover {
    background: #5a6578;
}

/* ==================== LEGAL MODAL ==================== */

.legal-modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.82);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    overflow-y: auto;
    padding: 20px;
}
.legal-modal.hidden { display: none !important; }

.legal-modal-content {
    background: #1a2640;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    width: 100%;
    max-width: 860px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 32px rgba(0,0,0,0.6);
}

.legal-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}
.legal-modal-header h2 {
    color: #63b3ed;
    font-size: 1.2rem;
    margin: 0;
}

.legal-close-btn {
    background: none;
    border: none;
    color: #aaa;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}
.legal-close-btn:hover { color: #e74c3c; }

.legal-modal-body {
    padding: 24px;
    overflow-y: auto;
    color: #dde;
    font-size: 0.9rem;
    line-height: 1.6;
}

.legal-section { margin-bottom: 28px; }

.legal-section h3 {
    color: #63b3ed;
    font-size: 1rem;
    margin: 0 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.legal-section p { margin: 0 0 8px; }
.legal-section ul { margin: 0 0 8px 22px; }
.legal-section li { margin-bottom: 6px; }
.legal-section a { color: #63b3ed; text-decoration: none; }
.legal-section a:hover { text-decoration: underline; }

.warning-box {
    background: rgba(230, 126, 34, 0.2);
    border-left: 4px solid #e67e22;
    padding: 14px 16px;
    margin: 0 0 14px;
    border-radius: 4px;
}
.warning-box p { margin: 0 0 6px; color: #ffd; }
.warning-box p:last-child { margin: 0; }

.legal-footer {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
    text-align: center;
    color: #778;
    font-size: 0.8rem;
}

/* ==================== LSR WIDGET ICONS ==================== */

.lsr-widget-icon {
    width: 24px;
    height: 24px;
    display: block;
    filter: drop-shadow(0 0 2px rgba(0,0,0,0.8));
}
.lsr-widget-icon svg {
    width: 24px;
    height: 24px;
    overflow: visible;
}

.lsr-window-ctrl {
    display: flex;
    align-items: center;
}

.lsr-window-ctrl { margin-left: auto; }
.lsr-window-ctrl ~ .widget-close-btn { margin-left: 0; }

/* ── MRMS Rotation Track colorbar ─────────────────────────────────── */
/* Sits inside .leaflet-container (position:relative), above tile layers */
/* MRMS product dropdown — sits on the right of the widget header */
.mrms-product-select {
    background: rgba(9, 21, 37, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #b8d4ef;
    font-size: 0.68rem;
    padding: 1px 5px;
    border-radius: 3px;
    cursor: pointer;
    outline: none;
    margin-left: auto; /* push to right side of the header flex row */
    user-select: none;
    max-width: 160px;
}
.mrms-product-select:hover { border-color: rgba(255, 255, 255, 0.4); }
/* When the product select is present, the close button should not also auto-margin */
.widget-header:has(.mrms-product-select) .widget-close-btn { margin-left: 0; }

/* HRRR variable dropdown — wider to fit variable names + optgroup labels */
select.mrms-product-select[id^="hrrr-var-sel-"] {
    max-width: 240px;
    min-width: 140px;
}

.mrms-colorbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 42px;
    background: rgba(15, 18, 32, 0.88);
    backdrop-filter: blur(2px);
    padding: 4px 10px 2px;
    z-index: 1000;   /* above Leaflet tile layers (~400) but below popups (700+) */
    display: flex;
    flex-direction: column;
    gap: 1px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    pointer-events: none;  /* don't block map pan/zoom */
}
.mrms-colorbar-gradient {
    height: 12px;
    border-radius: 2px;
    border: 1px solid rgba(255,255,255,0.15);
}
.mrms-colorbar-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.62rem;
    color: #ccc;
    font-family: monospace;
    line-height: 1;
}
.mrms-colorbar-title {
    font-size: 0.6rem;
    color: #888;
    text-align: center;
    line-height: 1;
}
