/*
 * Look and feel modelled after the former desktop client (FlatLaf macOS themes).
 * The theme follows the operating system / browser setting.
 */
:root {
    color-scheme: light dark;
    --bg: #ffffff;
    --bg-content: #f7f8fa;
    --fg: #1a1c20;
    --fg-muted: #6b7280;
    --border: #d5d8de;
    --separator: #e5e7eb;
    --control-bg: #ffffff;
    --control-hover: #eef0f4;
    --accent: #007aff;
    --accent-fg: #ffffff;
    --danger: #dc3545;
    --danger-fg: #ffffff;
    --alert-info-bg: #dbeafe;
    --alert-error-bg: #fde2e4;
    --radius: 8px;
    --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 10%);
    --transition: 120ms ease;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #16181d;
        --bg-content: #1d2026;
        --fg: #e8eaed;
        --fg-muted: #9aa0aa;
        --border: #3a3f48;
        --separator: #2a2e36;
        --control-bg: #262a32;
        --control-hover: #2f343d;
        --accent: #0a84ff;
        --alert-info-bg: #1b3556;
        --alert-error-bg: #5a2328;
    }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--fg);
    font: 15px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.5em; }
h2 { font-size: 1.25em; }
h3 { font-size: 1.1em; }

label { color: var(--fg-muted); font-size: .93em; font-weight: 500; }
.checkbox, .checkbox span { color: var(--fg); font-size: 1em; font-weight: 400; }

a { color: var(--accent); }

/* Main tabs */
.tabbar, .subtabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--separator);
    background: var(--bg);
}

.tabbar { padding: 8px 12px; }

.tab {
    padding: 6px 16px;
    color: var(--fg-muted);
    text-decoration: none;
    border-radius: 999px;
}

.tab { transition: background var(--transition), border-color var(--transition); }
.tab:hover { background: var(--control-hover); color: var(--fg); }
.tab.selected { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 600; }

.content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-content);
    padding: 12px;
}

/* Centered block with spacers around, like the GridLayout forms of the desktop client */
.center {
    margin: auto;
    width: min(100%, 460px);
}

/* Form controls */
input[type=text], input[type=password], input[type=url], input[type=number], input[type=date], textarea, select {
    width: 100%;
    padding: 6px 10px;
    color: var(--fg);
    background: var(--control-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
}

input:hover:not(:focus):not([readonly]), textarea:hover:not(:focus), select:hover:not(:focus) {
    border-color: var(--fg-muted);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

input[readonly] { color: var(--fg-muted); }
textarea { resize: none; }

.form-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 10px;
    align-items: center;
}

.form-stack { display: flex; flex-direction: column; gap: 4px; }
.form-stack > label { margin-top: 8px; }
.form-stack > label:first-child { margin-top: 0; }

button, .button {
    display: inline-block;
    padding: 6px 16px;
    font-weight: 500;
    color: var(--fg);
    background: var(--control-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: background var(--transition), border-color var(--transition), filter var(--transition), transform var(--transition);
}

button:hover:not(:disabled), .button:hover { background: var(--control-hover); }
button:active:not(:disabled), .button:active { transform: translateY(1px); box-shadow: none; }
button:disabled { opacity: .45; cursor: default; }

button.primary { color: var(--accent-fg); background: var(--accent); border-color: var(--accent); }
button.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.1); }
button.danger { color: var(--danger-fg); background: var(--danger); border-color: var(--danger); }
button.danger:hover:not(:disabled) { background: var(--danger); filter: brightness(1.1); }
button.toggle[aria-pressed=true] { color: var(--accent-fg); background: var(--accent); border-color: var(--accent); }

.button-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.spacer { flex: 1; }
.checkbox { display: inline-flex; gap: 6px; align-items: center; }
[hidden] { display: none !important; }

/* Messages */
.flash { padding: 8px 12px 0; background: var(--bg-content); }
.alert {
    --alert-color: var(--accent);
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 14px;
    border: 1px solid color-mix(in srgb, var(--alert-color) 30%, transparent);
    border-left: 4px solid var(--alert-color);
    border-radius: var(--radius);
    background: var(--alert-info-bg);
}

.alert::before {
    content: "i";
    flex: none;
    width: 1.4em;
    height: 1.4em;
    border-radius: 50%;
    color: var(--accent-fg);
    background: var(--alert-color);
    font-size: .9em;
    font-weight: 700;
    line-height: 1.4em;
    text-align: center;
}

.alert-error { --alert-color: var(--danger); background: var(--alert-error-bg); }
.alert-error::before { content: "!"; }

/* Dialogs (login page, confirmations) */
.login-page { align-items: center; justify-content: center; background: var(--bg-content); }

.dialog {
    width: min(92vw, 420px);
    padding: 28px;
    background: var(--bg);
    border: 1px solid var(--separator);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgb(16 24 40 / 10%), 0 2px 6px rgb(16 24 40 / 6%);
}

.dialog-title { margin-bottom: 18px; font-size: 1.4em; font-weight: 600; text-align: center; }
.dialog .alert { margin-bottom: 12px; }
.dialog-buttons { display: flex; gap: 8px; align-items: center; margin-top: 16px; }

dialog.modal {
    width: min(92vw, 460px);
    padding: 24px;
    color: var(--fg);
    background: var(--bg);
    border: 1px solid var(--separator);
    border-radius: 14px;
    box-shadow: 0 20px 50px rgb(16 24 40 / 25%);
}

dialog.modal::backdrop { background: rgb(16 24 40 / 45%); backdrop-filter: blur(2px); }
dialog.modal h3 { margin-bottom: 10px; font-size: 1.05em; }
dialog.modal .modal-body { margin-bottom: 4px; }
dialog.modal .dialog-buttons { justify-content: flex-end; }

/* About */
.about { align-items: center; gap: 16px; }
.about-logo { flex: 1; min-height: 0; width: 100%; display: flex; justify-content: center; }
.about-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.about-info { text-align: center; padding-bottom: 8px; }

dialog.modal:has(.license-text) { width: min(92vw, 780px); }
.license-text { max-height: 55vh; overflow: auto; font-family: ui-monospace, "DejaVu Sans Mono", monospace;
    font-size: 12px; white-space: pre-wrap; }

/* Dashboard */
.dashboard { display: flex; flex-direction: column; gap: 10px; width: min(100%, 520px); }
.dashboard > div { padding: 14px 18px; background: var(--bg); border: 1px solid var(--separator); border-radius: 12px; box-shadow: var(--shadow); font-size: 1.05em; }

/* Debug table */
.grid-table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--bg); border: 1px solid var(--separator); border-radius: 12px; overflow: hidden; }
.grid-table th, .grid-table td { padding: 8px 14px; text-align: left; border-bottom: 1px solid var(--separator); }
.grid-table th { color: var(--fg-muted); background: var(--bg-content); font-size: .85em; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.grid-table tbody tr:last-child td { border-bottom: 0; }
.grid-table tbody tr:hover td { background: var(--control-hover); }

/* Species tab */
.species-back { display: none; }
.species-tab { flex-direction: row; gap: 0; padding: 0; }

.species-sidebar {
    flex: 0 0 260px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-right: 1px solid var(--separator);
}

.species-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 2px; }

/* Rounded entries, the selected one is tinted */
.species-item {
    display: block;
    flex: none;
    min-height: 2.6em;
    padding: 6px 12px;
    color: var(--fg);
    text-decoration: none;
    border-radius: var(--radius);
    transition: background var(--transition);
}

.species-item:hover { background: var(--control-hover); }
.species-item[aria-current] { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.species-item[aria-current] > :first-child { color: var(--accent); font-weight: 600; }
.species-item.extinct { color: var(--fg-muted); }
.species-item .origin { display: block; color: var(--fg-muted); font-size: .9em; }

.species-sidebar-buttons { display: flex; flex-direction: column; gap: 6px; padding: 8px; }
.species-sidebar-buttons button { width: 100%; }

.species-empty { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; color: var(--fg-muted); text-align: center; }
.species-detail { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.subtabs { padding: 8px 12px; }
.subtab-content { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 12px; }

/* Species info */
.species-info { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 40%); gap: 16px; }
.species-info-fields { display: flex; flex-direction: column; gap: 4px; min-height: 0; }
.species-info-fields textarea { flex: 1; min-height: 6em; }
.species-info-fields > label { margin-top: 8px; }
/* As many columns as fit: the three fields of a form share one row on wide panes, which leaves more height for the notes */
.form-grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.species-info-side { display: flex; flex-direction: column; gap: 4px; min-height: 0; }
.species-image { flex: 1; min-height: 120px; display: flex; align-items: center; justify-content: center; }
.species-image img { max-width: 100%; max-height: 100%; object-fit: contain; }
.iucn-status { padding-top: 8px; }
.iucn-svg { width: 100%; height: auto; color: var(--fg); font-family: var(--font); }


/* Ancestry */
.ancestry { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.ancestry .button-row { margin-top: 0; }

.split {
    --split-left: 50%;
    flex: 1;
    min-height: 0;
    display: flex;
    border: 1px solid var(--separator);
    border-radius: 12px;
    background: var(--bg);
    overflow: hidden;
}

.split-left { flex: 0 0 var(--split-left); min-width: 0; overflow: auto; }
.split-right { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 8px; }
.split-divider { flex: 0 0 10px; cursor: col-resize; background: var(--bg); border-left: 1px solid var(--separator);
    border-right: 1px solid var(--separator); }
.split-divider:hover { background: var(--control-hover); }

.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 4px; padding-top: 8px; }
.pane > label { margin-top: 8px; }
.pane textarea { flex: 1; min-height: 5em; }
.population-id { width: 8em; align-self: flex-end; text-align: right; }

/* Diagram */
.diagram { min-height: 100%; display: flex; padding: 16px; }

.diagram-grid {
    position: relative;
    display: grid;
    gap: 36px 30px;
    justify-content: center;
    /* margin:auto centers without cutting off the start when the diagram is wider than the pane */
    margin: auto;
}

.diagram-lines { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.diagram-lines line { stroke: var(--fg-muted); stroke-width: 2; stroke-linecap: round; opacity: .7; }

.diagram-point {
    position: relative;
    z-index: 1;
    min-width: 2.6em;
    min-height: 2.6em;
    aspect-ratio: 1;
    padding: 0 6px;
    border-radius: 999px;
    font-weight: 600;
    box-shadow: 0 2px 6px rgb(16 24 40 / 14%);
}

.diagram-point:hover { border-color: var(--accent); }
.diagram-point.selected {
    color: var(--accent-fg);
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent), 0 2px 6px rgb(16 24 40 / 20%);
}
.diagram-point.extinct:not(.selected) { color: var(--fg-muted); background: var(--bg-content); border-style: dashed; }

/* Maps */
.map { position: relative; flex: 1; min-height: 200px; z-index: 0; border: 1px solid var(--border);
    border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.map-fill { min-height: 0; }

dialog.map-dialog { width: min(94vw, 900px); }
.map-dialog-map { height: min(60vh, 520px); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.map-dialog-controls { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.map-dialog-controls input { width: 8em; }

/* Tabs implemented as buttons (detail panes) */
button.tab { background: transparent; border: 0; box-shadow: none; font: inherit; }
button.tab:hover:not(:disabled) { background: var(--control-hover); }
button.tab.selected { background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* Settings */
.settings-tab { padding: 0; }
.profile { flex: 1; display: flex; flex-direction: column; }
.profile-logout { align-self: flex-end; }
.profile .center, .backup { margin: auto; padding: 20px; background: var(--bg); border: 1px solid var(--separator); border-radius: 12px; box-shadow: var(--shadow); }
.backup { display: flex; flex-direction: column; gap: 8px; width: min(100%, 320px); }
a.button.primary-link { color: var(--accent-fg); background: var(--accent); border-color: var(--accent); }

/* Wrapping and scrolling of tab bars and button rows */
.tabbar, .subtabs { overflow-x: auto; scrollbar-width: thin; }
.tab { flex: none; white-space: nowrap; }
.button-row { flex-wrap: wrap; }
dialog.modal { max-height: 92dvh; overflow: auto; }
.map-dialog-map { height: min(60dvh, 520px); }
.map-dialog-controls { flex-wrap: wrap; }
.grid-table { display: block; overflow-x: auto; }

/* Touch devices: bigger targets */
@media (pointer: coarse) {
    button, .button, input[type=text], input[type=password], input[type=date], input[type=number], select {
        min-height: 44px;
    }

    .tab { padding: 12px 16px; }
    .species-item { min-height: 48px; padding-top: 10px; padding-bottom: 10px; }
}

/* Tablets and phones: stack the panes and let the page scroll instead of scrolling inside the panes */
@media (max-width: 800px) {
    html, body { height: auto; }
    body { min-height: 100dvh; }
    /* Prevent iOS from zooming into focused fields */
    input, textarea, select { font-size: 16px; }

    .content { padding: 8px; min-height: 0; }

    /* Main navigation as a bar at the bottom edge, within reach of the thumb */
    body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
    .tabbar {
        position: fixed;
        z-index: 10;
        left: 0;
        right: 0;
        bottom: 0;
        gap: 2px;
        padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--separator);
        border-bottom: 0;
        box-shadow: 0 -2px 10px rgb(16 24 40 / 8%);
    }
    .tabbar { gap: 0; }
    .tabbar .tab {
        flex: 1 1 0;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: 6px 2px;
        border-radius: var(--radius);
        font-size: 11px;
        line-height: 1.2;
        text-align: center;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .tabbar .tab::before {
        content: "";
        width: 24px;
        height: 24px;
        background: currentColor;
        -webkit-mask: var(--icon) center / contain no-repeat;
        mask: var(--icon) center / contain no-repeat;
    }
    .tabbar .tab[data-tab=dashboard] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7' height='9'/%3E%3Crect x='14' y='3' width='7' height='5'/%3E%3Crect x='14' y='12' width='7' height='9'/%3E%3Crect x='3' y='16' width='7' height='5'/%3E%3C/svg%3E"); }
    .tabbar .tab[data-tab=tasks] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='9 11 12 14 22 4'/%3E%3Cpath d='M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11'/%3E%3C/svg%3E"); }
    .tabbar .tab[data-tab=species] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='8' y1='6' x2='21' y2='6'/%3E%3Cline x1='8' y1='12' x2='21' y2='12'/%3E%3Cline x1='8' y1='18' x2='21' y2='18'/%3E%3Cline x1='3' y1='6' x2='3.01' y2='6'/%3E%3Cline x1='3' y1='12' x2='3.01' y2='12'/%3E%3Cline x1='3' y1='18' x2='3.01' y2='18'/%3E%3C/svg%3E"); }
    .tabbar .tab[data-tab=settings] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='4' y1='21' x2='4' y2='14'/%3E%3Cline x1='4' y1='10' x2='4' y2='3'/%3E%3Cline x1='12' y1='21' x2='12' y2='12'/%3E%3Cline x1='12' y1='8' x2='12' y2='3'/%3E%3Cline x1='20' y1='21' x2='20' y2='16'/%3E%3Cline x1='20' y1='12' x2='20' y2='3'/%3E%3Cline x1='1' y1='14' x2='7' y2='14'/%3E%3Cline x1='9' y1='8' x2='15' y2='8'/%3E%3Cline x1='17' y1='16' x2='23' y2='16'/%3E%3C/svg%3E"); }
    .tabbar .tab[data-tab=about] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='16' x2='12' y2='12'/%3E%3Cline x1='12' y1='8' x2='12.01' y2='8'/%3E%3C/svg%3E"); }
    .tabbar .tab[data-tab=debug_info] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='16 18 22 12 16 6'/%3E%3Cpolyline points='8 6 2 12 8 18'/%3E%3C/svg%3E"); }
    .tab { padding: 8px 12px; }
    .center { width: 100%; }

    /* Settings: the logout button belongs below the form, full width */
    .profile { flex-direction: column-reverse; justify-content: flex-end; gap: 12px; }
    .profile-logout { align-self: stretch; }
    .profile-logout button { width: 100%; min-height: 48px; }
    .profile .button-row > button { flex: 1 1 0; }
    .profile .button-row .spacer { display: none; }

    .form-grid-2 { grid-template-columns: 1fr; }
    .subtab-content { flex: none; padding: 8px; }

    /* Species */
    .species-tab { flex-direction: column; }
    /* Master/detail: the list is shown alone, a selected species hides it and offers a back link */
    .species-sidebar { flex: none; border-right: 0; border-bottom: 1px solid var(--separator); }
    .species-list { overflow: visible; }
    .species-list { gap: 8px; padding: 4px 0 12px; }
    .species-item {
        position: relative;
        min-height: 60px;
        padding: 12px 40px 12px 16px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        background: var(--bg);
        border: 1px solid var(--separator);
        border-radius: 12px;
        box-shadow: var(--shadow);
    }
    .species-item::after {
        content: "";
        position: absolute;
        right: 18px;
        top: 50%;
        width: 8px;
        height: 8px;
        border-top: 2px solid var(--fg-muted);
        border-right: 2px solid var(--fg-muted);
        transform: translateY(-50%) rotate(45deg);
    }
    .species-item > :first-child { font-weight: 600; }
    .species-sidebar { border-bottom: 0; }
    .species-sidebar-buttons { order: -1; padding: 0 0 4px; }
    .has-selection .species-sidebar { display: none; }
    .species-empty { display: none; }
    .species-back { display: block; color: var(--accent); font-weight: 600; }
    .species-sidebar-buttons { flex-direction: row; flex-wrap: wrap; }
    .species-sidebar-buttons form { flex: 1 1 140px; }
    .species-detail { flex: none; }
    /* One column; the save bar sticks to the bottom edge (above the navigation) while the form is scrolled */
    .species-info { display: flex; flex-direction: column; gap: 4px; }
    .species-info-fields { display: contents; }
    .species-info-side { order: 1; }
    .save-bar .spacer, .species-info-side .spacer { display: none; }
    .save-bar > button, .species-info-side .button-row > button { flex: 1 1 0; min-height: 48px; }
    .save-bar {
        order: 2;
        position: sticky;
        bottom: calc(58px + env(safe-area-inset-bottom));
        z-index: 5;
        margin: 8px -8px 0;
        padding: 8px;
        background: var(--bg-content);
        border-top: 1px solid var(--separator);
    }
    /* Notes use about half of the screen height instead of a few lines */
    .species-info-fields textarea { min-height: 40dvh; flex: none; }
    .species-image { flex: none; min-height: 200px; max-height: 50dvh; }

    /* Ancestry */
    .ancestry { flex: none; }
    .ancestry-toolbar { flex-wrap: nowrap; }
    .ancestry-toolbar > button { flex: 1 1 auto; padding-left: 8px; padding-right: 8px; white-space: nowrap; }
    .diagram-point { min-width: 48px; min-height: 48px; }
    .diagram-grid { gap: 32px 18px; }
    .split { flex: none; flex-direction: column; overflow: visible; background: transparent; border: 0; gap: 12px; }
    .split-left { flex: none; max-height: 45dvh; background: var(--bg); border: 1px solid var(--separator); border-radius: 12px; }
    .split-right { background: var(--bg); border: 1px solid var(--separator); border-radius: 12px; scroll-margin-bottom: 120px; }
    .split-right .subtabs { padding: 0 0 8px; border-bottom: 0; background: transparent; }
    .diagram { padding: 12px; }
    input.population-id { align-self: flex-end; width: 6em; min-height: 0; padding: 2px 4px; border-color: transparent; background: transparent; box-shadow: none; font-size: 13px; }
    .split-divider { display: none; }
    .split-right { flex: none; }
    .pane { flex: none; }
    .pane textarea { flex: none; min-height: 30dvh; }
    .map { flex: none; height: 260px; min-height: 0; }
    /* Origin pane: map first, then the actions as full width buttons */
    #pane-origin .map { order: -1; height: 300px; }
    #pane-origin .button-row { flex-direction: column; align-items: stretch; gap: 8px; margin-top: 8px; }
    #pane-origin .button-row .spacer { display: none; }
    #pane-origin .button-row > button { min-height: 48px; }
    #pane-origin #clear-origin-button { order: 1; }
    .map-fill { height: 62dvh; }

    /* Misc */
    .about-logo { flex: none; min-height: 40dvh; }
    .login-page { padding: 12px; }
    .dialog { padding: 16px; }
}

@media (max-width: 480px) {
    dialog.modal { width: 96vw; padding: 14px; }
    /* Dialog buttons side by side with the same width; the radius field gets its own row */
    dialog.modal .dialog-buttons > button, .map-dialog-controls > button { flex: 1 1 0; min-height: 48px; }
    .map-dialog-controls { display: grid; grid-template-columns: auto 1fr; gap: 8px; }
    .map-dialog-controls input { width: 100%; }
    .map-dialog-controls .spacer { display: none; }
    .map-dialog-controls > button { grid-column: 1 / -1; }
    .map-dialog-controls > button[data-ok] { order: 1; }
    .map-dialog-controls > button[data-cancel] { order: 2; }
    .dialog-buttons { flex-wrap: wrap; }
    .backup { width: 100%; }
}

/* Leaflet controls. leaflet.css is loaded after this file, so the selectors are made more specific. */
.leaflet-container .leaflet-bar { border: 0; border-radius: var(--radius); box-shadow: 0 2px 8px rgb(16 24 40 / 20%); overflow: hidden; }
.leaflet-container .leaflet-bar a { color: var(--fg); background-color: var(--control-bg); border-bottom-color: var(--separator); transition: background var(--transition); }
.leaflet-container .leaflet-bar a:hover, .leaflet-container .leaflet-bar a:focus { background-color: var(--control-hover); color: var(--fg); }
.leaflet-container .leaflet-bar a.leaflet-disabled { color: var(--fg-muted); background-color: var(--control-bg); opacity: .6; }
.leaflet-container { font-family: var(--font); }
.leaflet-container .leaflet-control-attribution { color: var(--fg-muted); background: color-mix(in srgb, var(--bg) 80%, transparent); border-radius: var(--radius) 0 0 0; }
.leaflet-container .leaflet-control-attribution a { color: var(--accent); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { color: var(--fg); background: var(--bg); }

/* Darken the (light) OpenStreetMap tiles in the dark theme */
@media (prefers-color-scheme: dark) {
    .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--fg-muted) 45%, transparent) transparent; }

/* Loading state: a shimmering placeholder while a value is being fetched */
.loading { color: var(--fg-muted); background-image: linear-gradient(90deg, transparent, color-mix(in srgb, var(--fg-muted) 18%, transparent), transparent); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .loading { animation: none; } }

/* Tasks */
.badge { display: inline-block; min-width: 1.4em; margin-left: 6px; padding: 0 6px; color: var(--danger-fg); background: var(--danger); border-radius: 999px; font-size: .8em; line-height: 1.5; text-align: center; }
.dashboard .stat-tasks.overdue { border-color: var(--danger); }
.dashboard .stat-tasks a { color: inherit; text-decoration: none; }
.dashboard .stat-tasks a:hover { text-decoration: underline; }

.tasks { width: min(100%, 720px); margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.tasks-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tasks-empty { color: var(--fg-muted); text-align: center; }
.task-group h3 { margin-bottom: 6px; color: var(--fg-muted); font-size: .85em; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.task-group-overdue h3 { color: var(--danger); }
.task-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.task { display: flex; align-items: flex-start; gap: 12px; padding: 10px 14px; background: var(--bg); border: 1px solid var(--separator); border-radius: 12px; box-shadow: var(--shadow); }
.task form { margin: 0; }
.task-check { width: 32px; min-height: 32px; padding: 0; color: transparent; border-radius: 50%; }
.task-check:hover:not(:disabled) { color: var(--accent); }
.task-check.checked { color: var(--accent-fg); background: var(--accent); border-color: var(--accent); }
.task-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; color: inherit; text-decoration: none; }
.task-title { font-weight: 500; overflow-wrap: anywhere; }
.task.done .task-title { color: var(--fg-muted); text-decoration: line-through; }
.task-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--fg-muted); font-size: .88em; }
.task-meta .overdue { color: var(--danger); font-weight: 600; }
.task-meta .today { color: var(--accent); font-weight: 600; }
.task-note { color: var(--fg-muted); font-size: .9em; white-space: pre-line; overflow-wrap: anywhere; }

.task-form, .task-delete, .task-history { padding: 20px; background: var(--bg); border: 1px solid var(--separator); border-radius: 12px; box-shadow: var(--shadow); }
.task-form textarea { resize: vertical; }
.task-form .button-row .spacer { flex: 1; }
.quick-dates { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.quick-dates[hidden] { display: none; }
.repeat-toggle { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.repeat-details { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-left: 3px solid var(--separator); }
.repeat-details[hidden] { display: none; }
.repeat-interval { display: flex; align-items: center; gap: 8px; }
.repeat-interval input { width: 5em; }
.repeat-interval select { width: auto; flex: 1; }
.hint { color: var(--fg-muted); }
.task-delete { display: flex; justify-content: flex-end; padding: 12px 20px; }
.task-history h3 { margin-bottom: 6px; }
.task-history ul { margin: 0; padding-left: 20px; }
.muted { color: var(--fg-muted); }
.species-add-task { text-align: center; text-decoration: none; }
.tasks-header .spacer { flex: 1; }
.task-filter { font-size: .9em; }
