:root {
    --primary-blue: #002c4d;
    --active-blue: #004070;
    --accent-blue: #6db9ff;
    --bg-light: #f8f9fa;
    --border-color: #ddd;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body, html { height: 100%; width: 100%; font-family: 'Segoe UI', sans-serif; overflow: hidden; }

.main-container { display: flex; flex-direction: column; height: 100vh; width: 100vw; }

/* Sidebar */
.sidebar {
    width: 100%; 
    height: 280px;
    order: 2;
    background: var(--bg-light); 
    border-top: 1px solid var(--border-color);
    display: flex; 
    flex-direction: row; 
    transition: 0.3s; 
    position: relative; 
    z-index: 2000;
}

.upgrade-link {
  color: #7aa8cc;
  text-decoration: none;
  transition: all 0.2s ease;
  border-bottom: 1px dotted rgba(122,168,204,0.4);
}

.upgrade-link:hover {
  color: #ffb830;
  border-bottom-color: #ffb830;
}

.sidebar.collapsed { margin-bottom: -280px; }

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Map Area */
#map-wrapper { flex-grow: 1; position: relative; height: auto; order: 1; }
#map { height: 100%; width: 100%; z-index: 1; }

/* Positioning native Leaflet controls adjacent to the Brand Bar */
.leaflet-top.leaflet-right {
    left: 330px !important;
    right: auto !important;
    top: 15px !important;
    margin: 0 !important;
    align-items: flex-start;
    display: flex;
    flex-direction: row;
}

.leaflet-top.leaflet-right .leaflet-control-layers {
    margin-top: 0 !important;
    margin-left: 0 !important;
    border: none !important;
    border-radius: 4px !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3) !important;
}

.leaflet-top.leaflet-right .leaflet-control-layers-toggle {
    width: 38px !important;
    height: 38px !important;
    background-size: 20px 20px !important;
}

.leaflet-right .leaflet-control-toolbar .leaflet-toolbar-actions,
.leaflet-right .leaflet-draw-actions,
.leaflet-right .leaflet-menu-container {
    left: 100% !important;
    right: auto !important;
    margin-left: 5px;
}

.leaflet-right .leaflet-toolbar-actions::before {
    left: -14px !important;
    right: auto !important;
    border-right-color: rgba(0,0,0,0.4);
    border-left-color: transparent !important;
}

.leaflet-bar {
    border: none !important;
    box-shadow: none !important;
}

/* Docked Feature Registry Panel */
#h2f-docked-registry {
    position: absolute;
    top: 150px;
    right: 10px;
    z-index: 1000;
    pointer-events: auto;
    width: 380px;
}
#h2f-selection-ext {
    position: absolute;
    top: 158px;
    right: 10px;
    z-index: 999;
    pointer-events: auto;
    width: 380px;
    display: none;
}

/* ═══════════════════════════════════════════════════════════════════════
   SUBSCRIPTION PLAN GATING — CSS LAYER
   Default: hide sensitive UI; reveal only when correct plan class is
   applied to <html> by auth-guard.js.
═══════════════════════════════════════════════════════════════════════ */

/* ── Coordinate Display Box ──────────────────────────────────────────── */
/* Hidden by default — only shown for standard and pro */
.coordinate-display {
    position: absolute; 
    top: 10px; 
    right: 10px; 
    z-index: 1000;
    background: white; 
    padding: 12px; 
    border-radius: 4px; 
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    min-width: 220px; 
    pointer-events: auto;

    /* Hidden for basic plan by default */
    display: none;
}

/* Show coordinate display for standard and pro */
:root.plan-standard .coordinate-display,
:root.plan-pro .coordinate-display {
    display: block;
}

.coordinate-display h3 { font-size: 14px; margin-bottom: 8px; border-bottom: 1px solid #eee; }
.coord-row { font-size: 12px; margin: 4px 0; color: #444; }

/* ── Lat/Lon REDACTION for standard plan ─────────────────────────────── */
/* Standard sees "LOCKED" instead of real values — JS handles the text,
   CSS provides the visual style */
:root.plan-standard .coord-gated {
    color: #bbb !important;
    font-style: italic;
    letter-spacing: 0.05em;
}

/* ── Pro Draw Tools Spacing & Overlap Fix ── */
.leaflet-top.leaflet-left .leaflet-draw {
    margin-top: 10px !important;  /* Fix for the continuous left tools */
    clear: both !important;       
    position: relative;           
    z-index: 1000;
}


/* ── Map Feature Registry (Black Box) ────────────────────────────────── */
/* Hidden for basic; shown for standard and pro */
#h2f-docked-registry {
    display: none;
}

:root.plan-standard #h2f-docked-registry,
:root.plan-pro #h2f-docked-registry {
    display: block;
}

/* ── Plan-gated UI elements (districts, scientific layers) ────────────── */
/* base state: normal */
.plan-gated {
    position: relative;
}

/* BASIC: ghost disabled layers — visible but unusable */
:root.plan-basic .plan-gated--district,
:root.plan-basic .plan-gated--scientific {
    opacity: 0.38;
    filter: grayscale(80%);
    pointer-events: none;
    user-select: none;
    cursor: not-allowed;
}

/* Add a "🔒 Upgrade" badge on ghosted items */
:root.plan-basic .plan-gated--district::after,
:root.plan-basic .plan-gated--scientific::after {
    content: '🔒 Upgrade required';
    display: block;
    font-size: 9px;
    color: #ffb830;
    font-family: monospace;
    letter-spacing: 0.05em;
    padding: 2px 15px 6px;
    opacity: 0.8;
}

/* Don't add the badge text inside top-bar pill buttons */
:root.plan-basic .map-ctrl-check.plan-gated--district::after,
:root.plan-basic .map-ctrl-check.plan-gated--scientific::after {
    content: none;
}

/* STANDARD: districts enabled, scientific layers enabled */
:root.plan-standard .plan-gated--district,
:root.plan-standard .plan-gated--scientific,
:root.plan-pro .plan-gated--district,
:root.plan-pro .plan-gated--scientific {
    opacity: 1;
    filter: none;
    pointer-events: auto;
    cursor: default;
}

/* ── Plan upgrade hint banner ─────────────────────────────────────────── */
/* Shown only to basic and standard users, inside the sidebar */
.plan-upgrade-hint {
    display: none;
    margin: 10px;
    padding: 8px 10px;
    background: rgba(255,184,48,0.08);
    border: 1px solid rgba(255,184,48,0.25);
    border-radius: 5px;
    font-size: 10px;
    color: #c48a00;
    font-family: monospace;
    line-height: 1.5;
}

:root.plan-basic .plan-upgrade-hint,
:root.plan-standard .plan-upgrade-hint {
    display: block;
}

/* ── Feature registry item states for standard plan ──────────────────── */
/* Export and navigate items are visible but disabled for standard */
:root.plan-standard .h2f-ctx-item[data-restricted="true"] {
    opacity: 0.4;
    pointer-events: none;
    cursor: not-allowed;
}

/* ── Zoom-level warning toast (injected by map-init.js) ──────────────── */
.zoom-limit-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    background: rgba(20, 10, 0, 0.92);
    border: 1px solid rgba(255, 184, 48, 0.35);
    border-radius: 6px;
    padding: 8px 16px;
    font-family: 'Segoe UI', sans-serif;
    font-size: 12px;
    color: #ffb830;
    box-shadow: 0 4px 20px rgba(0,0,0,0.45);
    pointer-events: none;
    animation: zltoast-in 0.2s ease both;
}
@keyframes zltoast-in {
    from { opacity: 0; bottom: 70px; }
    to   { opacity: 1; bottom: 80px; }
}

/* ══════════════════════════════════════════════════════════════════════ */

/* Bookmark Panel */
.bookmarks-panel {
    position: absolute;
    top: 180px;
    right: 80px;
    width: 250px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 1001;
}

.bookmark-item {
    padding: 8px; 
    margin-bottom: 5px; 
    background: #f1f3f5;
    border-radius: 4px; 
    cursor: pointer; 
    font-size: 12px;
}
.input-group { display: flex; gap: 5px; margin-top: 10px; }
.input-group input { flex: 1; padding: 5px; border: 1px solid #ddd; }
.bookmark-add-btn { 
    padding: 5px 10px; 
    background: var(--primary-blue); 
    color: white; 
    border: none; 
    cursor: pointer; 
}

/* ── Sidebar Tab Rail (left edge of bottom pane) ── */
.sidebar-tab-rail {
    width: 160px;
    flex-shrink: 0;
    background: var(--primary-blue);
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tab-btn {
    flex: none;
    padding: 14px 12px;
    border: none;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    border-right: 3px solid transparent;
    background: none;
    color: rgba(255,255,255,0.55);
    cursor: pointer;
    font-size: 11px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s, color 0.2s, border-right-color 0.2s;
    font-family: 'Segoe UI', sans-serif;
    letter-spacing: 0.03em;
}

.tab-btn:hover {
    background: rgba(255,255,255,0.07);
    color: rgba(255,255,255,0.85);
}

.tab-btn.active {
    background: rgba(255,255,255,0.1);
    color: white;
    border-right-color: var(--accent-blue);
    font-weight: 600;
}

.tab-icon {
    font-size: 14px;
    opacity: 0.8;
    line-height: 1;
}

.tab-label {
    font-size: 11px;
    line-height: 1.3;
}

.sidebar-toggle {
    position: absolute; 
    left: 50%; 
    top: -20px; 
    transform: translateX(-50%);
    width: 60px; 
    height: 20px; 
    background: white; 
    border: 1px solid var(--border-color);
    border-bottom: none; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    cursor: pointer; 
    border-radius: 6px 6px 0 0; 
    font-size: 10px; 
    color: var(--primary-blue);
    font-weight: bold;
    z-index: 2001;
    box-shadow: 0 -3px 8px rgba(0, 0, 0, 0.05);
    transition: background-color 0.2s ease, color 0.2s ease, height 0.2s ease, top 0.2s ease;
}

.sidebar-toggle:hover {
    background: #f1f3f5;
    color: var(--active-blue);
    height: 22px;
    top: -22px;
}

/* ── Tab Content ── */
.tab-content {
    display: none;
    height: 100%;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

.pane-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ── Layer Cards (replaces .tree-group) ── */
.layer-card {
    background: white;
    border: 1px solid #e8ecf0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    transition: box-shadow 0.2s;
}

.layer-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.layer-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #f8f9fb, #f1f4f8);
    border-bottom: 1px solid #eaecf0;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.layer-card-header:hover {
    background: linear-gradient(135deg, #eef1f6, #e8ecf4);
}

.lc-arrow {
    font-size: 10px;
    color: #6b8aad;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.lc-title {
    font-size: 12px;
    font-weight: 600;
    color: #002c4d;
    letter-spacing: 0.02em;
    flex: 1;
}

.layer-card .group-items {
    display: none;
    padding: 4px 0;
}

.layer-card .group-items.expanded {
    display: block;
}

.layer-card .tree-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px 7px 30px;
    font-size: 11.5px;
    color: #3a4a5c;
    cursor: pointer;
    transition: background 0.12s;
    border-bottom: 1px solid rgba(0,0,0,0.03);
}

.layer-card .tree-item:last-child { border-bottom: none; }

.layer-card .tree-item:hover {
    background: rgba(0, 64, 112, 0.05);
}

/* ── Empty State ── */
.pane-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 30px;
    text-align: center;
    color: #8a9db5;
}

.pane-empty-icon {
    font-size: 36px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.pane-empty-title {
    font-size: 14px;
    font-weight: 600;
    color: #4a6480;
    margin-bottom: 10px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.pane-empty-body {
    font-size: 11.5px;
    line-height: 1.6;
    color: #8a9db5;
    max-width: 280px;
}

/* ── Inline Map Controls (State Borders & Mask beside layering btn) ── */
#map-inline-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
}

.map-ctrl-check {
    display: flex;
    align-items: center;
    gap: 5px;
    height: 38px;
    padding: 0 10px;
    background: #002c4d;
    color: rgba(255,255,255,0.8);
    font-size: 11px;
    font-family: 'Segoe UI', sans-serif;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    white-space: nowrap;
    transition: background 0.2s;
    user-select: none;
    box-sizing: border-box;
}

.map-ctrl-check:hover {
    background: #004070;
    color: white;
}

.map-ctrl-check input[type="checkbox"] {
    width: 13px;
    height: 13px;
    cursor: pointer;
    accent-color: #6db9ff;
    flex-shrink: 0;
}

/* Tree View Styling */
.group-header { 
    display: flex; 
    align-items: center; 
    padding: 10px 15px; 
    background: white; 
    border-bottom: 1px solid #eee; 
    cursor: pointer; 
}
.group-items { display: none; }
.group-items.expanded { display: block; }
.tree-item { 
    display: flex; 
    align-items: center; 
    padding: 8px 15px 8px 40px; 
    font-size: 12px; 
}

/* Upload Section */
.upload-section {
    padding: 15px;
    background: white;
    border-bottom: 1px solid #eee;
}

.upload-btn {
    width: 100%;
    padding: 10px;
    background: var(--primary-blue);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.contributors-section {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

.section-title {
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    color: #002c4d;
    margin-bottom: 15px;
    letter-spacing: 0.05em;
}

.member {
    display: flex;
    align-items: center;
    margin-bottom: 18px;
}

.member-img {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid #0a3d62;
    object-fit: cover;
    margin-right: 12px;
}

.member-info {
    display: flex;
    flex-direction: column;
}

.member-name {
    font-size: 13px;
    font-weight: 600;
    color: #002c4d;
}

.member-role {
    font-size: 11px;
    color: #000000;
}

.upload-btn:hover {
    background: var(--active-blue);
}

.info-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.memorial-card {
    margin-top: auto;
    padding: 10px;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(0,44,77,0.06), rgba(0,44,77,0.02));
    border: 1px solid rgba(0,44,77,0.15);
    text-align: center;
}

.brand-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
}

.brand-logo {
    filter: drop-shadow(0 0 2px rgba(0,44,77,0.3));
}

.group-header {
    display: flex;
    align-items: center;
    gap: 8px; /* controls spacing between arrow, checkbox, text */
}

.group-header .arrow {
    margin-right: 4px;
}

.group-header input[type="checkbox"] {
    margin-right: 6px;
}

/* PARTNER */
.partner-block {
    text-align: center;
    margin-bottom: 15px;
}

.partner-logo {
    width: 200px;
    height: auto;
    object-fit: contain;
    margin-bottom: 6px;
}

.partner-name {
    font-size: 13px;
    font-weight: 600;
    color: #002c4d;
}

.arrow {
    font-size: 12px;  /* reduce size */
}

/* COLLABORATORS */
.collab-group {
    text-align: center;
    margin-bottom: 12px;
}

.tree-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tree-item input[type="checkbox"] {
    margin-right: 6px;
}

.collab-subtitle {
    font-size: 15px;
    font-weight: 600;
    color: #002c4d;
    margin-bottom: 4px;
}

.collab-list div {
    font-size: 11px;
    color: #555;
}

/* ACKNOWLEDGEMENT */
.ack-list {
    text-align: center;
}

.ack-list div {
    font-size: 11px;
    color: #555;
    margin-bottom: 3px;
}

.brand-logo {
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

/* Typography */
.memorial-text {
    font-size: 11px;
    color: #003a66;
    line-height: 1.5;
}

.memorial-text strong {
    font-size: 12px;
    display: block;
    margin-bottom: 4px;
}
.memorial-card {
    border-top: 1px solid #e6eef5;
}

/* Info Content */
.info-content {
    padding: 15px;
    background: white;
}

/* Map Loading Indicator */
.map-loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2000;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 20px 30px;
    border-radius: 8px;
    display: none;
    align-items: center;
    gap: 15px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    font-size: 14px;
    pointer-events: none;
}

.loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.leaflet-zoom-animated {
    image-rendering: -webkit-optimize-contrast;
}

/* ═══════════════════════════════════════════════════════════════════════════
   PI OVERLAY STYLES
═══════════════════════════════════════════════════════════════════════════ */

#pi-progress-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9000;
    pointer-events: none;
    background: rgba(0, 12, 28, 0.88);
    border: 1px solid rgba(109, 185, 255, 0.25);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55),
                0 0 0 1px rgba(109, 185, 255, 0.08);
    padding: 24px 32px 22px;
    min-width: 320px;
    max-width: 420px;
    width: 360px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    font-family: 'Segoe UI', sans-serif;
    color: #e8f4ff;
}

.pi-legend {
    background: rgba(255, 255, 255, 0.92);
    border-radius: 6px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
    font-family: 'Segoe UI', sans-serif;
    user-select: none;
    min-width: 80px;
}

.pi-legend-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.pi-legend-title {
    font-size: 11px;
    font-weight: 600;
    color: #002c4d;
    text-align: center;
    line-height: 1.3;
    max-width: 80px;
}

.pi-legend-body {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 5px;
}

.pi-legend-ticks {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.pi-legend-tick {
    position: absolute;
    left: 0;
    transform: translateY(-50%);
    font-size: 10px;
    color: #333;
    white-space: nowrap;
    line-height: 1;
}

#pi-analysis-group .group-label {
    font-weight: 600;
    color: #002c4d;
}

#pi-analysis-group .tree-item {
    font-size: 11px;
    color: #333;
    cursor: pointer;
    transition: background 0.15s;
}

#pi-analysis-group .tree-item:hover {
    background: rgba(0, 64, 112, 0.06);
    border-radius: 3px;
}

#pi-analysis-group .pi-no-data-hint {
    padding: 10px 15px;
    font-size: 11px;
    color: #999;
    font-style: italic;
}

#geological-layers-group .group-label {
    font-weight: 600;
    color: #002c4d;
}

/* ═══════════════════════════════════════════════════════════════════════
   TOP LEFT BRAND BAR (I-BUTTON MENU)
   ═══════════════════════════════════════════════════════════════════════ */
#top-left-brand-bar {
    position: absolute;
    top: 15px;
    left: 15px;
    z-index: 2000;
    font-family: 'Segoe UI', sans-serif;
    pointer-events: auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
}

.brand-bar-header {
    display: flex;
    align-items: center;
    height: 38px;
    box-sizing: border-box;
    background: #002c4d;
    color: white;
    padding: 0 15px;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    gap: 12px;
    transition: background 0.2s;
}

.brand-bar-header:hover {
    background: #004070;
}

.info-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: 1.5px solid rgba(255,255,255,0.8);
    border-radius: 50%;
    font-size: 13px;
    font-family: monospace;
    font-weight: bold;
    color: white;
}

.brand-title {
    font-size: 14px;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.dropdown-icon {
    font-size: 10px;
    color: rgba(255,255,255,0.7);
}

.brand-dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 8px;
    background: white;
    width: 320px;
    border-radius: 6px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    overflow: hidden;
    color: #333;
    z-index: 2001;
}

.brand-dropdown-content.open {
    display: block;
}

.brand-dropdown-content .info-content {
    padding: 15px;
    background: white;
}

/* Push Leaflet controls down so they don't overlap with the top-left menu */
.leaflet-top.leaflet-left {
    margin-top: 60px !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TABLET RESPONSIVE — PROJECT SHWETA
   Target: screens 769px – 1024px (tablets, small laptops in portrait)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (min-width: 769px) and (max-width: 1024px) {

    /* ── Sidebar: slightly shorter on tablet, tab rail goes horizontal ── */
    .sidebar {
        height: 260px;
        flex-direction: column !important;
    }

    .sidebar.collapsed {
        margin-bottom: -260px;
    }

    /* ── Tab rail: horizontal on tablet ── */
    .sidebar-tab-rail {
        width: 100%;
        height: 42px;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
        -ms-overflow-style: none;
        border-bottom: 1px solid rgba(255,255,255,0.1);
        border-right: none;
        flex-shrink: 0;
    }

    .sidebar-tab-rail::-webkit-scrollbar { display: none; }

    .tab-btn {
        flex: none;
        padding: 0 16px;
        height: 42px;
        border-bottom: 2px solid transparent;
        border-right: none;
        font-size: 11px;
        white-space: nowrap;
    }

    .tab-btn.active {
        border-right-color: transparent;
        border-bottom-color: var(--accent-blue);
    }

    /* ── Sidebar content: below the tab rail ── */
    .sidebar-content {
        margin-top: 42px;
        height: calc(100% - 42px);
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* ── Brand bar: stays manageable on tablet ── */
    #top-left-brand-bar {
        top: 10px;
        left: 10px;
        gap: 5px;
    }

    .brand-title {
        font-size: 13px;
        max-width: 200px;
    }

    /* ── Docked registry: constrain width ── */
    #h2f-docked-registry,
    #h2f-selection-ext {
        width: clamp(280px, 40vw, 380px);
        right: 10px;
    }

    /* ── Coordinate display: above the sidebar ── */
    .coordinate-display {
        bottom: 280px;
        right: 10px;
    }

    /* ── Zoom toast: above sidebar ── */
    .zoom-limit-toast {
        bottom: 280px;
    }

    /* ── Leaflet controls: avoid overlap with brand bar ── */
    .leaflet-top.leaflet-right {
        left: auto !important;
        right: 10px !important;
        top: 60px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE — PROJECT SHWETA
   Target: screens ≤ 768px (phones, small tablets)
   Rule: NO horizontal scroll except map & output table
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

    /* ── Root overflow guard ── */
    html, body {
        overflow: hidden !important;
    }

    /* ── Main container stays full-screen column ── */
    .main-container {
        flex-direction: column;
    }

    /* ── Map fills remaining space above sidebar ── */
    #map-wrapper {
        flex: 1 1 auto;
        min-height: 0;
    }

    /* ── Sidebar: shorter on mobile, no horizontal overflow ── */
    .sidebar {
        height: 220px;
        flex-shrink: 0;
        overflow: hidden;
    }

    .sidebar.collapsed {
        margin-bottom: -220px;
    }

    /* ── Tab rail: horizontal scrollable bar across the top of sidebar ── */
    .sidebar-tab-rail {
        width: 100%;
        height: 40px;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
        -ms-overflow-style: none;
        border-bottom: 1px solid rgba(255,255,255,0.1);
        border-right: none;
        flex-shrink: 0;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        z-index: 2;
    }

    .sidebar-tab-rail::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        flex: none;
        padding: 0 14px;
        height: 40px;
        border-bottom: none;
        border-right: none;
        border-bottom: 2px solid transparent;
        font-size: 10px;
        white-space: nowrap;
        gap: 5px;
    }

    .tab-btn.active {
        border-right-color: transparent;
        border-bottom-color: var(--accent-blue);
    }

    .tab-icon {
        font-size: 12px;
    }

    .tab-label {
        font-size: 10px;
    }

    /* ── Sidebar content: shifted below the tab rail ── */
    .sidebar-content {
        margin-top: 40px;
        height: calc(100% - 40px);
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* ── Sidebar is now horizontal-stack → switch to column ── */
    .sidebar {
        flex-direction: column !important;
    }

    /* ── Sidebar toggle handle ── */
    .sidebar-toggle {
        left: 50%;
        transform: translateX(-50%);
    }

    /* ── Top-left brand bar: shrink on mobile ── */
    #top-left-brand-bar {
        top: 8px;
        left: 8px;
        right: 8px;
        flex-wrap: wrap;
        gap: 4px;
        max-width: calc(100vw - 16px);
    }

    .brand-bar-header {
        height: 34px;
        padding: 0 10px;
        gap: 8px;
        flex-shrink: 0;
        max-width: calc(100vw - 16px);
    }

    .brand-title {
        font-size: 11px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 160px;
    }

    /* ── Map inline controls: wrap to 2 per row, no horizontal overflow ── */
    #map-inline-controls {
        flex-wrap: wrap;
        gap: 4px;
        max-width: calc(100vw - 16px);
        margin-left: 0;
        margin-top: 4px;
    }

    .map-ctrl-check {
        height: 30px;
        padding: 0 8px;
        font-size: 10px;
        flex-shrink: 0;
    }

    /* ── Brand dropdown: limit width on mobile ── */
    .brand-dropdown-content {
        width: calc(100vw - 16px);
        max-width: 320px;
        left: 0;
        right: auto;
    }

    /* ── Coordinate display: stay on screen ── */
    .coordinate-display {
        top: auto;
        bottom: 240px; /* above sidebar */
        right: 8px;
        min-width: 160px;
        padding: 8px;
    }

    .coordinate-display h3 {
        font-size: 12px;
    }

    .coord-row {
        font-size: 11px;
    }

    /* ── Docked registry panels: fit within screen ── */
    #h2f-docked-registry,
    #h2f-selection-ext {
        width: calc(100vw - 16px);
        max-width: 380px;
        right: 8px;
        top: 120px;
    }

    /* ── Bookmarks panel ── */
    .bookmarks-panel {
        width: calc(100vw - 40px);
        right: 20px;
        top: 120px;
    }

    /* ── PI progress overlay ── */
    #pi-progress-overlay {
        min-width: unset;
        width: calc(100vw - 32px);
        padding: 18px 16px;
    }

    /* ── Leaflet controls positioning adjustment ── */
    .leaflet-top.leaflet-right {
        left: 8px !important;
        top: 50px !important;
    }

    .leaflet-top.leaflet-left {
        margin-top: 50px !important;
    }

    /* ── Plan comparison modal: stack on mobile ── */
    .shw-plans-grid {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        scrollbar-width: thin;
    }

    .shw-plans-grid-spacer {
        display: none;
    }

    .shw-plan-col {
        min-width: 120px;
        flex: 0 0 120px;
    }

    .shw-feature-table {
        font-size: 11px;
    }

    .shw-feat-label {
        padding-left: 10px;
        font-size: 11px;
        width: 38%;
    }

    .shw-feat-row td {
        padding: 7px 8px;
    }

    .shw-section-row td {
        padding: 10px 10px 4px;
        font-size: 8px;
    }

    .shw-modal-footer {
        flex-direction: column;
        gap: 12px;
        padding: 14px 16px;
    }

    /* ── About modal: respect mobile padding ── */
    #aboutModalOverlay {
        padding: 50px 12px 20px;
    }

    .about-modal-close {
        top: 12px;
        right: 16px;
    }

    .about-modal-title {
        font-size: 28px;
    }

    .about-section-container {
        padding: 24px 16px;
    }

    .about-grid {
        grid-template-columns: 1fr;
    }

    .collab-list {
        grid-template-columns: 1fr;
    }

    /* ── Deep Analysis tab inner panels: no horizontal scroll ── */
    #da-history-panel table,
    #da-results-table {
        font-size: 10px;
    }

    /* ── Pane scroll ── */
    .pane-scroll {
        padding: 8px;
    }

    /* ── Zoom limit toast: keep above sidebar ── */
    .zoom-limit-toast {
        bottom: 240px;
    }

    /* ── Brand title: hide "iprescienteras | " prefix to save space ── */
    .brand-title-full {
        display: none;
    }

    /* ── Map: ensure touch pan/zoom works normally ── */
    #map {
        touch-action: pan-x pan-y;
    }
}

/* ── Extra narrow phones (< 480px) ── */
@media (max-width: 480px) {

    .brand-title {
        max-width: 110px;
        font-size: 10px;
    }

    .brand-bar-header {
        padding: 0 8px;
        gap: 6px;
    }

    .info-icon {
        width: 18px;
        height: 18px;
        font-size: 11px;
    }

    /* Map controls: single small row, allow wrap */
    .map-ctrl-check {
        height: 26px;
        padding: 0 6px;
        font-size: 9px;
    }

    /* Sidebar even shallower */
    .sidebar {
        height: 195px;
    }

    .sidebar.collapsed {
        margin-bottom: -195px;
    }

    .sidebar-content {
        height: calc(100% - 40px);
    }

    .coordinate-display {
        bottom: 210px;
    }

    .zoom-limit-toast {
        bottom: 210px;
    }
}