@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Instrument+Serif:ital@0;1&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f1419;
    --surface: #1a2028;
    --surface-raised: #222b35;
    --surface-hover: #2a3542;
    --border: #2e3a46;
    --border-light: #3a4856;
    --text: #e8edf2;
    --text-muted: #8899a8;
    --text-dim: #5a6b7a;
    --amber: #f59e0b;
    --amber-glow: rgba(245, 158, 11, 0.15);
    --amber-dim: #b8760a;
    --sky: #38bdf8;
    --overlay-bg: rgba(15, 20, 25, 0.8);
    --radius: 10px;
    --radius-lg: 14px;
    --font: 'DM Sans', system-ui, sans-serif;
    --font-display: 'Instrument Serif', Georgia, serif;
}

[data-theme="light"] {
    --bg: #f2f0ec;
    --surface: #ffffff;
    --surface-raised: #f0ede8;
    --surface-hover: #e6e2dc;
    --border: #d8d3cb;
    --border-light: #ccc6bc;
    --text: #1c1c1a;
    --text-muted: #5c5c56;
    --text-dim: #8a8a82;
    --amber: #d97706;
    --amber-glow: rgba(217, 119, 6, 0.1);
    --amber-dim: #a85d04;
    --sky: #0284c7;
    --overlay-bg: rgba(255, 255, 255, 0.85);
}

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.header-inner h1 {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 400;
}

.header-spacer { flex: 1; }

.btn-theme {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.35rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-theme:hover {
    background: var(--amber-glow);
    border-color: var(--amber-dim);
    color: var(--amber);
}

.btn-theme .icon-moon,
[data-theme="light"] .btn-theme .icon-sun { display: none; }
[data-theme="light"] .btn-theme .icon-moon { display: block; }

.tagline {
    font-size: 0.65rem;
    color: var(--text-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 500;
}

.sun-icon { animation: sun-pulse 4s ease-in-out infinite; }
@keyframes sun-pulse {
    0%, 100% { filter: drop-shadow(0 0 4px rgba(245,158,11,0.4)); }
    50% { filter: drop-shadow(0 0 10px rgba(245,158,11,0.7)); }
}

/* ── Layout ── */
main {
    max-width: 600px;
    margin: 0 auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ── Card ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.card-header h2, .card-toggle h2 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

/* ── Collapsible Location ── */
.card-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 0;
    font-family: var(--font);
}

.location-summary {
    flex: 1;
    text-align: right;
    font-size: 0.8rem;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

.chevron {
    color: var(--text-dim);
    transition: transform 0.25s;
    flex-shrink: 0;
}

.card-toggle.collapsed .chevron {
    transform: rotate(-90deg);
}

.collapsible {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.25s ease, margin 0.3s ease;
    max-height: 500px;
    opacity: 1;
    margin-top: 0.75rem;
}

.collapsible.expanded {
    overflow: visible;
}

.collapsible.collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}

/* ── Location Search ── */
.search-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.6rem;
}

.search-wrap {
    position: relative;
    z-index: 1000;
    flex: 1;
}

.search-icon {
    position: absolute;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
    pointer-events: none;
    z-index: 2;
}

.search-input {
    width: 100%;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.6rem 0.5rem 2.2rem;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1.5;
    -webkit-appearance: none;
    appearance: none;
}

.search-input:focus {
    outline: none;
    border-color: var(--amber);
    box-shadow: 0 0 0 2px var(--amber-glow);
}

.search-input::placeholder {
    color: var(--text-dim);
}

.search-input:-webkit-autofill,
.search-input:-webkit-autofill:hover,
.search-input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px var(--surface-raised) inset;
    -webkit-text-fill-color: var(--text);
    caret-color: var(--text);
}

.search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 50;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 4px;
    max-height: 240px;
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.search-suggestion {
    padding: 0.55rem 0.75rem;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
}

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

.search-suggestion:hover {
    background: var(--surface-hover);
}

.search-suggestion-type {
    font-size: 0.65rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.search-no-results {
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-dim);
    text-align: center;
}

/* ── Map ── */
.map-container {
    height: 280px;
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 0.6rem;
    border: 1px solid var(--border);
}

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

.coord-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

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

.coord-field span {
    font-size: 0.65rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
}

.coord-field input {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.5rem;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    width: 100%;
}

.coord-field input:focus {
    outline: none;
    border-color: var(--amber);
    box-shadow: 0 0 0 2px var(--amber-glow);
}

.btn-icon {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.4rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: var(--amber-glow);
    border-color: var(--amber-dim);
    color: var(--amber);
}

/* ── Period ── */
.period-actions { display: flex; gap: 0.25rem; }

.btn-text {
    background: none;
    border: none;
    color: var(--text-dim);
    font-family: var(--font);
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

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

.month-ribbon {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.3rem;
}

.month-pill {
    padding: 0.4rem 0;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-dim);
    font-family: var(--font);
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.month-pill:hover { background: var(--surface-hover); color: var(--text-muted); }

.month-pill.selected {
    background: var(--amber-glow);
    border-color: var(--amber);
    color: var(--amber);
    box-shadow: 0 0 8px var(--amber-glow);
}

[data-theme="light"] .month-pill.selected {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border-color: #d97706;
    color: #1a1200;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(245,158,11,0.25);
}

[data-theme="light"] .btn-icon {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border-color: #d97706;
    color: #1a1200;
}

[data-theme="light"] .btn-icon:hover {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    border-color: #f59e0b;
    color: #1a1200;
}

/* ── Sliders ── */
.slider-group { margin-bottom: 0.85rem; }
.slider-group:last-of-type { margin-bottom: 0; }

.slider-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.3rem;
}

.slider-label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
}

.slider-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.slider-track-wrap { position: relative; padding: 4px 0; }

.styled-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--surface-raised);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.styled-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--text);
    border: 3px solid var(--surface);
    box-shadow: 0 1px 6px rgba(0,0,0,0.4);
    cursor: grab;
}

.styled-range::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--text);
    border: 3px solid var(--surface);
    box-shadow: 0 1px 6px rgba(0,0,0,0.4);
    cursor: grab;
}

.slider-endpoints {
    display: flex;
    justify-content: space-between;
    margin-top: 0.15rem;
}

.slider-endpoints span {
    font-size: 0.62rem;
    color: var(--text-dim);
    font-weight: 500;
}

/* ── Calculate ── */
.btn-calculate {
    width: 100%;
    padding: 0.8rem;
    background: linear-gradient(135deg, var(--amber), #d97706);
    border: none;
    border-radius: var(--radius);
    color: #1a1200;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
    box-shadow: 0 2px 12px rgba(245,158,11,0.2);
    margin-top: 0.25rem;
}

.btn-calculate:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(245,158,11,0.3);
}

.btn-calculate:active { transform: translateY(0); }
.btn-calculate:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ── Tabs ── */
.tabs {
    display: flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 3px;
    position: relative;
}

.tab {
    flex: 1;
    padding: 0.6rem;
    background: none;
    border: none;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.25s;
    position: relative;
    z-index: 2;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--text); }

.tab-indicator {
    position: absolute;
    top: 3px;
    left: 3px;
    width: calc(50% - 3px);
    height: calc(100% - 6px);
    background: var(--surface-raised);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
}

.tab[data-tab="weather"].active ~ .tab-indicator {
    transform: translateX(100%);
}

/* ── Tab Content ── */
.tab-content {
    display: none;
    animation: fadeIn 0.25s ease;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

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

/* ── Chart ── */
.chart-card { position: relative; }

.chart-wrap {
    position: relative;
    height: 280px;
}

.chart-wrap-bar {
    height: 220px;
}

.chart-overlay-kwh {
    position: absolute;
    top: 12%;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    padding: 0.3rem 0.6rem;
    background: var(--overlay-bg);
    border-radius: 6px;
    pointer-events: none;
}

.chart-overlay-line {
    width: 28px;
    height: 0;
    border-top: 3px solid currentColor;
}

.chart-overlay-left .chart-overlay-line {
    border-top-style: dashed;
}

.chart-overlay-label {
    font-size: 0.6rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.chart-overlay-value {
    font-size: 1.1rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.chart-overlay-unit {
    font-size: 0.6rem;
    font-weight: 500;
    color: var(--text-dim);
}


.chart-overlay-left {
    left: 12%;
}

.chart-overlay-right {
    right: 7%;
}

.chart-overlay-loss-inline {
    font-size: 1.1rem;
    font-weight: 700;
    opacity: 0.7;
}

.chart-overlay-loss-inline.high-loss {
    color: #ef4444;
    opacity: 1;
}

#tab-clearsky .chart-overlay-left { color: #f59e0b; }
#tab-clearsky .chart-overlay-right { color: #fb923c; }
#tab-weather .chart-overlay-left { color: #38bdf8; }
#tab-weather .chart-overlay-right { color: #818cf8; }

[data-theme="light"] #tab-clearsky .chart-overlay-left { color: #b45309; }
[data-theme="light"] #tab-clearsky .chart-overlay-right { color: #c2410c; }
[data-theme="light"] #tab-weather .chart-overlay-left { color: #0369a1; }
[data-theme="light"] #tab-weather .chart-overlay-right { color: #4f46e5; }

.chart-overlay-info {
    position: absolute;
    top: 75%;
    left: 55%;
    transform: translate(-50%, -50%);
    z-index: 10;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-dim);
    pointer-events: none;
    line-height: 1.6;
}

/* ── Generation Summary ── */
.generation-summary { padding: 0.85rem 1rem; }

.gen-row {
    display: flex;
    gap: 0.5rem;
}

.gen-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.6rem;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.gen-label {
    font-size: 0.65rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
}

.gen-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.gen-unit {
    font-size: 0.62rem;
    color: var(--text-dim);
}

.gen-optimal {
    border-color: var(--amber-dim);
    background: var(--amber-glow);
}

.gen-optimal .gen-value { color: var(--amber); }

/* ── Optimal Angles Info ── */
.optimal-angles {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.65rem;
    padding-top: 0.65rem;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.optimal-tag {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--amber);
    background: var(--amber-glow);
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    margin-right: 0.2rem;
}

.optimal-angles strong {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.sep { color: var(--text-dim); }

/* ── Insight ── */
.insight-card {
    display: flex;
    gap: 0.65rem;
    align-items: flex-start;
}

.insight-icon {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    background: var(--amber-glow);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--amber);
}

.insight-card p {
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--text-muted);
}

/* ── Loading ── */
.loading-overlay {
    background: var(--overlay-bg);
    backdrop-filter: blur(4px);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--amber);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.hidden { display: none !important; }

/* ── Card Title ── */
.card-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

/* ── Angle Values (above slider) ── */
.angle-values {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.3rem;
}

.angle-row {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
}

.angle-row strong {
    font-variant-numeric: tabular-nums;
    font-size: 0.78rem;
}

.angle-optimal {
    color: var(--amber);
}

.angle-optimal strong {
    color: var(--amber);
}

.angle-my strong {
    color: var(--text);
}

/* ── Optimal Marker on Slider ── */
.optimal-marker {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 10px;
    height: 10px;
    background: var(--amber);
    border: 2px solid var(--surface);
    border-radius: 2px;
    transform: translate(-50%, -50%) rotate(45deg);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s, left 0.3s;
    z-index: 3;
}

.optimal-marker.visible {
    opacity: 1;
}

.optimal-marker::after {
    content: attr(data-label);
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%) rotate(-45deg);
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--amber);
    white-space: nowrap;
    font-family: var(--font);
    font-variant-numeric: tabular-nums;
}

/* ── Desktop ── */
@media (min-width: 700px) {
    main { max-width: 720px; padding: 1rem; gap: 1rem; }
    .chart-wrap { height: 340px; }
    .month-ribbon { grid-template-columns: repeat(12, 1fr); }
}
