:root {
    --bg: #f2f1ed;
    --surface: #ffffff;
    --surface-2: #ebebE6;
    --text: #1a1916;
    --muted: #6b7280;
    --accent: #2d6e45;
    --accent-dim: #245939;
    --border: #dddbd4;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.10);
    --sidebar-w: 400px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
}

#map {
    position: absolute;
    inset: 0;
    background: var(--bg);
}

.leaflet-control-attribution {
    background: rgba(242, 241, 237, 0.85) !important;
    color: var(--muted) !important;
    font-size: 10px;
}
.leaflet-control-attribution a { color: var(--accent-dim) !important; }
.leaflet-control-zoom a {
    background: var(--surface) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--surface-2) !important; }

/* Top bar */
#top-bar {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    z-index: 1100;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    pointer-events: none;
    transition: right 0.28s ease, transform 0.28s ease;
}

body:has(#sidebar:not(.hidden)) #top-bar {
    right: calc(var(--sidebar-w) + 10px);
}

#top-bar > * { pointer-events: auto; }

.header-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 10px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 4px;
}

#title-card { 
    white-space: nowrap; 
    text-decoration: none;
    color: var(--text);
    display: flex;
    align-items: center;
}
#title-card:hover { background: var(--surface-2); }
.title-main { font-weight: 600; font-size: 14px; }

#search-container {
    flex: 1;
    min-width: 180px;
}

#search, #search-tree {
    width: 100%;
    border: none;
    background: transparent;
    font: inherit;
    outline: none;
    padding: 4px 0;
    -webkit-appearance: none;
    appearance: none;
}

#search::-webkit-search-decoration,
#search::-webkit-search-cancel-button,
#search::-webkit-search-results-button,
#search::-webkit-search-results-decoration,
#search-tree::-webkit-search-decoration,
#search-tree::-webkit-search-cancel-button,
#search-tree::-webkit-search-results-button,
#search-tree::-webkit-search-results-decoration {
  -webkit-appearance: none;
}

.btn-icon {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: var(--text);
    transition: background 0.15s;
    font-size: 13px;
    font-weight: 600;
}
.btn-icon:hover { background: var(--surface-2); }

/* Separator between buttons */
.sep {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 4px;
}

#locate-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    width: 48px;
    height: 48px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 24px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    pointer-events: auto;
}
#locate-btn:hover { background: var(--surface-2); }
#locate-btn.active { color: var(--accent); background: #daeee4; border-color: var(--accent); }

.nav-link {
    text-decoration: none;
    color: var(--text);
    font-weight: 500;
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--surface-2);
    transition: background 0.15s;
}
.nav-link:hover { background: var(--border); }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(2px);
}
.modal.hidden { display: none; }

.modal-content {
    background: var(--surface);
    max-width: 500px;
    width: 100%;
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 24px;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content h2 { margin-top: 0; font-size: 20px; }
.modal-content p { line-height: 1.6; color: var(--text); }
.modal-content a { color: var(--accent); font-weight: 500; }

#close-modal {
    position: absolute;
    top: 16px; right: 16px;
    font-size: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--muted);
}

@media (max-width: 800px) {
    #top-bar {
        gap: 6px;
    }
    #search-container {
        order: 2;
        flex: 1 1 100%;
    }
    #title-card { order: 1; flex: 1; }
    #actions-card { order: 1; }
    
    body:has(#sidebar:not(.hidden)) #top-bar {
        right: 10px;
        transform: translateY(-150%);
    }
}

/* Tooltip */
#tooltip {
    position: fixed;
    z-index: 2000;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    pointer-events: none;
    box-shadow: var(--shadow);
    max-width: 350px;
    font-size: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
#tooltip.hidden { display: none; }

.tt-image {
    width: 100%;
    max-height: 220px;
    object-fit: cover;
    border-bottom: 1px solid var(--border);
}

.tt-body { padding: 12px 14px 16px; }

#tooltip .tt-species { font-style: italic; font-weight: 600; font-size: 17px; line-height: 1.2; }
#tooltip .tt-common  { color: var(--muted); font-size: 14px; margin-top: 3px; }
#tooltip .tt-summary { 
    margin-top: 10px; 
    line-height: 1.5; 
    color: var(--text); 
    font-size: 15px;
}

/* Sidebar */
#sidebar {
    position: fixed;
    top: 0; right: 0;
    width: var(--sidebar-w);
    height: 100%;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 1500;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: transform 0.28s ease;
}
#sidebar.hidden { transform: translateX(100%); }

#close-sidebar {
    position: absolute;
    top: 10px; right: 12px;
    z-index: 2000;
    background: rgba(255,255,255,0.85);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 30px; height: 30px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.10);
}
#close-sidebar:hover { background: var(--surface-2); }

#sidebar-image-wrap {
    width: 100%;
    aspect-ratio: 16 / 10;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    flex-shrink: 0;
}
#plant-image {
    width: 100%; height: 100%;
    object-fit: cover;
}
#plant-image[src=""], #plant-image:not([src]) { display: none; }

#sidebar-body { padding: 18px 20px 28px; }

#plant-species {
    margin: 0;
    font-style: italic;
    font-size: 22px;
    font-weight: 600;
    line-height: 1.2;
}
#plant-common {
    margin: 4px 0 14px;
    color: var(--muted);
    font-size: 15px;
}
#plant-summary {
    margin: 0 0 18px;
    line-height: 1.6;
    color: var(--text);
    font-size: 15px;
}

/* Wikipedia icon link */
#plant-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 20px;
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    padding: 5px 10px 5px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    transition: background 0.15s, border-color 0.15s;
}
#plant-link:hover {
    background: var(--border);
    border-color: var(--muted);
}
#plant-link svg { flex-shrink: 0; }

/* Metadata table */
#plant-meta {
    margin: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 12px;
    row-gap: 5px;
    border-top: 1px solid var(--border);
    padding-top: 14px;
    font-size: 13px;
}
#plant-meta dt {
    color: var(--muted);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.06em;
    align-self: center;
    white-space: nowrap;
}
#plant-meta dd { margin: 0; color: var(--text); word-break: break-word; }

/* Plant markers drawn on canvas — no CSS rules needed */

/* Status toast */
#status {
    position: absolute;
    bottom: 24px; left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 14px;
    color: var(--muted);
    font-size: 12px;
    box-shadow: var(--shadow);
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}
#status.visible { opacity: 1; }

@media (max-width: 720px) {
    :root { --sidebar-w: 100%; }
    #top-bar { right: 16px; flex-wrap: wrap; }
}
