:root {
  --ink: #14201b;
  --muted: #69766f;
  --deep: #0b2118;
  --green: #286a51;
  --green-2: #3f8b6c;
  --mint: #dfece4;
  --cream: #f2f4ef;
  --card: #ffffff;
  --yellow: #f4c84a;
  --orange: #d88935;
  --red: #c5554f;
  --border: #dce2dd;
  --shadow: 0 14px 40px rgba(11, 33, 24, 0.08);
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--cream);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 92% -10%, rgba(244, 200, 74, 0.18), transparent 28rem),
    var(--cream);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding-bottom: calc(94px + var(--safe-bottom));
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 20px 12px;
  background: rgba(242, 244, 239, 0.9);
  border-bottom: 1px solid rgba(220, 226, 221, 0.75);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  gap: 11px;
  align-items: center;
  color: var(--deep);
  font-size: 16px;
  text-decoration: none;
  letter-spacing: -0.02em;
}

.brand strong { color: var(--green); }

.brand-mark {
  position: relative;
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  overflow: hidden;
  border-radius: 11px;
  background: var(--deep);
}

.brand-mark::before {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 9px;
  height: 9px;
  content: "";
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 3px rgba(244, 200, 74, 0.14);
}

.brand-mark span {
  position: absolute;
  bottom: 6px;
  left: 6px;
  width: 22px;
  height: 12px;
  transform: skew(-12deg);
  border: 1.5px solid #dbece2;
  background: repeating-linear-gradient(90deg, var(--green) 0 5px, #dbece2 5px 6px);
}

.install-button {
  padding: 9px 12px;
  cursor: pointer;
  color: #fff;
  border: 0;
  border-radius: 999px;
  background: var(--green);
  font-size: 12px;
  font-weight: 750;
}

.offline-banner {
  padding: 9px 20px;
  color: #593c06;
  background: #fff0b7;
  font-size: 12px;
  text-align: center;
}

main { padding: 18px 18px 0; }
.screen { display: none; animation: screen-in 180ms ease-out; }
.screen.active { display: block; }

@keyframes screen-in {
  from { transform: translateY(5px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.page-heading, .panel-heading {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
}

.page-heading { margin: 4px 2px 18px; }
.page-heading h1, .panel-heading h2 { margin: 0; letter-spacing: -0.035em; }
.page-heading h1 { font-size: clamp(26px, 7vw, 36px); }
.panel-heading h2 { font-size: 20px; }

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.icon-button {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  cursor: pointer;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.82);
}

.icon-button.loading svg { animation: spin 900ms linear infinite; }
.icon-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@keyframes spin { to { transform: rotate(360deg); } }

.status-card {
  --status-color: #6f7b75;
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
  min-height: 172px;
  padding: 24px;
  overflow: hidden;
  color: #fff;
  border-radius: 28px;
  background:
    radial-gradient(circle at 90% 16%, color-mix(in srgb, var(--status-color) 55%, transparent), transparent 38%),
    var(--deep);
  box-shadow: 0 22px 50px rgba(11, 33, 24, 0.18);
}

.status-card.good { --status-color: #4fa879; }
.status-card.warn { --status-color: #d99a3e; }
.status-card.bad { --status-color: #c95a54; }
.status-copy { max-width: 430px; }
.status-label { color: rgba(255, 255, 255, 0.62); font-size: 12px; font-weight: 700; }
.status-card h2 { margin: 6px 0 8px; font-size: clamp(22px, 6vw, 30px); line-height: 1.08; }
.status-card p { margin: 0; color: rgba(255, 255, 255, 0.72); font-size: 13px; line-height: 1.5; }

.status-ring {
  display: grid;
  flex: 0 0 92px;
  width: 92px;
  height: 92px;
  place-content: center;
  border: 8px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--status-color);
  border-right-color: var(--status-color);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  text-align: center;
}

.status-ring span { font-size: 21px; font-weight: 820; letter-spacing: -0.04em; }
.status-ring small { color: rgba(255, 255, 255, 0.6); font-size: 10px; }

.period-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  width: 220px;
  margin: 20px auto 14px;
  padding: 4px;
  border-radius: 13px;
  background: #e3e7e2;
}

.period-switch button {
  padding: 8px;
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 12px;
  font-weight: 750;
}

.period-switch button.active { background: #fff; box-shadow: 0 4px 10px rgba(11, 33, 24, 0.08); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  padding: 17px;
  border: 1px solid rgba(220, 226, 221, 0.7);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 8px 28px rgba(11, 33, 24, 0.045);
}

.metric-card.wide { grid-column: 1 / -1; }
.metric-card span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
.metric-card strong { display: block; font-size: 25px; letter-spacing: -0.045em; }
.metric-card small { display: block; margin-top: 4px; color: #89928d; font-size: 10px; }

.panel {
  margin-top: 16px;
  padding: 20px;
  border: 1px solid rgba(220, 226, 221, 0.82);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.legend { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 10px; }
.legend span { width: 8px; height: 8px; border-radius: 3px; }
.legend .expected { margin-left: 6px; background: #cfd7d1; }
.legend .actual { margin-left: 6px; background: var(--green); }

.bar-chart {
  display: flex;
  gap: 9px;
  align-items: end;
  min-height: 188px;
  margin-top: 20px;
  padding-top: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.bar-chart::-webkit-scrollbar { display: none; }

.chart-day {
  display: grid;
  flex: 1 0 34px;
  grid-template-rows: 145px auto;
  gap: 7px;
  min-width: 34px;
  text-align: center;
}

.bars { display: flex; gap: 3px; align-items: end; justify-content: center; height: 145px; }
.bar { width: 11px; min-height: 2px; border-radius: 5px 5px 2px 2px; }
.bar.expected { background: #cfd7d1; }
.bar.actual { background: linear-gradient(180deg, var(--green-2), var(--green)); }
.chart-day label { color: #78827d; font-size: 9px; }

.insight-card {
  display: flex;
  gap: 14px;
  margin-top: 16px;
  padding: 17px;
  border-radius: 18px;
  background: var(--mint);
}

.insight-icon {
  display: grid;
  flex: 0 0 27px;
  width: 27px;
  height: 27px;
  place-items: center;
  color: #fff;
  border-radius: 50%;
  background: var(--green);
  font-family: Georgia, serif;
  font-weight: 700;
}
.insight-card strong { font-size: 13px; }
.insight-card p { margin: 4px 0 0; color: #52655b; font-size: 12px; line-height: 1.45; }
.data-note { margin: 13px 4px 0; color: #85908a; font-size: 10px; text-align: center; }

.form-panel { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

label {
  display: grid;
  gap: 7px;
  color: #4b5a52;
  font-size: 12px;
  font-weight: 720;
}
label small { color: #8b948f; font-size: 10px; font-weight: 500; line-height: 1.4; }

input, select {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  color: var(--ink);
  border: 1px solid #ccd5cf;
  border-radius: 13px;
  outline: 0;
  background: #fff;
  font-size: 15px;
}
input:focus, select:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(63, 139, 108, 0.13); }

.input-with-unit { position: relative; display: block; }
.input-with-unit input { padding-right: 56px; }
.input-with-unit > span { position: absolute; top: 50%; right: 13px; transform: translateY(-50%); color: var(--muted); font-size: 11px; font-weight: 700; }

.primary-button, .secondary-button, .danger-button, .text-button, .location-button {
  cursor: pointer;
  border-radius: 13px;
  font-weight: 760;
}

.primary-button {
  min-height: 51px;
  padding: 12px 18px;
  color: #fff;
  border: 0;
  background: var(--green);
  box-shadow: 0 9px 20px rgba(40, 106, 81, 0.2);
}
.primary-button:disabled { cursor: wait; opacity: 0.6; }
.secondary-button { min-height: 45px; padding: 10px 14px; color: var(--green); border: 1px solid #bbd0c3; background: #f7fbf8; }
.danger-button { min-height: 42px; padding: 9px 13px; color: var(--red); border: 1px solid #e4c4c1; background: #fff8f7; }
.text-button { padding: 7px 0; color: var(--green); border: 0; background: transparent; font-size: 11px; }
.button-row { display: flex; flex-wrap: wrap; gap: 9px; margin: 16px 0 12px; }

.history-list { display: grid; gap: 2px; margin-top: 16px; }
.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  padding: 13px 2px;
  border-top: 1px solid #ebeeeb;
}
.history-item:first-child { border-top: 0; }
.history-item strong { display: block; font-size: 13px; }
.history-item small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.history-energy { font-size: 15px; font-weight: 800; }
.delete-entry { padding: 8px; cursor: pointer; color: #9b5b57; border: 0; background: transparent; font-size: 18px; }

.data-panel p, .source-note p { color: var(--muted); font-size: 12px; line-height: 1.55; }
.data-panel h2 { margin: 3px 0 0; font-size: 20px; }
.source-note { margin: 17px 4px 0; padding: 16px; color: #54625b; border-radius: 16px; background: rgba(223, 236, 228, 0.66); font-size: 12px; }
.source-note p { margin: 5px 0; }
.source-note a { color: var(--green); font-weight: 700; }

.empty-state { width: 100%; margin: auto; color: #8a938e; text-align: center; }
.empty-state.compact { display: grid; min-height: 100px; place-items: center; padding: 18px; font-size: 12px; line-height: 1.5; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(100%, 760px);
  min-height: calc(70px + var(--safe-bottom));
  margin: auto;
  padding: 7px 10px calc(7px + var(--safe-bottom));
  border-top: 1px solid rgba(213, 220, 215, 0.8);
  background: rgba(250, 251, 249, 0.94);
  backdrop-filter: blur(20px);
}

.bottom-nav button {
  display: grid;
  gap: 2px;
  cursor: pointer;
  place-content: center;
  color: #7d8882;
  border: 0;
  border-radius: 16px;
  background: transparent;
  font-size: 10px;
  font-weight: 700;
}
.bottom-nav button.active { color: var(--green); background: rgba(223, 236, 228, 0.62); }
.bottom-nav svg { width: 21px; height: 21px; margin: auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app-dialog {
  width: min(calc(100% - 24px), 520px);
  max-height: calc(100dvh - 28px);
  margin: auto;
  padding: 0;
  overflow: auto;
  color: var(--ink);
  border: 0;
  border-radius: 26px;
  background: #fff;
  box-shadow: 0 25px 80px rgba(5, 20, 14, 0.35);
}
.app-dialog::backdrop { background: rgba(6, 20, 14, 0.68); backdrop-filter: blur(4px); }
.app-dialog form { margin: 0; }
.dialog-hero { position: relative; padding: 27px 25px 23px; overflow: hidden; color: #fff; background: var(--deep); }
.dialog-hero h2 { max-width: 330px; margin: 7px 0 8px; font-size: 28px; line-height: 1.08; letter-spacing: -0.04em; }
.dialog-hero p:last-child { max-width: 300px; margin: 0; color: rgba(255, 255, 255, 0.7); font-size: 12px; }
.dialog-hero .eyebrow { color: #91c3aa; }
.dialog-sun { position: absolute; top: -23px; right: -19px; width: 116px; height: 116px; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 0 22px rgba(244, 200, 74, 0.08), 0 0 0 48px rgba(244, 200, 74, 0.04); }
.dialog-body { position: relative; display: grid; gap: 14px; padding: 22px; }

.location-button {
  display: flex;
  gap: 13px;
  align-items: center;
  width: 100%;
  padding: 13px;
  color: var(--green);
  border: 1px solid #c5d7cc;
  background: #f4faf6;
  text-align: left;
}
.location-button svg { flex: 0 0 24px; width: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.location-button span { display: grid; gap: 2px; }
.location-button small { color: #718078; font-size: 10px; font-weight: 500; }
.coordinate-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.coordinate-row input { font-size: 13px; }
.small-dialog { width: min(calc(100% - 28px), 410px); }
.small-dialog h2 { margin: 3px 0; font-size: 25px; letter-spacing: -0.035em; }
.small-dialog ol { margin: 5px 0 8px; padding-left: 20px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.dialog-close { position: absolute; z-index: 2; top: 10px; right: 12px; width: 38px; height: 38px; cursor: pointer; border: 0; border-radius: 50%; background: #edf1ed; font-size: 25px; }

.toast {
  position: fixed;
  z-index: 100;
  right: 18px;
  bottom: calc(88px + var(--safe-bottom));
  left: 18px;
  width: fit-content;
  max-width: min(90%, 520px);
  margin: auto;
  padding: 12px 16px;
  transform: translateY(20px);
  pointer-events: none;
  color: #fff;
  border-radius: 13px;
  background: var(--deep);
  box-shadow: 0 13px 35px rgba(11, 33, 24, 0.25);
  font-size: 12px;
  opacity: 0;
  transition: 180ms ease;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: #7f3733; }

@media (min-width: 620px) {
  main { padding: 28px 30px 0; }
  .topbar { padding-right: 32px; padding-left: 32px; }
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .metric-card.wide { grid-column: auto; }
  .status-card { padding: 30px; }
  .chart-day { min-width: 40px; }
}

@media (max-width: 400px) {
  .status-card { align-items: flex-start; padding: 20px; }
  .status-ring { flex-basis: 76px; width: 76px; height: 76px; border-width: 6px; }
  .status-ring span { font-size: 17px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
