/* Shared control panel styling with transparency */
#controls {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 300px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 10px;
    z-index: 1000;
    font-family: var(--font, 'IBM Plex Sans', Arial, sans-serif);
}

/* Sub-panels with less transparency */
.control-panel {
    background: rgba(255, 255, 255, 0.8);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 10px;
}

.control-panel:last-child {
    margin-bottom: 0;
}

/* Title panel */
.title-panel {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
}

.title-panel h4 {
    flex: 1;
    text-align: center;
    margin: 0;
    font-size: 1.2em;
    font-weight: bold;
}

/* Collapse toggle button */
.nav-collapse-btn {
    position: relative;
    z-index: 11;
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 0 2px;
    cursor: pointer;
    font-size: 0.9em;
    color: #666;
    line-height: 1;
    font-family: inherit;
}

.nav-collapse-btn:hover {
    color: #000;
}

/* Collapsed state */
#controls.collapsed {
    background: rgba(255, 255, 255, 0.15) !important;
}

#controls.collapsed .title-panel {
    background: rgba(255, 255, 255, 0.4);
    margin-bottom: 0;
}

#controls.collapsed #nav-body {
    display: none;
}

/* Nav body wrapper — needed for overlay positioning */
#nav-body {
    position: relative;
}

/* Loading overlay — covers nav-body panels while tiles load */
#nav-loading-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(160, 160, 160, 0.65);
    border-radius: 6px;
    z-index: 10;
    justify-content: center;
    align-items: center;
    font-size: 0.85em;
    color: #222;
    font-weight: bold;
    pointer-events: all;
}

#controls.loading #nav-loading-overlay {
    display: flex;
}

.qr-toggle {
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 0;
    font-size: 0.75em;
    color: #666;
    cursor: pointer;
    font-family: inherit;
}

.qr-toggle:hover {
    color: #000;
}

.qr-popup {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    z-index: 1001;
}

.qr-popup.visible {
    display: block;
}

.qr-popup img {
    display: block;
    width: 120px;
    height: 120px;
}

/* View panel */
.view-panel label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

/* Regions and sharing panels */
.regions-panel label,
.sharing-panel label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

/* Navigation panel */
.nav-panel {
    text-align: center;
}

/* Reuse console.css button styling */
.button {
    background-color: #cccccc;
    border: 1px solid #999;
    padding: 5px 10px;
    margin: 2px;
    border-radius: 3px;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: inline-block;
}

.button:hover {
    background-color: #bbbbbb;
}

/* Input field styling */
.input-field {
    width: 100%;
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 3px;
    margin-bottom: 5px;
}

/* Progress bar styling */
#loading-progress {
    margin-top: 10px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 6px;
    padding: 10px;
}

.progress-bar {
    width: 100%;
    height: 20px;
    background-color: #f0f0f0;
    border-radius: 4px;
    margin-top: 10px;
    position: relative;
    overflow: hidden;
}

.progress-fill {
    width: 0%;
    height: 100%;
    background-color: #4CAF50;
    transition: width 0.3s ease;
}

.progress-text {
    position: absolute;
    width: 100%;
    height: 100%;
    text-align: center;
    line-height: 20px;
    color: #333;
    font-size: 12px;
}

/* Help popup styling */
.help-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.help-content {
    background: white;
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
    max-height: 80%;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.help-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 20px 0 20px;
    border-bottom: 1px solid #eee;
}

.help-header h2 {
    margin: 0;
    color: #333;
    font-size: 1.5em;
}

.close-button {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-button:hover {
    color: #333;
}

.help-body {
    padding: 20px;
}

.help-body ul {
    margin: 0;
    padding-left: 20px;
}

.help-body li {
    margin-bottom: 10px;
    line-height: 1.4;
    color: #555;
}

#help-link {
    font-weight: bold;
    font-size: 1.2em;
    text-decoration: none;
    color: #007bff;
}

#help-link:hover {
    color: #0056b3;
}

/* Error popup styling */
.error-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #ff4444;
    color: white;
    padding: 20px;
    border-radius: 8px;
    z-index: 2000;
    font-family: Arial, sans-serif;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    max-width: 400px;
    text-align: center;
}

/* Success notification styling */
.success-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #4CAF50;
    color: white;
    padding: 10px 15px;
    border-radius: 5px;
    z-index: 1000;
    font-family: Arial, sans-serif;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

/* Button group styling */
.button-group {
    display: flex;
    gap: 10px;
}

.link-button {
    background: #f0f0f0;
    border: 1px solid #ccc;
    color: #333;
}

.link-button:hover {
    background: #e0e0e0;
}

.warning-button {
    padding: 10px;
    background: #fff0f0;
    border: 1px solid #ffcccc;
    border-radius: 4px;
    cursor: pointer;
    flex: 1;
}

.warning-button:hover {
    background: #ffe0e0;
}

/* Webedit selection preview (annotate pages) */
.selection-hint {
    margin: -4px 0 10px 0;
    font-size: 0.8em;
    color: #666;
}

#selection-panel {
    margin-bottom: 12px;
    border-top: 1px solid #ddd;
    padding-top: 8px;
}

#selection-header {
    font-size: 0.85em;
    font-weight: 600;
    margin-bottom: 6px;
}

#selection-tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    margin-bottom: 6px;
}

.selection-tab {
    flex: 0 0 auto;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 3px 8px;
    font-size: 0.8em;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #f7f7f7;
    cursor: pointer;
}

.selection-tab.active {
    background: #ffd400;
    border-color: #c9a800;
    font-weight: 600;
}

#selection-body {
    max-height: 35vh;
    overflow-y: auto;
}

.prop-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8em;
    table-layout: fixed;
}

.prop-table th,
.prop-table td {
    text-align: left;
    vertical-align: top;
    padding: 3px 4px;
    border-bottom: 1px solid #eee;
    word-break: break-word;
}

.prop-table th {
    width: 40%;
    font-weight: normal;
    color: #555;
}

.prop-table tr.prop-editable th {
    font-weight: 600;
    color: #222;
}

.prop-editable-mark {
    color: #c9a800;
}

.prop-empty {
    color: #aaa;
}

/* Webmap sharing panel: Share and Go to side by side, each opening a pop-up */
.sharing-buttons {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.sharing-button-cell {
    flex: 1;
    text-align: center;
}

.sharing-button-cell .button {
    width: 100%;
    box-sizing: border-box;
}

.sharing-hint {
    font-size: 11px;
    color: #555;
    margin-top: 2px;
}

/* Share / go-to pop-ups (reuse the help-popup modal) */
.map-popup .help-body label {
    display: block;
    font-weight: bold;
    margin-bottom: 5px;
}

.map-popup .input-field {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 10px;
}

.map-popup textarea.input-field {
    font-family: monospace;
    font-size: 12px;
    resize: vertical;
}

.map-popup .help-body .button {
    width: 100%;
    box-sizing: border-box;
    padding: 6px;
}

/* Basemap picker, once moved into the Visibility (legend) panel */
.maplibregl-legend-list .basemap-control {
    margin: 4px 0 6px 0;
}

.maplibregl-legend-list .basemap-control label {
    display: block;
    font-size: 12px;
    font-weight: bold;
}

.maplibregl-legend-list .basemap-control select {
    width: 100%;
    box-sizing: border-box;
    font-size: 12px;
    padding: 2px 4px;
    margin: 2px 0 0 0;
}

/* Webmap header row: atlas name, QR, Home/3D/? and the collapse toggle on one line.
   Fixed px sizes: the panel inherits a large base font from console.css. */
.webmap-controls .header-row {
    gap: 6px;
    padding: 6px 8px;
}

.webmap-controls .header-row h4 {
    min-width: 0;
    text-align: left;
    font-size: 15px;
    line-height: 1.2;  /* a long name wraps onto a second line */
}

.webmap-controls .header-row .qr-toggle {
    font-size: 11px;
}

.webmap-controls .header-links {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
}

.webmap-controls .header-link {
    font-size: 12px;
    padding: 2px 6px;
    border: 1px solid #bbb;
    border-radius: 3px;
    background: #e8e8e8;
    color: #333;
    text-decoration: none;
    line-height: 1.3;
}

.webmap-controls .header-link:hover {
    background: #d4d4d4;
}

.webmap-controls #help-link {
    font-size: 12px;
    color: #007bff;
}

/* Collapsed: hide everything but the toggle, which stays at the top-right.
   #controls in the selector so it outranks the base #controls width/background. */
#controls.webmap-controls.collapsed {
    width: auto;
    background: none !important;  /* beats the shared #controls.collapsed !important */
    /* padding kept, so the toggle doesn't move */
}

#controls.webmap-controls.collapsed .header-row {
    margin: 0;
    background: rgba(255, 255, 255, 0.85);
}

/* Sit below MapLibre's top-right controls (e.g. Go to current location) */
#controls.webmap-controls {
    top: 40px;
    right: 0;
}

/* Visibility panel collapse toggle: the legend library's close / reopen buttons
   restyled as the nav panel's ▾ / ▸ */
.maplibregl-legend-list .maplibregl-legend-close-button {
    font-size: 16px;
    color: #666;
    padding: 5px 6px 0 0;
}

.maplibregl-ctrl-group button.maplibregl-legend-switcher {
    background-image: none;
    font-size: 16px;
    color: #666;
    line-height: 1;
}

.maplibregl-legend-list .maplibregl-legend-close-button:hover,
.maplibregl-ctrl-group button.maplibregl-legend-switcher:hover {
    color: #000;
}

#controls.webmap-controls.collapsed .header-row > :not(#nav-collapse-btn) {
    display: none;
}

/* In-app help: a small "?" that opens the matching help page in a new tab */
.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    border: 1px solid #9ab;
    border-radius: 50%;
    font-size: 11px;
    font-weight: bold;
    line-height: 1;
    color: #007bff;
    background: #fff;
    text-decoration: none;
    font-family: Arial, sans-serif;
}

.help-icon:hover {
    background: #e8f0fe;
}

.help-header .help-icon {
    margin-left: auto;
    margin-right: 8px;
}

.regions-panel {
    display: flex;
    align-items: center;
    gap: 6px;
}

.regions-panel select {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.maplibregl-legend-list .help-icon {
    margin-left: 4px;
    vertical-align: middle;
}
