/* Vaalea teema (oletus) */
:root {
    --bg: #f7f6f2;
    --surface: #ffffff;
    --surface-2: #eef0ea;
    --border: #e1ddd2;
    --text: #1f2420;
    --text-muted: #6b6f66;
    --text-faint: #9a9d92;
    --success-bg: #eaf3de;
    --success-text: #27500a;
    --warning-bg: #faeeda;
    --warning-text: #633806;
    --danger-bg: #fcebeb;
    --danger-text: #791f1f;
    --accent: #185fa5;
    --radius-md: 8px;
    --radius-lg: 14px;
    --max-width: 480px;
}

/* Tumma teema — järjestelmän mukaan (auto) */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #15170f;
        --surface: #1f2219;
        --surface-2: #262a1f;
        --border: #34382c;
        --text: #ece9e0;
        --text-muted: #b3b6a9;
        --text-faint: #82857a;
        --success-bg: #1d2c10;
        --success-text: #c0dd97;
        --warning-bg: #2e2310;
        --warning-text: #fac775;
        --danger-bg: #2e1414;
        --danger-text: #f7c1c1;
        --accent: #85b7eb;
    }
}

/* Tumma teema — pakotettu */
:root[data-theme="dark"] {
    --bg: #15170f;
    --surface: #1f2219;
    --surface-2: #262a1f;
    --border: #34382c;
    --text: #ece9e0;
    --text-muted: #b3b6a9;
    --text-faint: #82857a;
    --success-bg: #1d2c10;
    --success-text: #c0dd97;
    --warning-bg: #2e2310;
    --warning-text: #fac775;
    --danger-bg: #2e1414;
    --danger-text: #f7c1c1;
    --accent: #85b7eb;
}

/* Vaalea teema — pakotettu */
:root[data-theme="light"] {
    --bg: #f7f6f2;
    --surface: #ffffff;
    --surface-2: #eef0ea;
    --border: #e1ddd2;
    --text: #1f2420;
    --text-muted: #6b6f66;
    --text-faint: #9a9d92;
    --success-bg: #eaf3de;
    --success-text: #27500a;
    --warning-bg: #faeeda;
    --warning-text: #633806;
    --danger-bg: #fcebeb;
    --danger-text: #791f1f;
    --accent: #185fa5;
}

/* Ylätunnisteen logo -- kaksi versiota, näytetään aina se joka sopii
   nykyiseen teemaan (sama Auto/Light/Dark-logiikka kuin väreillä yllä). */
.topbar-logo-row { display: flex; justify-content: center; }
.app-logo { height: 120px; width: auto; object-fit: contain; }

.app-logo-dark-variant { display: none; }
.app-logo-light-variant { display: block; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .app-logo-dark-variant { display: block; }
    :root:not([data-theme="light"]) .app-logo-light-variant { display: none; }
}
:root[data-theme="dark"] .app-logo-dark-variant { display: block; }
:root[data-theme="dark"] .app-logo-light-variant { display: none; }
:root[data-theme="light"] .app-logo-dark-variant { display: none; }
:root[data-theme="light"] .app-logo-light-variant { display: block; }

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.app {
    max-width: var(--max-width);
    margin: 0 auto;
    min-height: 100vh;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    padding-bottom: 64px;
    position: relative;
}

.view { display: none; padding: 0 16px; }
.view.active { display: block; }

header.topbar {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 16px 8px;
}

.topbar-info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.topbar .location-label { font-size: 12px; color: var(--text-muted); margin: 0; }
.topbar .location-value { font-size: 17px; font-weight: 600; margin: 2px 0 0; display: flex; align-items: center; gap: 4px; }

.icon-btn {
    background: none; border: none; color: var(--text-muted);
    font-size: 22px; cursor: pointer; padding: 4px; line-height: 1;
}
.icon-btn:hover { color: var(--text); }

#map-wrap { padding: 4px 16px; }
#map-wrap svg { width: 100%; height: auto; max-height: 200px; display: block; }

.region-path {
    fill: var(--surface-2);
    stroke: var(--surface);
    stroke-width: 1.2;
    cursor: pointer;
    transition: opacity 0.15s;
}
.region-path:hover { opacity: 0.8; }
.region-path.level-0, .region-path.level-1 { fill: #c0dd97; }
.region-path.level-2, .region-path.level-3 { fill: #fac775; }
.region-path.level-4, .region-path.level-5 { fill: #f09595; }
.region-path.own-region { stroke: var(--accent); stroke-width: 3; }

.map-hint {
    text-align: center; font-size: 11px; color: var(--text-faint); margin: 4px 0 10px;
}

.legend-row {
    display: flex; justify-content: center; gap: 14px; font-size: 11px; color: var(--text-muted);
    margin-bottom: 4px; flex-wrap: wrap;
}
.legend-dot {
    display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px;
}

.card {
    background: var(--surface-2);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    margin: 12px 0;
}

.card .card-label { font-size: 12px; color: var(--text-muted); margin: 0 0 2px; }
.card .card-title { font-size: 15px; font-weight: 600; margin: 0 0 10px; }

.forecast-grid {
    display: grid;
    grid-template-columns: 1fr repeat(var(--cols, 3), 34px);
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}
.forecast-grid.header-row { font-size: 10px; color: var(--text-faint); }
.forecast-grid .plant-name { font-size: 13px; display: flex; align-items: center; gap: 6px; }
.forecast-grid .plant-name .ic { color: var(--text-muted); font-size: 15px; }

.level-badge {
    text-align: center; font-size: 12px; font-weight: 600;
    border-radius: var(--radius-md); padding: 4px 0;
}
.level-badge.l-low { background: var(--success-bg); color: var(--success-text); }
.level-badge.l-mid { background: var(--warning-bg); color: var(--warning-text); }
.level-badge.l-high { background: var(--danger-bg); color: var(--danger-text); }

.btn {
    width: 100%;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    font-size: 13px; padding: 10px 0; margin-top: 8px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
    color: var(--text); cursor: pointer; text-decoration: none;
}
.btn:visited { color: var(--text); }
.btn.primary:visited { color: #fff; }
.settings-section p a { color: var(--accent); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }

.ad-container {
    margin: 12px 0;
    text-align: center;
    min-height: 0;
}

.info-card {
    background: var(--surface-2); border-radius: var(--radius-md); padding: 12px 14px;
    display: flex; gap: 10px; font-size: 12px; color: var(--text-muted); margin: 4px 0 0;
}

nav.bottom-nav {
    position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
    width: 100%; max-width: var(--max-width);
    display: flex; justify-content: space-around; align-items: center;
    padding: 10px 0; background: var(--surface); border-top: 1px solid var(--border);
}
nav.bottom-nav button {
    background: none; border: none; font-size: 22px; color: var(--text-faint); cursor: pointer;
}
nav.bottom-nav button.active { color: var(--text); }

.settings-section { margin: 16px 0; }
.settings-section h3 { font-size: 14px; margin: 0 0 8px; }
.settings-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 0; border-bottom: 1px solid var(--border);
}
.settings-row label { font-size: 14px; }
select, input[type="range"] { accent-color: var(--accent); }
select, input[type="text"] {
    padding: 8px 10px; border-radius: var(--radius-md); border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font-size: 14px;
    width: 100%; margin-bottom: 8px;
}

.privacy-note {
    font-size: 11px; color: var(--text-faint); margin: 8px 0 0; line-height: 1.5;
}
.info-text {
    font-size: 13px; color: var(--text-muted); line-height: 1.6; margin: 0;
}
.copyright-line {
    text-align: center; font-size: 11px; color: var(--text-faint); margin: 24px 0 8px;
}

.location-tabs {
    display: flex; gap: 8px; padding: 4px 16px 0;
}
.location-tabs button {
    flex: 1; font-size: 12px; padding: 7px 0; border-radius: var(--radius-md);
    border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); cursor: pointer;
}
.location-tabs button.active {
    background: var(--accent); color: #fff; border-color: var(--accent);
}

.region-path.own-region-2 { stroke: #6aa0c8; stroke-width: 3; stroke-dasharray: 3 2; }

/* Palkkinäkymä kasveille */
.plant-bar-row {
    padding: 5px 0;
}
.plant-bar-header {
    display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 3px;
}
.plant-bar-name { font-size: 13px; display: flex; align-items: center; gap: 6px; }
.plant-bar-value { font-size: 12px; font-weight: 600; min-width: 32px; text-align: right; }
.plant-bar-value.l-low  { color: #3B6D11; }
.plant-bar-value.l-mid  { color: #633806; }
.plant-bar-value.l-high { color: #791F1F; }
.plant-bar-track {
    height: 7px; border-radius: 4px; background: var(--surface-2); overflow: visible;
}
.plant-bar-fill {
    height: 100%; border-radius: 4px;
    min-width: 4px;
    transition: width 0.4s ease;
}

/* Ennustepalkki: pienempi, useampi päivä rinnakkain */
.forecast-bar-grid {
    display: grid;
    gap: 4px;
    margin-bottom: 2px;
}
.forecast-day-col { text-align: center; }
.forecast-day-label { font-size: 10px; color: var(--text-faint); margin-bottom: 3px; }
.forecast-bar-mini-track {
    height: 6px; border-radius: 3px; background: var(--surface-2); overflow: visible; margin: 0 auto;
}
.forecast-bar-mini-fill {
    height: 100%; border-radius: 3px;
    min-width: 4px;
}
.forecast-bar-mini-val { font-size: 11px; font-weight: 600; margin-top: 2px; }

/* Asennusohje-kortti */
.install-card {
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 14px 16px; margin: 12px 0;
}
.install-card h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.install-step { font-size: 13px; color: var(--text-muted); line-height: 1.6; margin: 6px 0 0; }
.install-step strong { color: var(--text); font-weight: 500; }

.back-row { display: flex; align-items: center; gap: 10px; padding: 10px 0 4px; }
.back-row .icon-btn { font-size: 20px; }
.back-row .title { font-size: 16px; font-weight: 600; margin: 0; }
.back-row .subtitle { font-size: 12px; color: var(--text-muted); margin: 0; }

@media (min-width: 480px) {
    #map-wrap svg { max-height: 220px; }
}
@media (max-height: 700px) {
    #map-wrap svg { max-height: 180px; }
}
@media (max-height: 500px) {
    #map-wrap svg { max-height: 140px; }
}
@media (max-width: 400px) {
    #map-wrap svg { max-height: 180px; }
}

/* Vaalea teema — pakotettu */
:root[data-theme="light"] {
    --bg: #f7f6f2;
    --surface: #ffffff;
    --surface-2: #eef0ea;
    --border: #e1ddd2;
    --text: #1f2420;
    --text-muted: #6b6f66;
    --text-faint: #9a9d92;
    --success-bg: #eaf3de;
    --success-text: #27500a;
    --warning-bg: #faeeda;
    --warning-text: #633806;
    --danger-bg: #fcebeb;
    --danger-text: #791f1f;
    --accent: #185fa5;
}
