/* Hvaler Genealogi - Styles */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

#map {
    flex: 1;
    width: 100%;
}

/* Controls Panel */
.controls {
    background: white;
    padding: 15px 20px;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.control-group label {
    font-weight: 600;
    color: #333;
}

#dateSlider {
    width: 500px;
}

#dateDisplay {
    font-size: 18px;
    font-weight: bold;
    color: #2c5aa0;
    min-width: 100px;
}

#locationCount {
    padding: 5px 12px;
    background: #e8f4f8;
    border-radius: 4px;
    font-size: 14px;
    color: #2c5aa0;
}

.boundary-toggle-container {
    display: flex;
    align-items: center;
}

.boundary-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.boundary-toggle input {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #2c5aa0;
}

.boundary-toggle.is-disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.boundary-toggle.is-disabled input {
    cursor: not-allowed;
}

.clickable-count {
    text-decoration: underline;
    font-weight: 600;
}

.clickable-count:hover {
    color: #1a3a6e;
}

.btn-editor {
    padding: 8px 16px;
    background: #2c5aa0;
    color: white;
    text-decoration: none;
    border-radius: 3px;
    font-weight: 600;
    font-size: 14px;
    transition: background 0.2s;
    display: inline-block;
    white-space: nowrap;
}

.btn-editor:hover {
    background: #1a3a6e;
}

.btn-editor:active {
    background: #0f2345;
}

.btn-editor[disabled] {
    opacity: 0.55;
    cursor: not-allowed !important;
    pointer-events: none;
}

.btn-editor.btn-editor-active {
    background: #146c43;
}

.btn-editor.btn-editor-active:hover {
    background: #0f5132;
}

.btn-editor-warning {
    background: #d97706;
}

.btn-editor-warning:hover {
    background: #b45309;
}

.btn-editor-warning:active {
    background: #92400e;
}

/* Toggle Switch */
.toggle-switch-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 26px;
}

.toggle-switch .slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle-switch input:checked + .slider {
    background-color: #2c5aa0;
}

.toggle-switch input:checked + .slider:before {
    transform: translateX(24px);
}

.toggle-switch .toggle-label {
    font-size: 14px;
    color: #333;
    cursor: pointer;
    user-select: none;
}

/* Loading Indicator */
.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 20px 40px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    z-index: 10000;
    font-size: 16px;
}

.hidden {
    display: none;
}

/* Leaflet Tooltip Customization */
.leaflet-tooltip {
    background-color: rgba(255, 255, 255, 0.95);
    border: 1px solid #ddd;
    border-radius: 4px;
    color: #333;
    font-size: 13px;
    padding: 5px 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.leaflet-tooltip-left::before {
    border-left-color: rgba(255, 255, 255, 0.95);
}

.leaflet-tooltip-right::before {
    border-right-color: rgba(255, 255, 255, 0.95);
}

.leaflet-tooltip-top::before {
    border-top-color: rgba(255, 255, 255, 0.95);
}

.leaflet-tooltip-bottom::before {
    border-bottom-color: rgba(255, 255, 255, 0.95);
}

/* Popup Content */
.popup-content {
    font-size: 14px;
    min-width: 200px;
}

.popup-content .header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
}

.popup-content h3 {
    margin: 0;
    color: #2c5aa0;
}

.popup-content .detail {
    margin: 0;
    font-size: 13px;
    color: #666;
}

.popup-content .detail .historical-badge {
    display: inline-block;
    padding: 4px 10px;
    background: #FF9800;
    color: white;
    font-size: 13px;
    font-weight: 700;
    border-radius: 4px;
    cursor: help;
}

.popup-content .detail .fallback-badge {
    display: inline-block;
    padding: 4px 10px;
    background: #78909C;
    color: white;
    font-size: 13px;
    font-weight: 700;
    border-radius: 4px;
    cursor: help;
}

.uncertain-coordinate-badge {
    display: block;
    padding: 8px 12px;
    margin: 0 -12px 12px -12px;
    background: #e74c3c;
    color: white;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    border-left: 4px solid #c0392b;
}

.popup-content .residents {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e0e0e0;
}

/* Family Groups in Popup */
.family-group {
    margin-bottom: 10px;
    padding-bottom: 8px;
}

.family-group:not(:last-child) {
    border-bottom: 1px solid #f0f0f0;
}

.family-group-title {
    font-weight: 600;
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
    margin-left: 3px;
}

.popup-content .resident-name {
    padding: 2px 0 2px 15px;
    font-size: 13px;
    color: #2c5aa0;
}

.popup-content .resident-name.indent-0 {
    padding-left: 15px;
}

.popup-content .resident-name.indent-1 {
    padding-left: 35px;
}

.popup-content .resident-name.indent-2 {
    padding-left: 55px;
}

.popup-content .resident-name.secondary {
    color: #999;
    cursor: default;
    text-decoration: none;
}

.popup-content .resident-name.secondary:hover {
    color: #999;
    text-decoration: none;
}

.popup-content .resident-name:hover {
    color: #1a3a6e;
}

.popup-content .loading {
    font-style: italic;
    color: #888;
    font-size: 12px;
}

/* Person Detail Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    overflow-y: auto;
}

.modal-overlay.visible {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e0e0e0;
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
}

.modal-header h2 {
    margin: 0;
    color: #2c5aa0;
    font-size: 20px;
    line-height: 1.4;
    flex: 1;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 32px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    flex-shrink: 0;
}

.modal-close:hover {
    color: #000;
}

.modal-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.modal-btn {
    padding: 8px 14px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.2s, transform 0.1s;
}

.modal-btn:hover {
    background: #45a049;
    transform: translateY(-1px);
}

.modal-btn:active {
    transform: translateY(0);
}

.modal-btn-edit {
    background: #2196F3;
}

.modal-btn-edit:hover {
    background: #0b7dda;
}

.modal-btn-export {
    background: #FF9800;
}

.modal-btn-export:hover {
    background: #e68900;
}

.modal-body {
    padding: 24px;
}

.modal-section {
    margin-bottom: 24px;
}

.modal-section h3 {
    margin: 0 0 12px 0;
    color: #333;
    font-size: 18px;
    border-bottom: 2px solid #2c5aa0;
    padding-bottom: 8px;
}

.modal-field {
    display: flex;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

.modal-field-label {
    font-weight: 600;
    width: 200px;
    color: #555;
    flex-shrink: 0;
}

.modal-field-value {
    color: #333;
    flex: 1;
}

/* Event Styles */
.event-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.event-item {
    padding: 12px;
    background: #f8f9fa;
    border-radius: 4px;
    border-left: 3px solid #2c5aa0;
}

.event-header {
    font-weight: 600;
    color: #2c5aa0;
    margin-bottom: 8px;
    font-size: 15px;
}

.event-detail {
    color: #555;
    font-size: 13px;
    margin: 4px 0;
    padding-left: 8px;
}

.event-detail em {
    font-style: normal;
    font-weight: 600;
    color: #666;
}

.event-detail a {
    color: #2c5aa0;
    text-decoration: none;
}

.event-detail a:hover {
    text-decoration: underline;
}

.event-date {
    font-weight: 600;
    color: #2c5aa0;
    margin-bottom: 4px;
}

.event-type {
    color: #666;
    font-size: 14px;
}

.event-location {
    color: #888;
    font-size: 13px;
    margin-top: 4px;
}

/* Relation Styles */
.relation-group {
    margin-bottom: 16px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 4px;
}

.relation-label {
    font-weight: 600;
    color: #2c5aa0;
    margin-bottom: 8px;
    font-size: 14px;
}

.relation-item {
    padding: 4px 0 8px 16px;
    color: #333;
    font-size: 14px;
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.relation-item span {
    font-weight: 500;
}

/* Relationship Lookup Button and Result */
.relation-lookup-btn {
    padding: 4px 10px;
    background: #2c5aa0;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
    transition: background 0.2s;
}

.relation-lookup-btn:hover {
    background: #1a3a6e;
}

.relation-lookup-btn:active {
    background: #0f2345;
}

.relation-result {
    padding: 4px 10px;
    background: #e8f4f8;
    color: #2c5aa0;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.relation-result.loading {
    background: #fff9e6;
    color: #666;
}

/* Search Box */
.search-box {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 340px;
    z-index: 1500;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

body.analytics-mode .search-box {
    display: block;
}

body.analytics-mode .search-input-wrapper,
body.analytics-mode #searchResults,
body.analytics-mode #searchFiltersPanel {
    display: none;
}

.analytics-mode-pane {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 340px;
    z-index: 1500;
    background: #ffffff;
    border: 2px solid #d0d0d0;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 14px;
}

.analytics-pane-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.analytics-pane-header h3 {
    margin: 0;
    font-size: 16px;
    color: #23395d;
}

.analytics-pane-header p {
    margin: 4px 0 0;
    font-size: 12px;
    color: #516176;
}

.analytics-pane-close {
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 24px;
    line-height: 1;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.analytics-pane-close:hover {
    background: #f1f5f9;
    color: #334155;
}

.analytics-pane-section {
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px solid #e5e9f0;
}

.analytics-pane-section-title {
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #334155;
}

.analytics-toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 13px;
    color: #2f3e4f;
}

.analytics-toggle-row input[disabled] {
    cursor: not-allowed;
}

.analytics-layer-swatch {
    display: inline-block;
    width: 16px;
    height: 10px;
    border-radius: 999px;
    border: 1px solid rgba(0, 0, 0, 0.18);
    margin-left: 2px;
}

.analytics-layer-swatch-rate {
    background: rgb(30, 64, 175);
    border: 1px solid #1e3a8a;
}

.analytics-layer-swatch-count {
    background: rgb(153, 27, 27);
    border: 1px solid #7f1d1d;
}

.analytics-layer-swatch-stillbirth {
    background: rgb(22, 101, 52);
    border: 1px solid #166534;
}

.analytics-layer-swatch-births {
    background: rgb(3, 105, 161);
    border: 1px solid #0c4a6e;
}

.analytics-layer-swatch-population {
    background: rgb(124, 45, 18);
    border: 1px solid #7c2d12;
}

.analytics-layer-swatch-immigration {
    background: rgb(6, 95, 70);
    border: 1px solid #065f46;
}

.analytics-layer-swatch-emigration {
    background: rgb(154, 52, 18);
    border: 1px solid #7c2d12;
}

.analytics-toggle-row.is-locked {
    opacity: 0.6;
}

.analytics-placeholder-row {
    font-size: 13px;
    color: #49566a;
    background: #f6f9fc;
    border: 1px solid #dbe4ef;
    border-radius: 6px;
    padding: 8px 10px;
}

.analytics-time-controls {
    display: grid;
    gap: 8px;
}

.analytics-time-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.analytics-time-speed-row {
    justify-content: space-between;
}

.analytics-time-speed-row label {
    font-size: 12px;
    color: #334155;
    font-weight: 600;
}

.analytics-time-btn {
    border: 1px solid #1e3a8a;
    background: #1e3a8a;
    color: #ffffff;
    border-radius: 6px;
    height: 32px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.analytics-time-btn:hover {
    background: #1e40af;
}

.analytics-time-btn-secondary {
    border-color: #c7d2e1;
    background: #f8fafc;
    color: #334155;
}

.analytics-time-btn-secondary:hover {
    background: #eef2f7;
}

.analytics-time-btn.is-playing {
    border-color: #7f1d1d;
    background: #991b1b;
}

.analytics-time-select {
    min-width: 120px;
    height: 30px;
    border: 1px solid #c7d2e1;
    border-radius: 6px;
    background: #ffffff;
    color: #1f2937;
    font-size: 12px;
    padding: 0 8px;
}

.analytics-time-bucket {
    font-size: 12px;
    color: #334155;
    font-weight: 600;
    padding: 6px 8px;
    border: 1px solid #dbe4ef;
    border-radius: 6px;
    background: #f7fafe;
}

.analytics-pane-footnote {
    margin-top: 12px;
    font-size: 11px;
    color: #67768a;
}

.analytics-layer-status {
    margin-top: 8px;
    padding: 6px 8px;
    font-size: 11px;
    color: #46556a;
    background: #f4f7fb;
    border: 1px solid #dbe4ef;
    border-radius: 6px;
}

.search-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.analytics-search-actions {
    margin-top: 8px;
    display: flex;
    justify-content: flex-end;
}

.search-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #d0d0d0;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.search-input::placeholder {
    color: #999;
}

.search-filter-btn {
    padding: 12px 12px;
    border: 2px solid #d0d0d0;
    border-radius: 8px;
    background: white;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-filter-btn:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.filter-icon {
    width: 18px;
    height: 18px;
    color: #333;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.search-filter-btn:hover .filter-icon {
    color: #667eea;
}

.search-filter-btn.btn-editor-active {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.search-filter-btn.btn-editor-active .filter-icon {
    color: #667eea;
}

.analytics-pane-actions {
    margin-top: 10px;
    display: flex;
}

.analytics-pane-link {
    width: 100%;
    text-align: center;
}

/* Advanced search filters panel */
.search-filters-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    margin-top: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 1501;
    width: 100%;
    border: 2px solid #d0d0d0;
}

.search-filters-panel.hidden {
    display: none;
}

.filters-content {
    padding: 16px;
}

.filter-search-field {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-panel-input {
    flex: 1;
    padding: 10px 12px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    background: white;
}

.filter-panel-input:focus {
    outline: none;
    box-shadow: 0 0 4px rgba(102, 126, 234, 0.3);
}

.filter-panel-close {
    padding: 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    transition: color 0.2s;
    flex-shrink: 0;
}

.filter-panel-close:hover {
    color: #d32f2f;
}

.filter-close-icon {
    width: 18px;
    height: 18px;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.filter-group {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e0e0e0;
}

.filter-group:last-of-type {
    border-bottom: none;
}

.filter-group label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    color: #333;
    margin-bottom: 8px;
}

.filter-range {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-number {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

.filter-number:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 4px rgba(102, 126, 234, 0.3);
}

.filter-range span {
    color: #999;
    font-size: 13px;
}

.filter-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 13px;
}

.filter-checkbox input {
    margin-right: 8px;
    cursor: pointer;
    accent-color: #667eea;
}

.filter-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 6px;
}

.filter-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 4px rgba(102, 126, 234, 0.3);
}

.filter-dropdown {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
    width: 100%;
    z-index: 1502;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.filter-dropdown.hidden {
    display: none;
}

.filter-dropdown-item {
    padding: 8px 10px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid #f0f0f0;
}

.filter-dropdown-item:hover {
    background: #f5f7ff;
}

.filter-buttons {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.filter-btn {
    flex: 1;
    padding: 10px 12px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn-apply {
    background: #667eea;
    color: white;
}

.filter-btn-apply:hover {
    background: #5568d3;
}

.filter-btn-clear {
    background: #e0e1e6;
    color: #333;
}

.filter-btn-clear:hover {
    background: #d0d1d6;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 8px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1501;
}

.search-results.hidden {
    display: none;
}

.search-results-list {
    padding: 8px 0;
}

.search-section-header {
    padding: 10px 16px 6px 16px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: #666;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    letter-spacing: 0.5px;
}

.search-result-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: #f5f7ff;
}

.search-result-content {
    flex: 1;
}

.search-result-name {
    font-weight: 500;
    color: #2c3e50;
    margin-bottom: 4px;
}

.search-result-years {
    font-size: 12px;
    color: #999;
}

.search-result-confidence {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    min-width: 50px;
}

.confidence-bar {
    width: 45px;
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    width: 100%;
    transition: width 0.3s ease;
}

.confidence-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.search-no-results,
.search-error {
    padding: 16px;
    text-align: center;
    color: #999;
    font-size: 13px;
}

.search-error {
    color: #d32f2f;
}

/* Phase 1: Search History Styles */
.search-section-header {
    padding: 12px 16px;
    background: #f0f0f0;
    font-weight: 600;
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 8px;
}

.search-section-header:first-of-type {
    margin-top: 0;
}

.search-history-remove {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 16px;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
}

.search-result-item:hover .search-history-remove {
    opacity: 1;
}

.search-history-remove:hover {
    color: #d32f2f;
}

.search-clear-history {
    padding: 12px 16px;
    text-align: center;
    color: #999;
    font-size: 12px;
    cursor: pointer;
    border-top: 1px solid #e0e0e0;
    margin-top: 8px;
}

.search-clear-history:hover {
    background: #f5f5f5;
    color: #666;
}

/* Phase 2: Bookmark Button Styles */
.bookmark-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 4px 8px;
    transition: transform 0.2s, color 0.2s;
    color: #ccc;
    margin-left: 8px;
}

.bookmark-btn:hover {
    transform: scale(1.2);
    color: #ffc107;
}

.bookmark-btn.bookmarked {
    color: #ffc107;
}

/* Phase 2: Bookmarks Panel Styles */
#bookmarksPanel {
    position: fixed;
    right: 20px;
    bottom: 96px;
    top: auto;
    left: auto;
    z-index: 1400;
    width: 300px;
    background: white;
    border: 1px solid #ddd;
    padding: 16px;
    max-height: 500px;
    overflow-y: auto;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.bookmarks-empty {
    padding: 20px;
    text-align: center;
    color: #999;
    font-style: italic;
}

.bookmarks-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bookmarks-section {
    padding: 8px 0;
}

.bookmarks-section-header {
    font-weight: 600;
    color: #2c5aa0;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e0e0e0;
}

.bookmark-item {
    padding: 8px 12px;
    background: #f9f9f9;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.bookmark-item:hover {
    background: #f0f0f0;
}

.bookmark-remove {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 4px;
    margin-left: auto;
    font-size: 14px;
}

.bookmark-remove:hover {
    color: #d32f2f;
}

.bookmarks-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
}

.bookmark-action-btn {
    flex: 1;
    padding: 8px;
    background: #2c5aa0;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}

.bookmark-action-btn:hover {
    background: #1e4070;
}

/* Phase 3: Heatmap Toggle Button */
/* Circle Marker Labels */
.circle-marker-label {
    background-color: transparent;
    border: none;
    font-weight: bold;
    font-size: 12px;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    padding: 0;
    text-decoration: none;
    box-shadow: none !important;
}

/* Cadastral Feature Popups */
.cadastral-popup .leaflet-popup-content-wrapper {
    background: rgba(64, 64, 64, 0.3);
    color: white;
    border-radius: 30px;
    padding: 2px 3px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    border: none;
}

.cadastral-popup .leaflet-popup-content {
    margin: 0;
    font-size: 14px;
    font-weight: bold;
    color: white;
}

.cadastral-popup .leaflet-popup-tip {
    display: none;
}

/* Phase 1: Share URL Section in Modal */
.modal-section input[readonly] {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
    background: #f9f9f9;
    font-family: 'Courier New', monospace;
}

/* Tag Input Component Styles */
.tag-input-container {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 8px;
    background: white;
    min-height: 44px;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}

.tag-item {
    display: inline-flex;
    align-items: center;
    background: #2196F3;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 13px;
    gap: 6px;
}

.tag-name {
    font-weight: 500;
}

.tag-remove {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    margin: 0;
    opacity: 0.8;
}

.tag-remove:hover {
    opacity: 1;
    transform: scale(1.2);
}

.tag-search-wrapper {
    position: relative;
}

.tag-search-input {
    width: 100%;
    border: none;
    padding: 6px 0;
    font-size: 14px;
    outline: none;
}

.tag-search-input:focus {
    outline: none;
}

.tag-search-results {
    position: absolute;
    top: 100%;
    left: -8px;
    right: -8px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    margin-top: 4px;
}

.tag-search-result {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.1s;
}

.tag-search-result:last-child {
    border-bottom: none;
}

.tag-search-result:hover {
    background: #f5f5f5;
}

.tag-search-no-results {
    padding: 10px 12px;
    color: #999;
    font-style: italic;
}

/* ========================================
   MOBILE RESPONSIVE DESIGN (Tablets: 768px, Phones: 480px)
   ======================================== */

/* Tablets (768px and below) */
@media (max-width: 768px) {
    /* Controls Panel - Stack vertically */
    .controls {
        flex-direction: column;
        gap: 12px;
        padding: 12px 15px;
        align-items: flex-start;
    }

    .control-group {
        width: 100%;
        flex-direction: column;
        gap: 6px;
    }

    .boundary-toggle-container {
        width: 100%;
    }

    .control-group label {
        font-size: 13px;
    }

    /* Date Slider - Responsive width */
    #dateSlider {
        width: 100%;
        max-width: 100%;
    }

    /* Date Display */
    #dateDisplay {
        font-size: 16px;
        min-width: 80px;
    }

    /* Button sizing for touch */
    .btn-editor {
        padding: 10px 14px;
        font-size: 13px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Search Box - Reposition and resize for tablet */
    .search-box {
        top: 10px;
        right: 10px;
        left: 60px; /* Avoid Leaflet zoom controls */
        width: auto;
        max-width: none;
    }

    .analytics-mode-pane {
        top: 10px;
        right: 10px;
        left: 60px;
        width: auto;
        max-width: none;
    }

    .search-input {
        font-size: 16px;
        padding: 14px 16px;
        min-height: 44px;
    }

    .search-filter-btn {
        min-height: 44px;
        min-width: 44px;
        padding: 10px;
    }

    /* Search Results Panel */
    .search-results {
        max-height: 300px;
        left: 10px;
        right: 10px;
        border-radius: 8px;
    }

    .search-result-item {
        padding: 14px;
        font-size: 14px;
    }

    /* Filter Panel - Make taller on tablet */
    .search-filters-panel {
        max-height: none;
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
    }

    /* Modal - Increase max-width on tablet */
    .modal-content {
        max-width: 95vw;
        max-height: 95vh;
    }

    .modal-header {
        padding: 16px;
    }

    .modal-body {
        padding: 16px;
    }

    .modal-field-label {
        width: 150px;
    }

    /* Event list - Better spacing */
    .event-item {
        padding: 14px;
    }

    .event-header {
        font-size: 14px;
    }

    .event-detail {
        font-size: 12px;
    }

    /* Popup content - Better spacing */
    .popup-content {
        min-width: 180px;
        font-size: 13px;
    }

    .popup-content .resident-name {
        padding: 3px 0 3px 12px;
        font-size: 13px;
    }
}

/* Phones (480px and below) */
@media (max-width: 480px) {
    /* Body & Layout */
    body {
        font-size: 13px;
    }

    /* Controls Panel - Compact with horizontal button rows */
    .controls {
        gap: 8px;
        padding: 10px;
        align-items: stretch;
    }

    .control-group {
        width: 100%;
        gap: 8px;
        flex-direction: row; /* Keep horizontal on mobile */
        align-items: center;
        justify-content: space-between;
    }

    .boundary-toggle-container {
        width: 100%;
    }

    .control-group label {
        font-size: 12px;
        white-space: nowrap;
    }

    /* Date Slider - Full width */
    #dateSlider {
        width: 100%;
        flex: 1;
    }

    #dateSlider::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }

    #dateDisplay {
        font-size: 14px;
        min-width: 60px;
        text-align: right;
    }

    /* Buttons - Compact horizontal row */
    .btn-editor {
        padding: 10px 12px;
        font-size: 11px;
        min-height: 44px;
        white-space: nowrap;
        flex: 1;
    }

    .btn-editor-warning {
        flex: 1;
    }

    /* Location count badge - inline */
    #locationCount {
        padding: 6px 10px;
        font-size: 12px;
        white-space: nowrap;
    }

    /* Search Box - Full screen mobile interface */
    .search-box {
        position: fixed;
        top: 10px;
        right: 10px;
        left: 60px; /* Avoid Leaflet zoom controls */
        width: auto;
        z-index: 1500;
    }

    .analytics-mode-pane {
        top: 10px;
        right: 10px;
        left: 60px;
        width: auto;
    }

    .search-input-wrapper {
        gap: 6px;
    }

    .search-input {
        font-size: 16px; /* Prevents zoom on iOS focus */
        padding: 12px 14px;
        min-height: 44px;
        border-radius: 6px;
    }

    .search-filter-btn {
        min-height: 44px;
        min-width: 44px;
        padding: 12px;
        border-radius: 6px;
    }

    .filter-icon {
        width: 20px;
        height: 20px;
    }

    /* Search Results - Full width on mobile */
    .search-results {
        position: fixed;
        top: 66px; /* Below search box (10px top + 44px height + 12px gap) */
        left: 60px; /* Align with search box */
        right: 10px;
        max-height: 50vh;
        max-width: none;
        z-index: 1501;
        border-radius: 8px;
    }

    .search-result-item {
        padding: 12px;
        font-size: 13px;
    }

    .search-result-years {
        font-size: 11px;
    }

    .search-result-confidence {
        min-width: 45px;
    }

    .confidence-bar {
        width: 40px;
    }

    /* Filter Panel - Full screen modal on mobile */
    .search-filters-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        z-index: 1502;
        overflow-y: auto;
        border: none;
        box-shadow: none;
        margin: 0;
        display: flex;
        flex-direction: column;
    }

    .filters-content {
        padding: 16px;
        flex: 1;
        overflow-y: auto;
    }

    .filter-search-field {
        margin-bottom: 16px;
        padding-bottom: 16px;
    }

    .filter-panel-input {
        font-size: 16px;
        padding: 12px;
        min-height: 44px;
    }

    .filter-panel-close {
        min-width: 44px;
        min-height: 44px;
    }

    .filter-group label {
        font-size: 12px;
    }

    .filter-number {
        min-height: 44px;
        font-size: 14px;
        padding: 10px;
    }

    .filter-input {
        min-height: 44px;
        font-size: 14px;
        padding: 10px;
    }

    .filter-btn {
        min-height: 44px;
        font-size: 12px;
        padding: 12px;
    }

    /* Modal - Full screen or near-full on mobile */
    .modal-overlay {
        padding: 0;
        align-items: flex-end;
    }

    .modal-overlay.visible {
        align-items: flex-end;
    }

    .modal-content {
        max-width: 100%;
        width: 100%;
        max-height: 95vh;
        border-radius: 12px 12px 0 0;
        overflow-y: auto;
    }

    .modal-header {
        padding: 14px;
        gap: 10px;
        flex-wrap: wrap;
    }

    .modal-header h2 {
        font-size: 18px;
        flex: 1;
        min-width: 200px;
    }

    .modal-actions {
        width: 100%;
        gap: 8px;
    }

    .modal-btn {
        flex: 1;
        padding: 10px;
        min-height: 44px;
        font-size: 12px;
    }

    .modal-close {
        min-height: 44px;
        width: 44px;
    }

    .modal-body {
        padding: 14px;
    }

    .modal-section h3 {
        font-size: 16px;
        margin-bottom: 10px;
    }

    .modal-field {
        flex-direction: column;
        gap: 4px;
    }

    .modal-field-label {
        width: 100%;
        font-size: 12px;
    }

    .modal-field-value {
        font-size: 13px;
    }

    /* Events - Better spacing for mobile */
    .event-list {
        gap: 10px;
    }

    .event-item {
        padding: 12px;
        border-left-width: 4px;
    }

    .event-header {
        font-size: 13px;
    }

    .event-detail {
        font-size: 12px;
        margin: 3px 0;
    }

    .event-location {
        font-size: 12px;
    }

    /* Relations - Better mobile display */
    .relation-group {
        padding: 10px;
        margin-bottom: 12px;
    }

    .relation-item {
        font-size: 13px;
        padding-left: 12px;
    }

    .relation-lookup-btn {
        min-height: 36px;
        padding: 6px 10px;
        font-size: 11px;
    }

    /* Popup - Mobile-friendly sizing */
    .popup-content {
        min-width: 150px;
        max-width: 90vw;
        font-size: 12px;
    }

    .popup-content h3 {
        font-size: 14px;
        margin-bottom: 8px;
    }

    .popup-content .detail {
        font-size: 12px;
        margin-bottom: 6px;
    }

    .popup-content .residents {
        margin-top: 8px;
        padding-top: 8px;
    }

    .family-group {
        margin-bottom: 8px;
        padding-bottom: 6px;
    }

    .family-group-title {
        font-size: 11px;
        margin-bottom: 4px;
    }

    .popup-content .resident-name {
        padding: 2px 0 2px 10px;
        font-size: 12px;
        min-height: 40px;
        display: flex;
        align-items: center;
    }

    .popup-content .resident-name:hover {
        background: rgba(44, 90, 160, 0.1);
        border-radius: 3px;
    }

    /* Toggle Switch - Larger on mobile */
    .toggle-switch {
        width: 56px;
        height: 32px;
    }

    .toggle-switch .slider:before {
        width: 24px;
        height: 24px;
    }

    .toggle-switch input:checked + .slider:before {
        transform: translateX(26px);
    }

    .toggle-label {
        font-size: 13px;
    }

    /* Tag Inputs - Better mobile experience */
    .tag-input-container {
        min-height: 48px;
        padding: 10px;
    }

    .tag-list {
        gap: 8px;
    }

    .tag-item {
        padding: 6px 10px;
        font-size: 12px;
        min-height: 32px;
    }

    .tag-search-input {
        font-size: 16px;
        min-height: 44px;
        padding: 10px 0;
    }

    .tag-search-results {
        max-height: 200px;
    }

    .tag-search-result {
        padding: 12px;
        font-size: 13px;
    }

    /* Bookmarks Panel - Mobile sized */
    #bookmarksPanel {
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: 88px;
        top: auto;
        width: auto;
        height: auto;
        max-height: 45vh;
        border-radius: 8px;
        z-index: 1400;
        overflow-y: auto;
    }

    .bookmark-item {
        padding: 12px;
        font-size: 13px;
        min-height: 40px;
    }

    .bookmark-action-btn {
        min-height: 44px;
        font-size: 12px;
    }

    /* Toggle switches and inputs */
    input[type="radio"],
    input[type="checkbox"] {
        width: 18px;
        height: 18px;
        cursor: pointer;
    }

    /* Help with scrolling on mobile */
    * {
        -webkit-touch-callout: none;
    }

    a, button {
        -webkit-touch-callout: default;
    }
}
