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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #0f1923;
    color: #e0e0e0;
    max-width: 800px;
    margin: 0 auto;
    padding: 0 16px;
    padding-bottom: 72px; /* plads til tab-bar */
}

.hidden { display: none !important; }

/* ===== Header ===== */
header {
    text-align: center;
    padding: 14px 0 8px;
}
header h1 {
    font-size: 1.4rem;
    color: #4fc3f7;
}
.subtitle {
    color: #546e7a;
    font-size: 0.8rem;
}

/* ===== Bottom tab bar ===== */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: #1a2733;
    border-top: 1px solid #263238;
    padding: 4px 0;
    padding-bottom: env(safe-area-inset-bottom, 4px);
    z-index: 100;
}
.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px 6px;
    background: none;
    border: none;
    color: #546e7a;
    font-size: 0.65rem;
    cursor: pointer;
    transition: color 0.2s;
}
.tab-btn svg {
    width: 22px;
    height: 22px;
}
.tab-btn.active {
    color: #4fc3f7;
}
.tab-btn:active {
    opacity: 0.7;
}

/* ===== Tab pages ===== */
.tab-page {
    display: none;
    padding-bottom: 16px;
}
.tab-page.active {
    display: block;
}

/* ===== Shared section box ===== */
.section-box {
    background: #1a2733;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid #263238;
}
.section-box h2 {
    font-size: 1rem;
    color: #b0bec5;
    margin-bottom: 12px;
}

/* ===== Energi tab — Live gauges ===== */
.live-gauges {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 6px;
}
.live-gauge {
    text-align: center;
    padding: 14px 8px;
    background: #1a2733;
    border-radius: 12px;
    border: 1px solid #263238;
}
.live-gauge .gauge-value {
    display: block;
    font-size: 1.6rem;
    font-weight: 700;
    color: #ffd54f;
}
.live-gauge .gauge-value.consumption { color: #ef5350; }
.live-gauge .gauge-value.surplus { color: #81c784; }
.live-gauge .gauge-value.surplus.negative { color: #ef5350; }
.gauge-label {
    display: block;
    font-size: 0.7rem;
    color: #78909c;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}
.gauge-unit {
    display: block;
    font-size: 0.65rem;
    color: #546e7a;
}

.live-source {
    text-align: center;
    font-size: 0.7rem;
    color: #546e7a;
    margin-bottom: 12px;
}

/* ===== Period tabs (energi) ===== */
.period-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}
.ptab {
    flex: 1;
    padding: 10px 8px;
    border: 1px solid #37474f;
    border-radius: 8px;
    background: transparent;
    color: #78909c;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.ptab.active {
    background: #263238;
    color: #4fc3f7;
    border-color: #4fc3f7;
}

/* ===== Period totals ===== */
.period-totals {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}
.total-item {
    background: #1a2733;
    border-radius: 10px;
    padding: 12px;
    border: 1px solid #263238;
    text-align: center;
}
.total-label {
    display: block;
    font-size: 0.7rem;
    color: #78909c;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.total-value {
    display: block;
    font-size: 1.4rem;
    font-weight: 700;
}
.total-item.usage .total-value { color: #ef5350; }
.total-item.production .total-value { color: #81c784; }

/* ===== Energy chart ===== */
.energy-chart-wrap {
    background: #1a2733;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid #263238;
}
.energy-chart-wrap canvas {
    max-height: 200px;
}

/* ===== Solar monitor ===== */
.solar-monitor {
    background: #1a2733;
    border-radius: 12px;
    padding: 12px;
    border: 1px solid #263238;
    margin-bottom: 16px;
}
.monitor-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}
.monitor-toggle input { display: none; }
.toggle-slider {
    width: 40px;
    height: 22px;
    background: #37474f;
    border-radius: 11px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}
.toggle-slider::after {
    content: "";
    position: absolute;
    top: 3px; left: 3px;
    width: 16px; height: 16px;
    background: #78909c;
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}
.monitor-toggle input:checked + .toggle-slider {
    background: rgba(129, 199, 132, 0.3);
}
.monitor-toggle input:checked + .toggle-slider::after {
    transform: translateX(18px);
    background: #81c784;
}
.toggle-label {
    font-size: 0.85rem;
    color: #b0bec5;
}
.monitor-config {
    margin-top: 10px;
    padding-left: 50px;
}
.monitor-config label {
    font-size: 0.8rem;
    color: #78909c;
}
.threshold-input {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}
.threshold-input input {
    width: 80px;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid #37474f;
    background: #0f1923;
    color: #fff;
    font-size: 0.9rem;
    text-align: right;
}
.threshold-input input:focus { border-color: #81c784; outline: none; }
.threshold-input span { font-size: 0.8rem; color: #546e7a; }
.monitor-status {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    text-align: center;
}
.monitor-status.watching { background: rgba(129, 199, 132, 0.1); color: #81c784; }
.monitor-status.warning { background: rgba(255, 213, 79, 0.15); color: #ffd54f; }
.monitor-status.alert { background: rgba(239, 83, 80, 0.15); color: #ef5350; }

/* ===== Ladning tab — Status cards ===== */
.status-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.card {
    background: #1a2733;
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    border: 1px solid #263238;
}
.card-label {
    display: block;
    font-size: 0.65rem;
    color: #78909c;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}
.card-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
}
.card-unit {
    display: block;
    font-size: 0.65rem;
    color: #546e7a;
}
#price-card .card-value { color: #4fc3f7; }
#co2-card .card-value { color: #81c784; }
#solar-card .card-value { color: #ffd54f; }
.card-value.loading { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ===== Charts ===== */
canvas {
    width: 100% !important;
    max-height: 280px;
}

/* ===== Recommend form ===== */
.form-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}
.form-row label {
    flex: 1;
    display: flex;
    flex-direction: column;
    font-size: 0.8rem;
    color: #78909c;
}
.form-row input,
.form-row select {
    margin-top: 4px;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #37474f;
    background: #263238;
    color: #fff;
    font-size: 1rem;
}
.button-row {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}
.btn {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn-cheapest { background: #4fc3f7; color: #0f1923; }
.btn-greenest { background: #81c784; color: #0f1923; }

/* Recommendation result */
.recommendation {
    margin-top: 16px;
    padding: 14px;
    background: #263238;
    border-radius: 10px;
}
.recommendation h3 { font-size: 1rem; margin-bottom: 10px; }
.rec-hours {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}
.hour-chip {
    padding: 5px 10px;
    border-radius: 16px;
    font-size: 0.8rem;
    font-weight: 600;
}
.hour-chip.cheapest { background: rgba(79, 195, 247, 0.2); color: #4fc3f7; border: 1px solid #4fc3f7; }
.hour-chip.greenest { background: rgba(129, 199, 132, 0.2); color: #81c784; border: 1px solid #81c784; }
.rec-summary {
    display: flex;
    gap: 12px;
    font-size: 0.8rem;
    color: #90a4ae;
    flex-wrap: wrap;
}
.btn-auto-charge {
    width: 100%;
    margin-top: 8px;
    background: #4fc3f7;
    color: #0f1923;
    font-weight: 700;
}
.btn-cancel {
    background: #37474f;
    color: #ef5350;
    border: 1px solid #ef5350;
    padding: 6px 14px;
    font-size: 0.75rem;
}

/* Auto-charge panel */
.auto-charge-panel {
    background: #1a2634;
    border: 1px solid #4fc3f7;
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 14px;
}
.auto-charge-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.auto-charge-badge {
    font-size: 0.8rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 12px;
    background: rgba(79, 195, 247, 0.2);
    color: #4fc3f7;
}
.auto-charge-badge.charging {
    background: rgba(129, 199, 132, 0.2);
    color: #81c784;
    animation: pulse-glow 2s infinite;
}
.auto-charge-badge.paused {
    background: rgba(255, 213, 79, 0.2);
    color: #ffd54f;
}
@keyframes pulse-glow {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}
.auto-charge-info p {
    font-size: 0.85rem;
    color: #b0bec5;
    margin-bottom: 6px;
}
.auto-charge-progress {
    display: flex;
    gap: 12px;
    font-size: 0.75rem;
    color: #78909c;
    flex-wrap: wrap;
}

.auto-charge-schedule {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}
.ac-slot {
    font-size: 0.72rem;
    padding: 3px 8px;
    border-radius: 8px;
    background: rgba(79, 195, 247, 0.15);
    color: #4fc3f7;
}
.ac-slot.active {
    background: rgba(129, 199, 132, 0.25);
    color: #81c784;
    font-weight: 700;
}
.ac-slot.past {
    opacity: 0.35;
}

/* ===== Savings ===== */
.savings-period-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}
.savings-period-tabs .tab {
    flex: 1;
    padding: 8px;
    border: 1px solid #37474f;
    border-radius: 8px;
    background: transparent;
    color: #78909c;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}
.savings-period-tabs .tab.active {
    background: #263238;
    color: #4fc3f7;
    border-color: #4fc3f7;
}
.savings-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}
.savings-card {
    text-align: center;
    padding: 10px 6px;
    background: #263238;
    border-radius: 10px;
}
.savings-label {
    display: block;
    font-size: 0.65rem;
    color: #78909c;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}
.savings-value {
    display: block;
    font-size: 1.3rem;
    font-weight: 700;
}
.savings-card:nth-child(1) .savings-value { color: #4fc3f7; }
.savings-card:nth-child(2) .savings-value { color: #81c784; }
.savings-card:nth-child(3) .savings-value { color: #ffd54f; }
.savings-unit {
    display: block;
    font-size: 0.6rem;
    color: #546e7a;
}
.savings-detail {
    display: flex;
    gap: 12px;
    font-size: 0.75rem;
    color: #546e7a;
    flex-wrap: wrap;
}

/* ===== Week planner ===== */
.week-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.week-day {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 10px;
    background: #263238;
}
.week-day.green  { border-left: 4px solid #81c784; }
.week-day.yellow { border-left: 4px solid #ffd54f; }
.week-day.red    { border-left: 4px solid #ef5350; }
.week-day.today  { background: #1e3a4a; border-right: 4px solid #4fc3f7; }
.week-loading { text-align: center; color: #546e7a; padding: 16px; font-size: 0.8rem; }
.week-day-name {
    min-width: 60px;
    font-weight: 600;
    font-size: 0.85rem;
}
.week-day.green .week-day-name  { color: #81c784; }
.week-day.yellow .week-day-name { color: #ffd54f; }
.week-day.red .week-day-name    { color: #ef5350; }
.week-day-stats {
    display: flex;
    gap: 12px;
    font-size: 0.75rem;
    color: #90a4ae;
    flex-wrap: wrap;
}
.week-day-tip { font-size: 0.75rem; color: #78909c; margin-top: 3px; }
.week-day-body { flex: 1; }
.week-day-km { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.km-input {
    width: 60px;
    padding: 5px 6px;
    border-radius: 6px;
    border: 1px solid #37474f;
    background: #0f1923;
    color: #fff;
    font-size: 0.8rem;
    text-align: right;
}
.km-input:focus { border-color: #4fc3f7; outline: none; }
.km-label { font-size: 0.7rem; color: #546e7a; }
.charge-need { color: #4fc3f7 !important; font-weight: 600; }
.week-charge-summary {
    font-size: 0.8rem;
    color: #4fc3f7;
    background: rgba(79, 195, 247, 0.1);
    padding: 8px 12px;
    border-radius: 8px;
    margin-bottom: 10px;
}

/* ===== Bil tab ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #546e7a;
    font-size: 0.9rem;
}
.car-header h2 {
    font-size: 1.1rem;
    color: #b0bec5;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}
.car-status-badge {
    font-size: 0.65rem;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.car-status-badge.charging { background: rgba(79, 195, 247, 0.2); color: #4fc3f7; }
.car-status-badge.ready { background: rgba(129, 199, 132, 0.2); color: #81c784; }
.car-status-badge.off { background: rgba(120, 144, 156, 0.2); color: #78909c; }
.car-gauges {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}
.car-gauge {
    text-align: center;
    padding: 14px 8px;
    background: #1a2733;
    border-radius: 12px;
    border: 1px solid #263238;
}
.car-gauge .gauge-value { color: #4fc3f7; }
.car-gauge:nth-child(2) .gauge-value { color: #81c784; }
.car-gauge:nth-child(3) .gauge-value { color: #ffd54f; }
.car-details {
    font-size: 0.8rem;
    color: #78909c;
    padding: 8px 12px;
    background: #1a2733;
    border-radius: 10px;
    border: 1px solid #263238;
    margin-bottom: 12px;
}
.car-details:empty { display: none; }
.car-controls { display: flex; gap: 12px; }
.btn-car-start { background: #4fc3f7; color: #0f1923; flex: 1; }
.btn-car-stop { background: #37474f; color: #b0bec5; border: 1px solid #546e7a; flex: 1; }
.btn-climate { background: #37474f; color: #b0bec5; border: 1px solid #546e7a; flex: 1; }
.btn-climate.active { background: rgba(255, 167, 38, 0.2); color: #ffa726; border-color: #ffa726; }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}
.modal {
    background: #1e293b;
    border-radius: 16px;
    padding: 24px;
    width: 280px;
    text-align: center;
}
.modal h3 { margin-bottom: 12px; color: #e0e0e0; }
.modal-temp { font-size: 1.3rem; font-weight: 700; color: #ffa726; margin-bottom: 4px; }
.modal-hint { font-size: 0.75rem; color: #546e7a; margin-bottom: 16px; }
.modal-buttons { display: flex; gap: 10px; margin-bottom: 12px; }
.modal-buttons .btn { flex: 1; }
.btn-modal-close { width: 100%; background: transparent; color: #78909c; border: 1px solid #37474f; }
.car-timestamp { text-align: center; font-size: 0.7rem; color: #546e7a; margin-top: 8px; }

/* ===== Settings tab ===== */
.btn-notify {
    width: 100%;
    background: #263238;
    color: #b0bec5;
    border: 1px solid #37474f;
}
.btn-notify.active { border-color: #81c784; color: #81c784; }
.setting-hint { font-size: 0.8rem; color: #546e7a; margin-top: 8px; }
.setting-detail { font-size: 0.8rem; color: #78909c; }

/* ===== Touch-friendly ===== */
@media (pointer: coarse) {
    .form-row input,
    .form-row select {
        padding: 12px;
        font-size: 16px;
    }
    .btn { padding: 16px; min-height: 48px; }
}

/* ===== Mobile ===== */
@media (max-width: 600px) {
    body { padding: 0 10px; padding-bottom: 72px; }
    header { padding: 10px 0 6px; }
    header h1 { font-size: 1.2rem; }
    .live-gauges { gap: 6px; }
    .live-gauge { padding: 10px 6px; }
    .live-gauge .gauge-value { font-size: 1.4rem; }
    .form-row { flex-direction: column; gap: 8px; }
    .rec-summary { flex-direction: column; gap: 3px; }
    .week-day { flex-direction: column; align-items: flex-start; gap: 4px; padding: 8px; }
    .week-day-name { min-width: unset; display: flex; gap: 8px; align-items: baseline; }
    .week-day-stats { gap: 8px; }
}

@media (max-width: 380px) {
    .live-gauge .gauge-value { font-size: 1.2rem; }
    .card-value { font-size: 1.2rem; }
    .btn { font-size: 0.9rem; padding: 12px; }
}
