/* style.css */

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: #f5f7fa;
    color: #333;
}

/* --- Header --- */
#siteHeader {
    background-color: #ffffff;
    border-bottom: 1px solid #e1e5eb;
    padding: 15px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 15px;
}

#siteLogo {
    height: 40px;
    width: auto;
}

#siteHeader h1 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 600;
    color: #2c3e50;
}

/* --- Main Content --- */
#mainContent {
    min-height: calc(100vh - 80px);
    padding: 30px 20px;
    display: flex;
    justify-content: center;
}

#appContainer {
    width: 100%;
    max-width: 900px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* --- Controls Section --- */
#controls {
    padding: 25px;
    background-color: #ffffff;
    border-bottom: 1px solid #e1e5eb;
}

.control-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
}

.control-group label {
    font-weight: 600;
    margin-bottom: 6px;
    color: #4a5568;
    font-size: 0.9rem;
}

.control-group input[type="text"] {
    padding: 12px 15px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.control-group input[type="text"]:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.control-group input[type="text"]::placeholder {
    color: #9ca3af;
}

.button-group {
    margin-top: 10px;
}

.button-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
}

.btn-secondary {
    background-color: transparent !important;
    color: #9ca3af !important;
    border: none !important;
    padding: 4px 0 !important;
    font-size: 13px !important;
    font-weight: 400 !important;
    text-decoration: underline;
}

.btn-secondary:hover {
    background-color: transparent !important;
    color: #4a5568 !important;
}

.control-group button,
#screenshotButton {
    padding: 12px 24px;
    background-color: #3b82f6;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: background-color 0.2s, transform 0.1s;
}

.control-group button:hover,
#screenshotButton:hover {
    background-color: #2563eb;
}

.control-group button:active,
#screenshotButton:active {
    transform: scale(0.98);
}

.control-group button:disabled {
    background-color: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

#statusMessage {
    display: block;
    margin-top: 10px;
    font-size: 0.9rem;
    color: #6b7280;
    font-style: italic;
}

/* --- UI State Management --- */
#businessChoices,
#getRankingsGroup,
#newSearchGroup,
#searchInfo {
    display: none;
}

#initialSearchGroup {
    display: block;
}

/* State: Selecting Business */
body.state-selecting #initialSearchGroup,
body.state-selecting #newSearchGroup {
    display: none;
}
body.state-selecting #businessChoices,
body.state-selecting #getRankingsGroup {
    display: block;
}

/* State: Showing Results */
body.state-results #initialSearchGroup,
body.state-results #businessChoices,
body.state-results #getRankingsGroup {
    display: none;
}
body.state-results #newSearchGroup {
    display: block;
}
body.state-results #searchInfo {
    display: flex;
}

/* --- Business Choices --- */
#businessChoices {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e1e5eb;
    max-height: 200px;
    overflow-y: auto;
}

#businessChoices p {
    margin: 0 0 10px 0;
    font-weight: 600;
    color: #4a5568;
}

.choice-item {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    background-color: #f9fafb;
    transition: background-color 0.2s;
    cursor: pointer;
}

.choice-item:hover {
    background-color: #f3f4f6;
}

.choice-item input[type="radio"] {
    margin-right: 10px;
    vertical-align: middle;
    transform: scale(1.1);
}

.choice-item label {
    font-weight: 500;
    cursor: pointer;
    vertical-align: middle;
}

.choice-item .address {
    color: #6b7280;
    font-size: 0.85rem;
    margin-left: 26px;
    margin-top: 4px;
}

/* --- Map Container --- */
#mapContainer {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-height: 500px;
}

#rankMap {
    flex-grow: 1;
    min-height: 400px;
    background-color: #e5e7eb;
    position: relative;
}

/* --- Loading Overlay --- */
#mapOverlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.85);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    color: #4a5568;
}

#mapOverlay.hidden {
    display: none;
}

.spinner {
    border: 4px solid rgba(59, 130, 246, 0.2);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border-left-color: #3b82f6;
    margin-bottom: 15px;
    animation: spin 1s ease infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Search Info Panel --- */
#searchInfo {
    padding: 12px 20px;
    background-color: #1e293b;
    color: white;
    font-size: 14px;
    display: none;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 15px;
}

#searchInfoContent {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

#searchInfo .info-separator {
    color: #64748b;
}

#infoBusiness {
    font-weight: 600;
}

#infoKeyword {
    color: #60a5fa;
}

#infoDateTime {
    width: 100%;
    color: #94a3b8;
    font-size: 13px;
}

#infoDateTime a {
    color: #94a3b8;
    text-decoration: none;
}

#infoDateTime a:hover {
    text-decoration: underline;
    color: #cbd5e1;
}

.info-label {
    color: #94a3b8;
    font-weight: 400;
}

#infoAvgRank {
    color: #fbbf24;
    font-weight: 600;
}

#screenshotButton {
    background-color: #22c55e;
    padding: 8px 16px;
    font-size: 13px;
}

#screenshotButton:hover {
    background-color: #16a34a;
}

#screenshotButton:disabled {
    background-color: #6b7280;
}

/* --- Legend --- */
#legend {
    padding: 15px 20px;
    background-color: #f9fafb;
    border-top: 1px solid #e1e5eb;
}

#legend h4 {
    margin: 0 0 10px 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: #4a5568;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.legend-item {
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    color: #4a5568;
}

.legend-box {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    margin-right: 6px;
    border: 1px solid rgba(0, 0, 0, 0.2);
}

/* Brand Colors: Ink (1-3), Amber (4-9), Berry (10+) */
.legend-ink { background-color: #1D273A; }
.legend-amber { background-color: #EA9A26; }
.legend-berry { background-color: #CB1542; }
.legend-center {
    background-color: #d1d5db;
    border: 2px solid #1f2937;
}

/* --- Map Markers --- */
.rank-marker {
    width: 28px !important;
    height: 28px !important;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.3);
    color: white;
    font-weight: bold;
    font-size: 12px;
    text-align: center;
    line-height: 24px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}

.rank-marker:hover {
    transform: scale(1.1);
}

/* Brand Colors: Ink (1-3), Amber (4-9), Berry (10+) */
.rank-marker-ink { background-color: #1D273A; }
.rank-marker-amber { background-color: #EA9A26; color: #1f2937; }
.rank-marker-berry { background-color: #CB1542; }

.center-marker {
    width: 34px !important;
    height: 34px !important;
    line-height: 30px;
    border: 3px solid #1f2937;
    z-index: 1000 !important;
    font-size: 14px;
}

/* --- Grid Info Badge --- */
#gridInfoBadge {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background-color: rgba(255, 255, 255, 0.95);
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 500;
    font-size: 13px;
    display: none;
}

body.state-results #gridInfoBadge {
    display: block;
}

#gridInfoBadge .grid-location {
    font-weight: 600;
    color: #1D273A;
    display: block;
}

#gridInfoBadge .grid-params {
    color: #6b7280;
    font-size: 12px;
}

/* --- Share of Voice Styling --- */
#infoShareOfVoice {
    color: #EA9A26;
    font-weight: 600;
}

#infoShareOfVoice.sov-high {
    color: #1D273A;
}

#infoShareOfVoice.sov-low {
    color: #CB1542;
}

/* --- Map Messages --- */
.map-message {
    color: #4a5568;
    text-align: center;
    padding: 30px;
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.9);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999;
}

.map-error-message {
    color: #ef4444;
}

/* --- Results CTA --- */
#resultsCta {
    display: none;
    padding: 18px 20px;
    text-align: center;
    background-color: #f9fafb;
    border-top: 1px solid #e1e5eb;
}

body.state-results #resultsCta {
    display: block;
}

#resultsCta p {
    margin: 0;
    font-size: 0.9rem;
    color: #6b7280;
}

#resultsCta a {
    color: #3b82f6;
    text-decoration: none;
    font-weight: 500;
}

#resultsCta a:hover {
    text-decoration: underline;
}

/* --- Footer --- */
#siteFooter {
    text-align: center;
    padding: 20px;
    color: #6b7280;
    font-size: 0.9rem;
}

#siteFooter p {
    margin: 0;
}

#siteFooter a {
    color: #3b82f6;
    text-decoration: none;
}

#siteFooter a:hover {
    text-decoration: underline;
}

#appVersion {
    color: #d1d5db;
    font-size: 0.75rem;
    margin-left: 4px;
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    #siteHeader {
        padding: 12px 15px;
    }

    .header-content {
        gap: 10px;
    }

    #siteLogo {
        height: 32px;
    }

    #siteHeader h1 {
        font-size: 1.1rem;
    }

    #mainContent {
        padding: 15px 10px;
    }

    #appContainer {
        border-radius: 8px;
    }

    #controls {
        padding: 20px 15px;
    }

    .control-group input[type="text"] {
        padding: 14px 12px;
    }

    .control-group button {
        width: 100%;
        padding: 14px;
    }

    #businessChoices {
        max-height: 150px;
    }

    #mapContainer {
        min-height: 400px;
    }

    #rankMap {
        min-height: 300px;
    }

    #searchInfo {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px 15px;
    }

    #searchInfoContent {
        font-size: 12px;
    }

    #screenshotButton {
        width: 100%;
    }

    .legend-items {
        gap: 10px;
    }

    .legend-item {
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    #siteHeader h1 {
        font-size: 1rem;
    }

    #siteLogo {
        height: 28px;
    }

    .legend-items {
        flex-direction: column;
        gap: 6px;
    }
}
