:root {
    --font-scale: 1;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: calc(16px * var(--font-scale));
    color: #111;
}

a {
    color: #2563eb;
}

button,
.form-button,
.export-link,
.small-action {
    border: 1px solid #aaa;
    border-radius: 0.35rem;
    background: #fff;
    color: #111;
    padding: 0.35rem 0.6rem;
    font-size: calc(0.95rem * var(--font-scale));
    text-decoration: none;
    cursor: pointer;
}

button:hover,
.form-button:hover,
.export-link:hover,
.small-action:hover {
    background: #f1f1f1;
}

input,
select {
    font-size: calc(1rem * var(--font-scale));
    padding: 0.3rem;
    box-sizing: border-box;
}

.date-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.date-form label {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.date-form .form-help {
    flex-basis: 100%;
    color: #667085;
    font-size: 0.9em;
}

.summary,
.compact-summary {
    background: #f7f7f7;
    border: 1px solid #ddd;
    border-radius: 0.45rem;
    padding: 0.65rem;
    box-sizing: border-box;
}

.summary-main,
.summary-line {
    line-height: 1.45;
}

.meta {
    color: #555;
    font-size: calc(0.9rem * var(--font-scale));
}

#map {
    height: 68vh;
    min-height: 420px;
    width: 100%;
    border: 1px solid #ccc;
    border-radius: 0.45rem;
    box-sizing: border-box;
}

#map-status {
    margin: 0.4rem 0;
    color: #555;
}

.map-symbol-marker {
    border: 0;
    background: transparent;
}

.map-symbol-marker-glyph {
    position: absolute;
    left: 50%;
    top: 50%;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: var(--marker-size);
    height: var(--marker-size);
    transform: translate(-50%, -50%);
    border: 2px solid #ffffff;
    border-radius: 50%;
    color: #ffffff;
    box-shadow: 0 2px 7px rgba(17, 24, 39, 0.45);
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
    box-sizing: border-box;
}

.overnight-marker {
    background: #6d28d9;
    font-size: calc(var(--marker-size) * 0.65);
}

.overnight-marker-group {
    background: #581c87;
    font-size: calc(var(--marker-size) * 0.48);
}

.google-place-marker {
    background: #d97706;
    font-size: calc(var(--marker-size) * 0.6);
}

.google-place-marker.google-place-visited {
    background: #15803d;
}

.google-place-marker.google-place-possible {
    background: #2563eb;
}

.place-visit-form {
    display: grid;
    gap: 0.4rem;
    margin-top: 0.6rem;
}

.place-visit-row {
    margin: 0.35rem 0;
}

.place-dismiss-button {
    float: right;
    min-width: 36px;
    min-height: 36px;
    margin-left: 0.3rem;
    font-size: 1.3rem;
}

.place-trip-result,
.place-trip-result a {
    display: block;
    margin-top: 0.25rem;
}

.place-visit-form input {
    max-width: 100%;
}

.google-place-popup {
    min-width: 210px;
}

.google-place-popup p {
    margin: 0.4rem 0 0;
}

.overnight-popup {
    min-width: 230px;
}

.overnight-popup p {
    margin: 0.35rem 0;
}

.overnight-popup-category {
    display: inline-block;
    margin: 0.25rem 0;
    padding: 0.15rem 0.4rem;
    border-radius: 999px;
    color: #4c1d95;
    background: #ede9fe;
    font-weight: 700;
}

.overnight-description {
    padding: 0.4rem 0.5rem;
    border-left: 3px solid #8b5cf6;
    background: #f5f3ff;
}

.overnight-editor {
    display: grid;
    gap: 0.4rem;
    margin-top: 0.6rem;
    padding-top: 0.55rem;
    border-top: 1px solid #d1d5db;
}

.overnight-editor label {
    font-weight: 700;
}

.overnight-editor select,
.overnight-editor input {
    box-sizing: border-box;
    width: 100%;
    padding: 0.4rem;
}

.overnight-editor button {
    justify-self: start;
}

.overnight-save-status {
    min-height: 1.1em;
    color: #4b5563;
    font-size: 0.9em;
}

.overnight-list-item {
    margin-top: 0.35rem;
    border-top: 1px solid #d1d5db;
}

.overnight-list-item summary {
    padding: 0.5rem 0.15rem;
    font-weight: 700;
    cursor: pointer;
}

.overnight-list-body {
    padding: 0 0.2rem 0.55rem;
}

.map-trip-list {
    margin-top: 0.8rem;
}

.trip-map-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.6rem 0;
}

.day-card {
    border: 1px solid #ddd;
    border-radius: 0.45rem;
    margin: 0.65rem 0;
    background: #fff;
    overflow: hidden;
}

.day-row {
    display: flex;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.65rem;
    background: #f7f7f7;
}

.day-toggle {
    cursor: pointer;
    font-weight: 700;
}

.day-trips {
    padding: 0.65rem;
}

.trip-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.trip-item {
    border-top: 1px solid #eee;
    padding: 0.55rem 0;
}

.trip-item:first-child {
    border-top: 0;
}

.day-color-dot {
    display: inline-block;
    width: 0.75em;
    height: 0.75em;
    border-radius: 50%;
    margin-right: 0.35rem;
    vertical-align: middle;
    border: 1px solid #fff;
    box-shadow: 0 0 0 1px #777;
}

.summary-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.4rem;
}

.summary-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.summary-table th,
.summary-table td {
    border-bottom: 1px solid #ddd;
    padding: 0.35rem;
    text-align: left;
}

.summary-table th {
    background: #f3f3f3;
}

.summary-day-heading th {
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
    background: #e8eef5;
}

.summary-day-heading-content {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
}

.summary-day-totals {
    color: #4b5563;
    font-size: calc(0.88rem * var(--font-scale));
    font-weight: 600;
    text-align: right;
}

.summary-map-link {
    display: inline-block;
    white-space: nowrap;
    font-weight: 600;
}

.summary-overnight-action {
    display: block;
    margin-top: 0.25rem;
}

.summary-trip-time,
.summary-trip-row td:nth-child(n+3) {
    white-space: nowrap;
}

.map-trip-row.selected-map-trip td {
    background: #dbeafe;
    box-shadow: inset 0 1px #93c5fd, inset 0 -1px #93c5fd;
}

.map-trip-row.selected-map-trip td:first-child {
    box-shadow: inset 3px 0 #2563eb, inset 0 1px #93c5fd, inset 0 -1px #93c5fd;
}

.map-trip-row.selected-map-overnight td {
    background: #f3e8ff;
    box-shadow: inset 0 1px #c084fc, inset 0 -1px #c084fc;
}

.map-trip-row.selected-map-overnight td:first-child {
    box-shadow: inset 3px 0 #9333ea, inset 0 1px #c084fc, inset 0 -1px #c084fc;
}

.summary-trip-detail td {
    padding-top: 0.2rem;
    padding-left: 0.7rem;
    background: #f8fafc;
}

.summary-trip-detail .meta + .meta {
    margin-left: 0.75rem;
}

.site-footer {
    margin-top: 2rem;
    padding: 0.5rem 0 0.3rem;
    text-align: center;
    font-size: calc(0.62rem * var(--font-scale));
    line-height: 1.2;
    color: #999;
    border-top: 1px solid #ececec;
    opacity: 0.8;
}

.site-footer div {
    margin: 0.05rem 0;
}

.adblue-ok {
    color: #166534;
    font-weight: 700;
}

.adblue-warn {
    color: #b45309;
    font-weight: 700;
}

.adblue-alert {
    color: #b91c1c;
    font-weight: 700;
}

@media (max-width: 520px) {
    /* Keep map controls behind an open popup. Leaflet normally places controls
       above the popup pane, which hides the close button on narrow screens. */
    #map .leaflet-popup-pane {
        z-index: 1000;
    }

    #map .leaflet-popup {
        max-width: calc(100vw - 3rem);
    }

    #map .leaflet-popup-content-wrapper {
        max-height: min(58dvh, 430px);
        overflow: hidden;
    }

    #map .leaflet-popup-content {
        width: min(calc(100vw - 8rem), 320px) !important;
        max-width: none;
        max-height: min(52dvh, 375px);
        margin: 1rem 1.1rem;
        padding-right: 0.35rem;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-gutter: stable;
    }

    #map .overnight-popup {
        min-width: 0;
    }

    #map .overnight-editor input,
    #map .overnight-editor select {
        box-sizing: border-box;
        width: 100%;
    }

    #map .leaflet-control-layers-toggle {
        width: 36px;
        height: 36px;
        background-size: 24px 24px;
    }

    #map {
        height: 58vh;
        min-height: 330px;
    }

    .date-form input[type="date"] {
        max-width: 9.2rem;
    }

    button,
    .form-button,
    .export-link,
    .small-action {
        font-size: calc(0.9rem * var(--font-scale));
        padding: 0.32rem 0.5rem;
    }

    .summary,
    .compact-summary,
    .day-row,
    .day-trips {
        padding: 0.55rem;
    }

    .summary-trip-table {
        font-size: calc(0.82rem * var(--font-scale));
    }

    .summary-trip-table th,
    .summary-trip-table td {
        padding: 0.3rem;
    }

    .summary-day-heading-content {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.15rem;
    }

    .summary-day-totals {
        text-align: left;
    }
}

/* Collapsible day/week lists */
.day-trips {
    display: none;
}

.day-trips.open {
    display: block;
}

/* Summary weeks default collapsed */
.summary-week {
    display: none;
}

.summary-week.open {
    display: block;
}

.content-page-body h1,
.content-page-body h2,
.content-page-body h3 {
    margin-top: 1rem;
}

.content-page-body pre {
    overflow-x: auto;
    background: #f3f3f3;
    padding: 0.6rem;
    border-radius: 0.35rem;
}

.content-page-body code {
    background: #f3f3f3;
    padding: 0.1rem 0.25rem;
    border-radius: 0.25rem;
}

/* Speed color legend */
.speed-legend,
.altitude-legend {
    background: rgba(255, 255, 255, 0.9);
    padding: 0.45rem 0.55rem;
    border-radius: 0.35rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
    font-size: calc(0.85rem * var(--font-scale));
    line-height: 1.35;
}

.speed-legend .legend-title,
.altitude-legend .legend-title {
    margin-bottom: 0.18rem;
    font-weight: 700;
}

.speed-legend .legend-items,
.altitude-legend .legend-items {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.08rem 0.65rem;
}

.speed-legend .legend-item,
.altitude-legend .legend-item {
    white-space: nowrap;
}

.speed-legend .legend-line,
.altitude-legend .legend-line {
    display: inline-block;
    width: 1.4rem;
    height: 0.35rem;
    margin-right: 0.35rem;
    vertical-align: middle;
    border-radius: 0.25rem;
}

.altitude-legend {
    max-height: 55vh;
    overflow-y: auto;
    font-size: calc(0.78rem * var(--font-scale));
    line-height: 1.25;
}

.altitude-legend .legend-line {
    width: 1.1rem;
}

.speed-legend .legend-line.gray,
.altitude-legend .legend-line.gray {
    background: #6b7280;
}

.speed-legend .legend-line.green,
.altitude-legend .legend-line.green {
    background: #16a34a;
}

.speed-legend .legend-line.blue,
.altitude-legend .legend-line.blue {
    background: #2563eb;
}

.speed-legend .legend-line.cyan,
.altitude-legend .legend-line.cyan {
    background: #06b6d4;
}

.speed-legend .legend-line.orange,
.altitude-legend .legend-line.orange {
    background: #f59e0b;
}

.speed-legend .legend-line.red,
.altitude-legend .legend-line.red {
    background: #dc2626;
}


/* Mobiilikartan popupin selkeä sulkemispainike */
@media (max-width: 520px) {
    .speed-legend,
    .altitude-legend {
        max-width: calc(100vw - 4.5rem);
        max-height: calc(100dvh - 8.5rem);
        overflow-y: auto;
        padding: 0.35rem 0.45rem;
        font-size: calc(0.72rem * var(--font-scale));
        line-height: 1.2;
    }

    .speed-legend .legend-items,
    .altitude-legend .legend-items {
        grid-template-columns: repeat(2, max-content);
        gap: 0.12rem 0.55rem;
    }

    .speed-legend .legend-line,
    .altitude-legend .legend-line {
        width: 1rem;
        margin-right: 0.22rem;
    }

    #map .leaflet-popup-close-button {
        width: 36px !important;
        height: 36px !important;
        font-size: 26px !important;
        line-height: 34px !important;
        color: #222 !important;
        background: rgba(255, 255, 255, 0.95) !important;
        border-radius: 0 12px 0 12px !important;
        z-index: 1001 !important;
    }
}


/* Yhteenvetolaatikko toimii matkalistan linkkinä */
.summary-trip-link {
    display: block;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
    -webkit-tap-highlight-color: rgba(37, 99, 235, 0.15);
}

.summary-trip-link:hover,
.summary-trip-link:focus-visible {
    background: #eef5ff;
    border-color: #93a4b8;
    outline: none;
}

.summary-trip-link:active {
    background: #e2ecf8;
}

/* Dark color theme */
html[data-theme="dark"] body {
    color: #e5e7eb;
}

html[data-theme="dark"] a {
    color: #93c5fd;
}

html[data-theme="dark"] button,
html[data-theme="dark"] .form-button,
html[data-theme="dark"] .export-link,
html[data-theme="dark"] .small-action,
html[data-theme="dark"] input,
html[data-theme="dark"] select {
    color: #e5e7eb;
    background: #1f2937;
    border-color: #4b5563;
}

html[data-theme="dark"] button:hover,
html[data-theme="dark"] .form-button:hover,
html[data-theme="dark"] .export-link:hover,
html[data-theme="dark"] .small-action:hover {
    background: #374151;
}

html[data-theme="dark"] .summary,
html[data-theme="dark"] .compact-summary,
html[data-theme="dark"] .day-row {
    background: #1f2937;
    border-color: #374151;
}

html[data-theme="dark"] .day-card {
    color: #e5e7eb;
    background: #111827;
    border-color: #374151;
}

html[data-theme="dark"] .trip-item,
html[data-theme="dark"] .summary-table th,
html[data-theme="dark"] .summary-table td {
    border-color: #374151;
}

html[data-theme="dark"] .summary-table th,
html[data-theme="dark"] .content-page-body pre,
html[data-theme="dark"] .content-page-body code {
    background: #1f2937;
}

html[data-theme="dark"] .summary-day-heading th {
    background: #263449;
}

html[data-theme="dark"] .summary-day-totals {
    color: #cbd5e1;
}

html[data-theme="dark"] .map-trip-row.selected-map-trip td {
    background: #1e3a5f;
    box-shadow: inset 0 1px #3b82f6, inset 0 -1px #3b82f6;
}

html[data-theme="dark"] .map-trip-row.selected-map-trip td:first-child {
    box-shadow: inset 3px 0 #60a5fa, inset 0 1px #3b82f6, inset 0 -1px #3b82f6;
}

html[data-theme="dark"] .map-trip-row.selected-map-overnight td {
    background: #3b1f5c;
    box-shadow: inset 0 1px #a855f7, inset 0 -1px #a855f7;
}

html[data-theme="dark"] .map-trip-row.selected-map-overnight td:first-child {
    box-shadow: inset 3px 0 #c084fc, inset 0 1px #a855f7, inset 0 -1px #a855f7;
}

html[data-theme="dark"] .summary-trip-detail td {
    background: #172033;
}

html[data-theme="dark"] .meta,
html[data-theme="dark"] #map-status,
html[data-theme="dark"] .site-footer {
    color: #9ca3af;
}

html[data-theme="dark"] .summary-trip-link:hover,
html[data-theme="dark"] .summary-trip-link:focus-visible {
    background: #263449;
    border-color: #64748b;
}

html[data-theme="dark"] .summary-trip-link:active {
    background: #334155;
}

html[data-theme="dark"] .speed-legend,
html[data-theme="dark"] .altitude-legend,
html[data-theme="dark"] .leaflet-popup-content-wrapper,
html[data-theme="dark"] .leaflet-popup-tip {
    color: #e5e7eb;
    background: rgba(17, 24, 39, 0.94);
}

html[data-theme="dark"] .leaflet-popup-close-button {
    color: #e5e7eb !important;
}

html[data-theme="dark"] .overnight-popup-category {
    color: #ede9fe;
    background: #4c1d95;
}

html[data-theme="dark"] .overnight-description {
    background: #312e4f;
}

html[data-theme="dark"] .overnight-editor {
    border-color: #4b5563;
}

html[data-theme="dark"] .overnight-list-item {
    border-color: #4b5563;
}

html[data-theme="dark"] .overnight-save-status {
    color: #d1d5db;
}

html[data-theme="dark"] .adblue-ok {
    color: #86efac;
}

html[data-theme="dark"] .adblue-warn {
    color: #fcd34d;
}

html[data-theme="dark"] .adblue-alert {
    color: #fca5a5;
}

.login-container {
    max-width: 480px;
    padding-top: 8vh;
}

.login-card {
    padding: 24px;
}

.login-form {
    display: grid;
    gap: 18px;
}

.login-form label:not(.login-remember) {
    display: grid;
    gap: 7px;
    font-weight: 600;
}

.login-form input[type="text"],
.login-form input[type="password"] {
    box-sizing: border-box;
    width: 100%;
}

.login-remember {
    display: flex;
    align-items: center;
    gap: 9px;
}

.login-error {
    margin-top: 0;
    color: #b91c1c;
    font-weight: 700;
}

html[data-theme="dark"] .login-error {
    color: #fca5a5;
}
