/*
 * /projects/ecoADDRESS/css/address.css
 * Ecological Address — warm natural palette, senior-friendly readability
 * Standalone — no ecoSPLAT dependencies
 *
 * v2: card grid with placeholder/snapshot/expanded states,
 *   species thumbnails, plant strata, new search button
 */

/* --- Reset & base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: Georgia, 'Times New Roman', serif;
    background: #f5f0e8;
    color: #2c2416;
    line-height: 1.7;
    font-size: 26px;
}

/* --- Hero banner --- */
#hero {
    position: relative;
    width: 100%;
    max-height: 300px;
    overflow: hidden;
}

#hero img {
    width: 100%;
    height: 300px;
    object-fit: cover;
    display: block;
    filter: brightness(0.8);
}

#hero-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 2.5rem 2.5rem 2rem;
    background: linear-gradient(transparent, rgba(44, 36, 22, 0.9));
}

#hero-overlay h1 {
    font-size: 2.5rem;
    font-weight: normal;
    letter-spacing: 0.03em;
    color: #fff;
    margin-bottom: 0.3rem;
}

#hero-overlay p {
    font-size: 1.2rem;
    color: #e0d8c8;
}

/* --- Main layout --- */
#app {
    max-width: 1020px;
    margin: 0 auto;
    padding: 2rem;
}

/* --- Place search --- */
#search-container {
    position: relative;
    margin-bottom: 1.25rem;
}

#place-search {
    width: 100%;
    padding: 0.8rem 1.1rem;
    border: 2px solid #c4b99a;
    border-radius: 6px;
    background: #fffdf7;
    color: #2c2416;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.15rem;
}

#place-search:focus {
    outline: none;
    border-color: #7a8c5a;
    box-shadow: 0 0 0 3px rgba(122, 140, 90, 0.2);
}

#place-search::placeholder {
    color: #9a8e76;
}

#search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: #fffdf7;
    border: 2px solid #c4b99a;
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 400px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(44, 36, 22, 0.15);
}

.search-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.1rem;
    cursor: pointer;
    border-bottom: 1px solid #e8e0d0;
    transition: background 0.15s;
}

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

.search-item:hover {
    background: #f0ebe0;
}

.search-item.disabled {
    cursor: default;
    color: #9a8e76;
    font-style: italic;
}

.search-item.disabled:hover {
    background: transparent;
}

.search-name {
    color: #2c2416;
    font-size: 1.05rem;
    flex: 1;
    margin-right: 0.75rem;
}

.search-source {
    font-size: 0.85rem;
    color: #7a6e56;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
    padding: 0.2rem 0.6rem;
    border-radius: 3px;
    background: #ece6d8;
}

/* --- Map --- */
#map-container {
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #c4b99a;
    margin-bottom: 1.25rem;
}

#map {
    width: 100%;
    height: 450px;
}

/* --- Controls --- */
#controls {
    margin-bottom: 1.75rem;
}

#coord-input {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    flex-wrap: wrap;
}

#coord-input label {
    font-size: 1.1rem;
    color: #5a4e3a;
    font-weight: bold;
}

#coord-input input {
    width: 160px;
    padding: 0.65rem 0.85rem;
    border: 2px solid #c4b99a;
    border-radius: 4px;
    background: #fffdf7;
    color: #2c2416;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
    font-size: 1.1rem;
}

#coord-input input:focus {
    outline: none;
    border-color: #7a8c5a;
    box-shadow: 0 0 0 3px rgba(122, 140, 90, 0.2);
}

#lookup-btn,
#new-search-btn,
#locate-btn {
    padding: 0.65rem 1.75rem;
    border: none;
    border-radius: 4px;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.2s;
}

#lookup-btn {
    background: #5c7a3a;
    color: #fff;
}

#lookup-btn:hover {
    background: #6c8a4a;
}

#locate-btn {
    background: #5a7a8a;
    color: #fff;
}

#locate-btn:hover {
    background: #6a8a9a;
}

#locate-btn:disabled {
    background: #a0a0a0;
    cursor: wait;
}

#new-search-btn {
    background: #7a6e56;
    color: #fff;
}

#new-search-btn:hover {
    background: #8a7e66;
}

#instructions {
    font-size: 1.05rem;
    color: #7a6e56;
    margin-top: 0.6rem;
}

/* --- Loading --- */
#loading {
    text-align: center;
    padding: 2.5rem;
}

#loading p {
    color: #7a6e56;
    font-size: 1.2rem;
    margin-top: 0.85rem;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid #e0d8c8;
    border-top-color: #5c7a3a;
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}


/* --- Results header (place identity + coordinates) --- */
.results-header {
    margin-bottom: 1.25rem;
}

.results-header h2 {
    font-size: 1.4rem;
    font-weight: bold;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #3a3020;
    margin-bottom: 0.2rem;
}

.results-header .header-place {
    font-size: 1.25rem;
    color: #2c2416;
    font-weight: bold;
    margin-bottom: 0.15rem;
}

.results-header .coords {
    font-size: 1.1rem;
    color: #5a4e3a;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
}


/* --- Card grid --- */
.card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.grid-card {
    background: #fffdf7;
    border: 2px solid #c4b99a;
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    box-shadow: 0 2px 8px rgba(44, 36, 22, 0.1);
    transition: box-shadow 0.2s, border-color 0.2s;
}

.grid-card h3 {
    font-size: 1.1rem;
    font-weight: bold;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #5c7a3a;
    margin-bottom: 0.6rem;
}

/* --- Placeholder state (before search) --- */
.grid-card.placeholder {
    min-height: 120px;
}

.card-explain {
    font-size: 1rem;
    color: #7a6e56;
    line-height: 1.55;
}

/* --- Data state (after search) --- */
.grid-card.has-data {
    cursor: pointer;
}

.grid-card.has-data:hover {
    border-color: #7a8c5a;
    box-shadow: 0 3px 12px rgba(44, 36, 22, 0.15);
}

.card-snapshot {
    margin-bottom: 0.3rem;
}

.snapshot-data {
    font-size: 1.05rem;
    color: #2c2416;
    line-height: 1.5;
}

.no-data {
    font-size: 1rem;
    color: #9a8e76;
    font-style: italic;
}

.expand-hint {
    display: block;
    font-size: 0.82rem;
    color: #b0a690;
    margin-top: 0.3rem;
    transition: color 0.2s;
}

.grid-card.has-data:hover .expand-hint {
    color: #7a8c5a;
}

/* --- Expanded state --- */
.grid-card.expanded {
    grid-column: 1 / -1;
    border-color: #7a8c5a;
    cursor: pointer;
}

.grid-card.expanded .card-snapshot {
    display: none;
}

.grid-card.expanded .card-expand {
    display: block !important;
}

.grid-card.expanded .expand-hint {
    display: none;
}

.card-expand {
    padding-top: 0.25rem;
}


/* --- Field rows (used in expanded cards) --- */
.field {
    display: flex;
    justify-content: space-between;
    padding: 0.45rem 0;
}

.field .label {
    color: #5a4e3a;
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-right: 1.25rem;
    font-weight: bold;
}

.field .value {
    color: #2c2416;
    font-size: 1.1rem;
    text-align: right;
}

.field.note {
    color: #7a6e56;
    font-size: 1.05rem;
    font-style: italic;
    justify-content: center;
    padding: 0.6rem 0;
}


/* --- Narrative paragraphs (for future use) --- */
.narrative {
    margin-top: 0.75rem;
    padding: 0.85rem 1rem;
    background: #f8f4ec;
    border-left: 3px solid #5c7a3a;
    border-radius: 0 4px 4px 0;
    color: #3a3020;
    font-size: 1.05rem;
    line-height: 1.65;
}

.narrative-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.75rem;
    padding: 0.85rem 1rem;
    background: #f8f4ec;
    border-left: 3px solid #e0d8c8;
    border-radius: 0 4px 4px 0;
    min-height: 2.5rem;
}

.spinner-sm {
    width: 22px;
    height: 22px;
    border: 2px solid #e0d8c8;
    border-top-color: #5c7a3a;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}


/* --- Expanded card sub-headers --- */
.card-expand h4 {
    font-size: 1.05rem;
    font-weight: bold;
    color: #5a4e3a;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.card-expand h4 .taxon-count {
    font-weight: normal;
    color: #7a6e56;
    font-size: 0.95rem;
}


/* --- Species thumbnails --- */
.species-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    margin-top: 0.5rem;
}

.species-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem;
    border-radius: 4px;
    background: #f8f4ec;
}

.species-thumb {
    width: 52px;
    height: 52px;
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
    background: #ece6d8;
}

.species-thumb.no-photo {
    background: #e0d8c8;
}

.species-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.species-name {
    font-size: 0.95rem;
    font-weight: bold;
    color: #2c2416;
    line-height: 1.3;
}

.species-sci {
    font-size: 0.82rem;
    font-style: italic;
    color: #7a6e56;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.species-count {
    font-size: 0.8rem;
    color: #9a8e76;
    line-height: 1.3;
}


/* --- Plant strata --- */
.plant-strata {
    margin-top: 0.85rem;
    padding: 0.85rem 1rem;
    background: #f2ede4;
    border-radius: 4px;
}

.plant-strata h4 {
    font-size: 1rem;
    color: #5c7a3a;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 0;
    margin-bottom: 0.6rem;
}

.stratum {
    padding: 0.3rem 0;
    display: flex;
    gap: 0.75rem;
}

.stratum-label {
    font-size: 0.95rem;
    font-weight: bold;
    color: #5a4e3a;
    flex-shrink: 0;
    min-width: 10rem;
}

.stratum-species {
    font-size: 0.95rem;
    color: #2c2416;
    font-style: italic;
}


/* --- Taxon group dividers --- */
.taxon-group {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid #e8e0d0;
}

.taxon-group:first-of-type {
    border-top: none;
    padding-top: 0;
}


/* --- Error card --- */
.card.error {
    background: #fffdf7;
    border: 2px solid #c4b99a;
    border-radius: 8px;
    padding: 1.75rem;
    text-align: center;
    color: #9a3a2a;
    font-size: 1.15rem;
}


/* --- Utility --- */
.hidden {
    display: none;
}


/* --- Responsive --- */
@media (max-width: 640px) {
    body {
        font-size: 24px;
    }

    #hero-overlay h1 {
        font-size: 1.8rem;
    }

    #app {
        padding: 1.25rem;
    }

    #map {
        height: 320px;
    }

    #coord-input {
        flex-direction: column;
        align-items: stretch;
    }

    #coord-input input {
        width: 100%;
    }

    #coord-input label {
        margin-top: 0.3rem;
    }

    /* Single column grid on mobile */
    .card-grid {
        grid-template-columns: 1fr;
    }

    .field {
        flex-direction: column;
        gap: 0.15rem;
    }

    .field .value {
        text-align: left;
    }

    .species-list {
        grid-template-columns: 1fr;
    }

    .stratum {
        flex-direction: column;
        gap: 0.15rem;
    }

    .stratum-label {
        min-width: auto;
    }
}