/* Layout v2.13: fixed app topbar + content toolbar */

html,
body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body.map-page,
body.report-page {
    background: #f5f5f5;
}

.container {
    width: 100% !important;
    max-width: 1240px !important;
    margin: 0 auto !important;
    padding: 3.15rem 0.55rem 1rem 0.55rem !important;
    box-sizing: border-box !important;
    background: #fff !important;
}

/* Global fixed topbar */
.app-topbar {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: min(100%, 1240px);
    z-index: 2600;
    box-sizing: border-box;
    padding: 0.28rem 0.45rem;
    background: #f3f1ff;
    border-bottom: 1px solid #c9c4e8;
    box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}

.app-topbar-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.25rem;
    overflow-x: auto;
    align-items: center;
    justify-content: flex-start;
}

.app-topbar a,
.app-topbar button,
.fullscreen-topbar-button {
    flex: 0 0 auto;
    margin: 0;
    padding: 0.28rem 0.45rem;
    font-size: calc(0.8rem * var(--font-scale));
    line-height: 1.1;
    white-space: nowrap;
    border: 1px solid #aaa;
    border-radius: 0.35rem;
    background: #fff;
    color: #111;
    text-decoration: none;
}

.app-topbar .icon-action,
.app-topbar .theme-toggle {
    width: 2rem;
    min-width: 2rem;
    padding-left: 0 !important;
    padding-right: 0 !important;
    font-size: calc(1rem * var(--font-scale)) !important;
}

.app-topbar .active-nav,
.fullscreen-topbar-button.active-nav {
    background: #e8e6ff !important;
    border-color: #777 !important;
    font-weight: 700 !important;
    box-shadow: inset 0 0 0 1px #777 !important;
}

/* Page title */
.page-title-row {
    margin: 0 0 0.45rem 0;
    padding: 0;
    border-bottom: 1px solid #ddd;
}

.page-title-row h1 {
    margin: 0;
    padding: 0.15rem 0 0.3rem 0;
    font-size: calc(1.15rem * var(--font-scale));
    line-height: 1.15;
}

/* Hide old header if any remains */
.page-header {
    display: none !important;
}

/* Forms and cards */
.date-form {
    margin-top: 0.25rem !important;
    margin-bottom: 0.45rem !important;
}

.summary.compact-summary {
    margin-top: 0.45rem !important;
    margin-bottom: 0.7rem !important;
}

/* Map */
body.map-page #map {
    width: 100% !important;
    box-sizing: border-box !important;
}

.map-settings {
    display: none;
}

.map-settings.open {
    display: block;
}

.map-settings,
.map-settings * {
    text-align: left !important;
}

.map-settings .map-controls {
    display: block !important;
    padding: 0.5rem !important;
    margin: 0.4rem 0 0.6rem 0 !important;
}

.map-control-title {
    display: block !important;
    font-weight: 700 !important;
    font-size: calc(0.85rem * var(--font-scale)) !important;
    margin: 0.45rem 0 0.2rem 0 !important;
}

.map-view-buttons,
.marker-mode-buttons,
.map-overlay-buttons,
.export-buttons {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.3rem !important;
    align-items: center !important;
    justify-content: flex-start !important;
    margin: 0 0 0.35rem 0 !important;
}

.map-view-buttons button,
.marker-mode-buttons button,
.map-overlay-buttons button,
.export-buttons a {
    margin: 0 !important;
    padding: 0.25rem 0.45rem !important;
    font-size: calc(0.8rem * var(--font-scale)) !important;
    line-height: 1.2 !important;
    border: 1px solid #aaa !important;
    border-radius: 0.35rem !important;
    background: #fff !important;
    color: #111 !important;
    text-decoration: none !important;
}

.map-view-buttons button.active,
.marker-mode-buttons button.active,
.map-overlay-buttons button.active {
    background: #e8e6ff !important;
    border-color: #777 !important;
    font-weight: 700 !important;
}

.export-buttons span {
    font-size: calc(0.85rem * var(--font-scale)) !important;
    margin-right: 0.25rem !important;
}

.light-pollution-settings {
    max-width: 28rem;
    margin: 0.1rem 0 0.55rem;
    padding: 0.45rem 0.55rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.4rem;
    background: #f8fafc;
}

.light-pollution-settings label,
.light-pollution-settings small {
    display: block;
    font-size: calc(0.75rem * var(--font-scale));
}

.light-pollution-settings input[type="range"] {
    width: 100%;
    min-height: 1.5rem !important;
}

.light-pollution-scale {
    display: grid;
    grid-template-columns: max-content 1fr max-content;
    gap: 0.4rem;
    align-items: center;
    font-size: calc(0.7rem * var(--font-scale));
}

.light-pollution-scale i {
    height: 0.55rem;
    border-radius: 999px;
    background: linear-gradient(90deg, #3b82f6, #06b6d4, #22c55e, #facc15, #f97316, #ef4444);
}

html[data-theme="dark"] .light-pollution-settings {
    color: #e5e7eb;
    background: #1f2937;
    border-color: #4b5563;
}

/* Fullscreen map */
.fullscreen-topbar {
    display: none;
}

body.fullscreen-map .app-topbar,
body.fullscreen-map .page-title-row {
    display: none !important;
}

body.fullscreen-map .container {
    max-width: none !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

body.fullscreen-map .fullscreen-topbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 42px !important;
    z-index: 2600 !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 0.25rem !important;
    overflow: hidden !important;
    padding: 4px max(4px, env(safe-area-inset-right)) 4px max(4px, env(safe-area-inset-left)) !important;
    box-sizing: border-box !important;
    background: #f3f1ff !important;
    border-bottom: 1px solid #c9c4e8 !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.18) !important;
}

body.fullscreen-map #map {
    top: 42px !important;
    height: calc(100vh - 42px) !important;
    height: calc(100dvh - 42px) !important;
}

body.fullscreen-map .leaflet-top {
    top: 10px !important;
}

body.fullscreen-map .fullscreen-map-button,
body.fullscreen-map .exit-fullscreen-map {
    display: none !important;
}

/* Desktop */
@media (min-width: 900px) {
    .container {
        padding-left: 1.25rem !important;
        padding-right: 1.25rem !important;
    }

    .app-topbar {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }
}

/* Mobile */
@media (max-width: 520px) {
    .container {
        padding-top: 3.1rem !important;
        padding-left: 0.45rem !important;
        padding-right: 0.45rem !important;
    }

    .app-topbar {
        padding-left: 0.2rem;
        padding-right: 0.2rem;
    }

    .app-topbar-actions {
        gap: 0.15rem;
    }

    .app-topbar a,
    .app-topbar button,
    .fullscreen-topbar-button {
        font-size: calc(0.74rem * var(--font-scale)) !important;
        padding-left: 0.34rem !important;
        padding-right: 0.34rem !important;
    }

    .app-topbar .icon-action,
    .app-topbar .theme-toggle {
        width: 1.8rem;
        min-width: 1.8rem;
        padding-left: 0 !important;
        padding-right: 0 !important;
        font-size: calc(0.95rem * var(--font-scale)) !important;
    }

    body.fullscreen-map .fullscreen-topbar {
        gap: 3px !important;
    }

    body.fullscreen-map .fullscreen-topbar-button {
        flex: 0 1 auto;
        min-width: 0;
        padding-left: 0.38rem !important;
        padding-right: 0.38rem !important;
        overflow: hidden;
    }

    body.fullscreen-map .fullscreen-icon-button,
    body.fullscreen-map .fullscreen-topbar .theme-toggle {
        flex: 0 0 2rem;
        width: 2rem;
        min-width: 2rem !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        font-size: calc(1rem * var(--font-scale)) !important;
    }

    .page-title-row h1 {
        font-size: calc(1.05rem * var(--font-scale));
    }
}

.content-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.8rem;
}

.content-tabs a {
    border: 1px solid #aaa;
    border-radius: 0.35rem;
    background: #fff;
    color: #111;
    text-decoration: none;
    padding: 0.28rem 0.45rem;
    font-size: calc(0.85rem * var(--font-scale));
}

.content-tabs a.active-nav {
    background: #e8e6ff;
    border-color: #777;
    font-weight: 700;
    box-shadow: inset 0 0 0 1px #777;
}

/* Unified typography and button sizing */
:root {
    --ui-font: calc(0.9rem * var(--font-scale));
    --ui-font-small: calc(0.82rem * var(--font-scale));
    --ui-title: calc(1.08rem * var(--font-scale));
    --ui-button-y: 0.32rem;
    --ui-button-x: 0.55rem;
}

button,
.form-button,
.export-link,
.small-action,
.app-topbar a,
.app-topbar button,
.fullscreen-topbar-button,
.map-view-buttons button,
.marker-mode-buttons button,
.map-overlay-buttons button,
.export-buttons a,
.content-tabs a {
    font-size: var(--ui-font-small) !important;
    line-height: 1.15 !important;
    padding: var(--ui-button-y) var(--ui-button-x) !important;
    min-height: 2rem !important;
    box-sizing: border-box !important;
}

input,
select,
.date-form input,
.date-form button {
    font-size: var(--ui-font) !important;
    line-height: 1.2 !important;
    min-height: 2rem !important;
    box-sizing: border-box !important;
}

body,
.summary-main,
.summary-line,
.day-row,
.trip-item,
.content-page-body {
    font-size: var(--ui-font) !important;
    line-height: 1.4 !important;
}

.page-title-row h1 {
    font-size: var(--ui-title) !important;
    line-height: 1.15 !important;
}

.meta,
.site-footer,
.map-control-title,
.export-buttons span {
    font-size: var(--ui-font-small) !important;
}

/* Align topbar link and button labels identically */
.app-topbar a,
.app-topbar button,
.fullscreen-topbar-button {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
    vertical-align: middle !important;
    min-height: 2rem !important;
}

/* True fullscreen map: hide all normal page content except map and fullscreen topbar */
body.fullscreen-map .page-title-row,
body.fullscreen-map .date-form,
body.fullscreen-map .summary,
body.fullscreen-map .map-settings,
body.fullscreen-map #map-status,
body.fullscreen-map #latest-position-status,
body.fullscreen-map .map-trip-list,
body.fullscreen-map .trip-map-actions,
body.fullscreen-map .day-card,
body.fullscreen-map .site-footer {
    display: none !important;
}

body.fullscreen-map #map {
    position: fixed !important;
    top: 42px !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: calc(100vh - 42px) !important;
    height: calc(100dvh - 42px) !important;
    min-height: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    z-index: 1000 !important;
}

body.fullscreen-map .fullscreen-topbar {
    z-index: 2600 !important;
}

body.fullscreen-map .leaflet-control-container {
    z-index: 1500 !important;
}

body.fullscreen-map .leaflet-bottom {
    bottom: max(4px, env(safe-area-inset-bottom)) !important;
}

.fullscreen-label-compact {
    display: none;
}

@media (max-width: 520px) {
    .fullscreen-label-full {
        display: none;
    }

    .fullscreen-label-compact {
        display: inline;
    }
}

html[data-theme="dark"] body.map-page,
html[data-theme="dark"] body.report-page {
    background: #030712;
}

html[data-theme="dark"] .container {
    background: #111827 !important;
}

html[data-theme="dark"] .app-topbar,
html[data-theme="dark"] body.fullscreen-map .fullscreen-topbar {
    background: #172033 !important;
    border-color: #374151 !important;
}

html[data-theme="dark"] .app-topbar a,
html[data-theme="dark"] .app-topbar button,
html[data-theme="dark"] .fullscreen-topbar-button,
html[data-theme="dark"] .content-tabs a,
html[data-theme="dark"] .map-view-buttons button,
html[data-theme="dark"] .marker-mode-buttons button,
html[data-theme="dark"] .map-overlay-buttons button,
html[data-theme="dark"] .export-buttons a {
    color: #e5e7eb !important;
    background: #1f2937 !important;
    border-color: #4b5563 !important;
}

html[data-theme="dark"] .app-topbar .active-nav,
html[data-theme="dark"] .fullscreen-topbar-button.active-nav,
html[data-theme="dark"] .content-tabs a.active-nav,
html[data-theme="dark"] .map-view-buttons button.active,
html[data-theme="dark"] .marker-mode-buttons button.active,
html[data-theme="dark"] .map-overlay-buttons button.active {
    background: #37335f !important;
    border-color: #8b8ab5 !important;
    box-shadow: inset 0 0 0 1px #8b8ab5 !important;
}

html[data-theme="dark"] .page-title-row {
    border-color: #374151;
}
