/* Green AI - Calculator + Map Slide-out */
/* Progressive reveal with personality */

/* ============================================
   TOKENS
   ============================================ */
:root {
    --bg: #0a0f0d;
    --surface: #111816;
    --surface2: #0e1412;
    --surface3: #1a2420;
    --stroke: rgba(255, 255, 255, 0.08);
    --stroke2: rgba(255, 255, 255, 0.15);

    --text: #f0f5f2;
    --muted: #a3b4ab;
    --dim: #6b7c73;

    --green: #22c55e;
    --green-bg: rgba(34, 197, 94, 0.15);
    --yellow: #eab308;
    --yellow-bg: rgba(234, 179, 8, 0.15);
    --orange: #f97316;
    --orange-bg: rgba(249, 115, 22, 0.15);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.15);

    --r: 12px;
    --r-sm: 6px;
    --r-lg: 16px;

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
    --bg: #f5f8f6;
    --surface: #ffffff;
    --surface2: #eef3f0;
    --surface3: #e4ebe7;
    --stroke: rgba(0, 0, 0, 0.08);
    --stroke2: rgba(0, 0, 0, 0.15);
    --text: #1a2420;
    --muted: #5a6b63;
    --dim: #8a9b93;
    --green: #16a34a;
    --green-bg: rgba(22, 163, 74, 0.12);
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
}

/* ============================================
   APP LAYOUT
   ============================================ */
.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================
   HEADER
   ============================================ */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--stroke);
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.1rem;
    font-weight: 700;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-link {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--muted);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: var(--r-sm);
    transition: all 0.15s;
}

.header-link:hover {
    background: var(--surface2);
    color: var(--text);
}

.theme-toggle {
    width: 32px;
    height: 32px;
    border-radius: var(--r-sm);
    background: var(--surface2);
    border: 1px solid var(--stroke);
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   MAIN LAYOUT - Flexible split
   ============================================ */
.main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Calculator - starts full width, shrinks when map opens */
.calculator {
    flex: 1;
    max-width: 600px;
    margin: 0 auto;
    padding: 40px 24px;
    overflow-y: auto;
    transition: all 0.5s var(--ease);
}

.app.map-open .calculator {
    flex: 0 0 380px;
    max-width: 380px;
    margin: 0;
    padding: 24px;
    border-right: 1px solid var(--stroke);
}

/* Map panel - hidden initially, slides in */
.map-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateX(40px);
    transition: all 0.5s var(--ease);
}

.map-panel.visible {
    opacity: 1;
    transform: translateX(0);
}

/* ============================================
   CALCULATOR STYLES
   ============================================ */
.calc-intro {
    text-align: center;
    margin-bottom: 40px;
}

.calc-intro h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.app.map-open .calc-intro {
    display: none;
}

.subtitle {
    color: var(--muted);
    font-size: 0.9rem;
}

.calc-section {
    margin-bottom: 32px;
}

.calc-label {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.calc-hint {
    color: var(--dim);
    font-size: 0.8rem;
    margin-bottom: 14px;
    font-style: italic;
}

/* Location */
.location-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.or {
    color: var(--dim);
    font-size: 0.8rem;
}

.location-result {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
}

.badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    font-weight: 500;
    background: var(--green-bg);
    color: var(--green);
    padding: 6px 14px;
    border-radius: var(--r-sm);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

/* Provider grid */
.provider-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}

.provider-btn {
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 12px 16px;
    background: var(--surface2);
    border: 1px solid var(--stroke);
    border-radius: var(--r);
    cursor: pointer;
    transition: all 0.15s;
    color: var(--text);
    text-align: center;
}

.provider-btn:hover {
    border-color: var(--stroke2);
    background: var(--surface3);
}

.provider-btn.active {
    background: var(--green-bg);
    border-color: var(--green);
    color: var(--green);
}

/* Model grid */
.model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}

.model-btn {
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 10px 12px;
    background: var(--surface2);
    border: 1px solid var(--stroke);
    border-radius: var(--r);
    cursor: pointer;
    transition: all 0.15s;
    color: var(--text);
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.model-btn:hover {
    border-color: var(--stroke2);
    background: var(--surface3);
}

.model-btn.selected {
    background: var(--green-bg);
    border-color: var(--green);
}

.model-name {
    font-weight: 600;
}

.model-size {
    font-size: 0.7rem;
    color: var(--dim);
    font-family: 'JetBrains Mono', monospace;
}

/* Usage grid */
.usage-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.usage-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 12px;
    background: var(--surface2);
    border: 1px solid var(--stroke);
    border-radius: var(--r);
    cursor: pointer;
    transition: all 0.15s;
    color: var(--text);
}

.usage-btn:hover {
    border-color: var(--stroke2);
}

.usage-btn.active {
    background: var(--green-bg);
    border-color: var(--green);
}

.usage-icon {
    font-size: 1.5rem;
    margin-bottom: 6px;
}

.usage-name {
    font-weight: 600;
    font-size: 0.85rem;
}

.usage-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--dim);
    margin-top: 4px;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 10px 18px;
    border-radius: var(--r);
    border: 1px solid var(--stroke);
    cursor: pointer;
    transition: all 0.15s;
}

.btn-secondary {
    background: var(--surface2);
    color: var(--text);
}

.btn-secondary:hover {
    border-color: var(--stroke2);
    background: var(--surface3);
}

.btn-primary {
    background: var(--green);
    border-color: var(--green);
    color: white;
}

.btn-primary:hover {
    background: #1ea853;
}

.btn-large {
    width: 100%;
    padding: 16px 24px;
    font-size: 1rem;
    font-weight: 600;
}

.btn-text {
    background: none;
    border: none;
    color: var(--dim);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 8px;
}

.btn-text:hover {
    color: var(--muted);
}

select {
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    padding: 10px 14px;
    background: var(--surface2);
    border: 1px solid var(--stroke);
    border-radius: var(--r);
    color: var(--text);
    cursor: pointer;
    min-width: 160px;
}

select:focus {
    outline: none;
    border-color: var(--green);
}

/* ============================================
   RESULT PANEL
   ============================================ */
.result-panel {
    background: var(--surface);
    border: 1px solid var(--stroke);
    border-radius: var(--r-lg);
    padding: 24px;
    animation: fadeIn 0.4s var(--ease);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.result-hero {
    text-align: center;
    margin-bottom: 12px;
}

.result-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 3rem;
    font-weight: 700;
    color: var(--green);
    display: block;
    line-height: 1;
}

.result-unit {
    font-size: 0.85rem;
    color: var(--dim);
}

.result-quip {
    text-align: center;
    color: var(--muted);
    font-style: italic;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.result-source {
    text-align: center;
    color: var(--dim);
    font-size: 0.7rem;
    font-family: 'JetBrains Mono', monospace;
    margin-bottom: 20px;
}

.quip-source {
    color: var(--dim);
    font-size: 0.65rem;
    font-family: 'JetBrains Mono', monospace;
    font-style: normal;
}

.result-details {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.detail-item {
    text-align: center;
}

.detail-label {
    font-size: 0.7rem;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: block;
    margin-bottom: 4px;
}

.detail-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem;
    font-weight: 600;
}

/* Info sections */
.plot-twist, .what-if, .at-scale {
    background: var(--surface2);
    border-radius: var(--r);
    padding: 14px 16px;
    margin-bottom: 14px;
}

.plot-twist h4, .what-if h4, .at-scale h4 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.plot-twist p, .what-if p {
    font-size: 0.85rem;
    color: var(--muted);
}

.whatif-saving {
    color: var(--green);
    font-weight: 500;
}

/* Scale comparison */
.scale-compare {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.scale-item {
    text-align: center;
}

.scale-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.3rem;
    font-weight: 700;
    display: block;
}

.scale-value.green { color: var(--green); }

.scale-label {
    font-size: 0.65rem;
    color: var(--dim);
    text-transform: uppercase;
}

.scale-arrow {
    color: var(--dim);
    font-size: 1.2rem;
}

.scale-saving {
    margin-left: auto;
    text-align: right;
}

#scale-saving-text {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: var(--green);
    display: block;
}

.scale-quip {
    font-size: 0.75rem;
    color: var(--dim);
    font-style: italic;
}

/* ============================================
   MAP PANEL
   ============================================ */
.map-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--stroke);
}

.map-header h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.map-hint {
    font-size: 0.8rem;
    color: var(--dim);
}

.map-container {
    flex: 1;
    position: relative;
    min-height: 300px;
}

#map {
    width: 100%;
    height: 300px;
    min-height: 300px;
    background: var(--bg);
}

/* Dark mode map tiles */
.leaflet-tile-pane {
    filter: brightness(0.6) invert(1) contrast(3) hue-rotate(200deg) saturate(0.3) brightness(0.7);
}

[data-theme="light"] .leaflet-tile-pane {
    filter: none;
}

/* Leaflet controls */
.leaflet-control-zoom {
    border: none !important;
}

.leaflet-control-zoom a {
    background: var(--surface) !important;
    color: var(--text) !important;
    border: 1px solid var(--stroke) !important;
}

.leaflet-control-attribution {
    background: rgba(0, 0, 0, 0.5) !important;
    color: var(--dim) !important;
    font-size: 10px !important;
}

/* Map legend */
.map-legend {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--surface);
    border: 1px solid var(--stroke);
    border-radius: var(--r);
    padding: 12px 14px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.7rem;
    color: var(--muted);
    margin-bottom: 6px;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot.green { background: var(--green); }
.dot.yellow { background: var(--yellow); }
.dot.orange { background: var(--orange); }
.dot.red { background: var(--red); }

.legend-quip {
    margin-left: auto;
    font-size: 0.6rem;
    color: var(--dim);
}

/* Datacenter markers */
.dc-marker {
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.15s;
}

.dc-marker:hover {
    transform: scale(1.3);
}

.dc-marker.selected {
    transform: scale(1.4);
    border-width: 3px;
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.2);
}

.dc-marker.green { background: var(--green); }
.dc-marker.yellow { background: var(--yellow); }
.dc-marker.orange { background: var(--orange); }
.dc-marker.red { background: var(--red); }

/* DC details panel */
.dc-details {
    padding: 16px 20px;
    border-top: 1px solid var(--stroke);
    background: var(--surface2);
    animation: slideUp 0.3s var(--ease);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.dc-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 12px;
}

.dc-name {
    font-size: 1rem;
    font-weight: 600;
}

.dc-region {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--dim);
    background: var(--surface);
    padding: 3px 8px;
    border-radius: var(--r-sm);
}

.dc-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 10px;
}

.dc-stat {
    text-align: center;
}

.dc-stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 600;
    display: block;
}

.dc-stat-label {
    font-size: 0.6rem;
    color: var(--dim);
    text-transform: uppercase;
}

.dc-quip {
    font-size: 0.8rem;
    color: var(--muted);
    font-style: italic;
    margin-bottom: 12px;
}

.dc-comparison {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dc-vs {
    font-size: 0.8rem;
    color: var(--dim);
}

.dc-saving {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    font-weight: 600;
}

.dc-saving.green { color: var(--green); }
.dc-saving.red { color: var(--red); }

/* Leaflet popup */
.leaflet-popup-content-wrapper {
    background: var(--surface) !important;
    border: 1px solid var(--stroke) !important;
    border-radius: var(--r) !important;
}

.leaflet-popup-content {
    margin: 10px 12px !important;
    color: var(--text) !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 0.85rem !important;
}

.leaflet-popup-tip {
    background: var(--surface) !important;
}

/* ============================================
   FOOTER
   ============================================ */
.footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 24px;
    background: var(--surface2);
    border-top: 1px solid var(--stroke);
    font-size: 0.75rem;
    color: var(--dim);
    flex-shrink: 0;
}

.footer-stats {
    display: flex;
    gap: 12px;
}

.footer-stats strong {
    color: var(--muted);
}

.footer-dot {
    color: var(--stroke2);
}

.footer-credit a {
    color: var(--muted);
    text-decoration: none;
}

/* ============================================
   UTILITIES
   ============================================ */
.hidden { display: none !important; }
.green { color: var(--green); }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 900px) {
    .main {
        flex-direction: column;
    }

    .calculator {
        max-width: 100%;
        padding: 24px 20px;
    }

    .app.map-open .calculator {
        flex: 0 0 auto;
        max-width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--stroke);
        padding: 20px;
    }

    .map-panel {
        flex: 1;
        min-height: 50vh;
    }

    .map-panel.visible {
        transform: translateY(0);
    }

    .usage-grid {
        grid-template-columns: 1fr;
    }

    .result-details {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .scale-compare {
        flex-direction: column;
        align-items: flex-start;
    }

    .scale-saving {
        margin-left: 0;
        margin-top: 8px;
        text-align: left;
    }
}

@media (max-width: 500px) {
    .header {
        padding: 10px 16px;
    }

    .calc-intro h2 {
        font-size: 1.2rem;
    }

    .location-row {
        flex-direction: column;
        align-items: stretch;
    }

    .or {
        text-align: center;
    }

    .provider-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .result-value {
        font-size: 2.5rem;
    }

    .footer {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    .map-legend {
        top: auto;
        bottom: 12px;
        right: 12px;
        left: 12px;
        display: flex;
        justify-content: space-around;
        padding: 10px;
    }

    .legend-item {
        flex-direction: column;
        gap: 4px;
        margin-bottom: 0;
    }

    .legend-quip {
        display: none;
    }
}
