:root {
  color-scheme: light;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  background: #eaf2f8;
}

.auth-view {
  display: grid;
  place-items: start center;
  min-height: calc(100svh - 80px);
  padding: clamp(28px, 8vh, 90px) 18px 28px;
  background: radial-gradient(ellipse at 12% 70%, #d6e7f4, transparent 65%);
}

.auth-card {
  width: min(100%, 450px);
  border: 1px solid #c8d7e6;
  border-top: 5px solid var(--schot-yellow);
  border-radius: 12px;
  padding: clamp(23px, 5vw, 38px);
  background: white;
  box-shadow: 0 12px 38px #07417b0d;
}

.auth-eyebrow {
  display: block;
  margin-bottom: 10px;
  color: #526b82;
  font-size: .95rem;
  font-weight: 500;
}

.auth-card h2 {
  margin-bottom: 10px;
  color: var(--schot-ink);
  font-size: clamp(1.9rem, 7vw, 2.5rem);
  font-weight: 600;
  line-height: 1.1;
}

.auth-card p {
  color: #4b5f76;
  font-size: 1rem;
  line-height: 1.45;
}

.auth-form {
  display: grid;
  margin-top: 24px;
  gap: 8px;
}

.auth-form label {
  margin-top: 7px;
  color: var(--schot-ink);
  font-size: 1rem;
  font-weight: 500;
}

.auth-form input {
  min-width: 0;
  width: 100%;
  min-height: 47px;
  padding: 9px 12px;
  border: 1px solid #9db1c7;
  border-radius: 6px;
  color: var(--schot-ink);
  background: white;
  font: 400 1rem/1.4 var(--schot-face);
}

.auth-form input:focus-visible {
  outline: 3px solid #8eb6df;
  outline-offset: 1px;
}

.auth-submit,
.oauth-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  margin-top: 14px;
  padding: 10px 18px;
  border: 1px solid var(--schot-blue);
  border-radius: 6px;
  background: var(--schot-blue);
  color: white;
  font: 600 1rem/1.2 var(--schot-face);
  cursor: pointer;
}

.auth-submit:hover {
  background: var(--schot-blue-dark);
}

.auth-submit:disabled,
.oauth-button:disabled {
  cursor: progress;
  opacity: .65;
}

.text-button {
  justify-self: center;
  min-height: 44px;
  padding: 8px 6px;
  border: 0;
  color: var(--schot-blue);
  background: transparent;
  font: 500 1rem/1.3 var(--schot-face);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.text-button:disabled {
  opacity: .65;
  cursor: progress;
}

.auth-access-note {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid #dce5ee;
  font-size: .92rem !important;
}

.auth-error,
.auth-message {
  padding: 10px 12px;
  margin-top: 17px;
  border-radius: 6px;
  overflow-wrap: anywhere;
}

.auth-error {
  color: #903b26 !important;
  background: #fff0e9;
  border: 1px solid #e9c8b8;
}

.auth-message {
  color: #255a43 !important;
  background: #edf6ef;
  border: 1px solid #c7dfcf;
}

.oauth-providers {
  display: grid;
  margin-top: 3px;
}

.oauth-button {
  margin-top: 9px;
  background: white;
  color: var(--schot-blue);
}

.oauth-button:hover {
  background: #eaf2f8;
}

.topbar .account-button {
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid #a5bfd6;
  border-radius: 6px;
  color: white;
  background: transparent;
  font: 500 .95rem/1 var(--schot-face);
  cursor: pointer;
}

.topbar .account-button:hover {
  background: #ffffff16;
}

.topbar :focus-visible {
  outline-color: var(--schot-yellow);
}

.account-dialog {
  font-family: var(--schot-face);
}

.account-dialog p {
  margin-top: 10px;
  overflow-wrap: anywhere;
}

.account-dialog .auth-submit {
  width: 100%;
  margin-top: 22px;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #dbeaf6;
  font-size: .92rem;
  white-space: nowrap;
}

.live-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #a5bfd6;
  border-radius: 6px;
  background: transparent;
  font-family: var(--schot-face);
  cursor: pointer;
}

.live-toggle:hover {
  background: #ffffff16;
}

.live-toggle[aria-pressed="true"] {
  border-color: #ffcf1380;
}

.live-toggle[aria-pressed="false"] .live-indicator {
  color: #dbeaf6;
}

.live-indicator[data-state="paused"]::before {
  background: transparent;
  border: 1px solid currentColor;
}

.live-indicator::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b9cce0;
}

.live-indicator[data-state="live"] {
  color: white;
}

.live-indicator[data-state="live"]::before {
  background: var(--schot-yellow);
  box-shadow: 0 0 0 3px #ffcf131a;
}

.site-grid[data-count="1"] {
  grid-template-columns: minmax(0, 1fr);
  max-width: 650px;
}

.site-grid[data-count="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.site-detail-link:not([hidden]) {
  z-index: 1;
}

.site-footer .site-link {
  position: relative;
  z-index: 2;
}

[data-session="checking"] #auth-heading {
  font-size: 1.8rem;
}

@media (max-width: 700px) {
  .topbar .topbar-inner {
    gap: 10px;
    padding-block: 10px;
  }

  .topbar .schot-brand {
    flex-basis: 100%;
    justify-content: space-between;
  }

  .topbar .topbar-actions {
    justify-content: stretch;
    align-items: center;
    width: 100%;
    gap: 8px;
  }

  .live-toggle {
    margin-inline-end: auto;
  }

  .schot-summary {
    gap: 6px 14px;
  }

  .detail-chart[data-period="24"] .detail-chart-plot {
    min-width: 600px;
  }

  .detail-chart[data-period="24"] .detail-trend-axis {
    min-width: 598px;
  }
}

@media (max-width: 554px) {
  .site-grid[data-count] {
    grid-template-columns: minmax(0, 1fr);
    max-width: none;
  }

  .site-card .site-name {
    font-size: 1.4rem;
  }

  .site-card .metric-number {
    font-size: 2.2rem;
  }

  .site-card .battery-section {
    gap: 10px;
  }

  .auth-view {
    padding-top: 28px;
  }
}

/* Give the overview the space left below the actual (possibly wrapped) header.
   The minimum is content-driven so long alarm messages always remain readable. */
@media (min-width: 555px) {
  html[data-session="dashboard"] body {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
  }
  #dashboard-view, #dashboard-overview:not([hidden]), #dashboard-overview .locations {
    display: flex;
    flex: 1 0 auto;
    flex-direction: column;
  }
  #dashboard-overview .site-grid {
    flex: 1 0 auto;
    min-block-size: 0;
  }
}

@media (min-width: 555px) and (orientation: landscape) {
  #dashboard-overview { --space: clamp(5px, 1.2dvh, 18px); }
  #dashboard-overview .locations { padding-block-start: var(--space); }
  .site-card .site-header { padding-block: var(--space); }
  .site-card .site-name { font-size: clamp(1.12rem, min(2.48vw, 3.8dvh), 2.48rem); }
  .site-card .site-header .site-state, .site-card .metric-label, .site-card .alarms-state {
    font-size: clamp(.77rem, min(1.55vw, 2.45dvh), 1.55rem);
  }
  .site-card .battery-section { padding-block: var(--space); row-gap: var(--space); }
  .site-card .battery-gauge { width: clamp(34px, min(5.1vw, 8dvh), 84px); }
  .site-card .metric-number { font-size: clamp(1.45rem, min(3.48vw, 5.7dvh), 3.48rem); }
  .site-card .battery-trend canvas { height: clamp(19px, 6.8dvh, 72px); }
  .site-card .schot-trend-axis { font-size: clamp(.63rem, 1.7dvh, 1.05rem); }
  .site-card .power-section, .site-card .alarms-section { padding-block: var(--space); }
  .site-card .power-reading { font-size: clamp(1.15rem, min(2.9vw, 4.5dvh), 2.9rem); }
  .site-card .energy-metric { padding-block: clamp(4px, .85dvh, 11px); }
  .site-card .energy-reading, .site-card .inverter-state { font-size: clamp(.98rem, min(2.07vw, 3.4dvh), 2.08rem); }
  .site-card .energy-metric .trend:not([hidden]) { height: clamp(12px, 3.4dvh, 32px); }
  #dashboard-overview .page-footer { padding-block: clamp(4px, .8dvh, 12px); }
}

@media (min-width: 555px) and (orientation: portrait) {
  #dashboard-overview .locations { padding-block-start: 6px; }
  #dashboard-overview .site-grid { gap: clamp(6px, .8dvh, 12px); }
  .site-card .site-header { padding-block: 6px; }
  .site-card .battery-trend canvas:not([hidden]) { flex: 0 0 auto; height: clamp(24px, 3.4dvh, 48px); min-height: 0; }
  .site-card .energy-metric .trend:not([hidden]) { height: clamp(18px, 2.8dvh, 40px); }
}

@media (max-width: 554px) and (orientation: portrait) {
  .topbar .topbar-inner { padding-block: 5px; gap: 5px; }
  #dashboard-overview .locations { padding-block-start: 5px; }
  #dashboard-overview .site-grid { gap: 6px; }
  .site-card {
    --card-padding: 10px;
    display: grid;
    grid-template-columns: minmax(0, .95fr) minmax(0, 1.25fr);
    grid-template-areas: "header header" "battery energy" "power energy" "alarm source";
    column-gap: 9px;
    padding-inline: var(--card-padding);
  }
  .site-card .site-header {
    grid-area: header;
    flex-flow: row wrap;
    align-items: baseline;
    margin-inline: 0;
    padding-block: 4px;
    gap: 2px 8px;
  }
  .site-card .site-name { font-size: 1.1rem; }
  .site-card .battery-section { grid-area: battery; padding: 5px 0; gap: 3px; grid-template-columns: 1fr auto; }
  .site-card .metric-number { font-size: 1.5rem; }
  .site-card .battery-gauge { width: 31px; }
  .site-card .battery-trend canvas { height: 20px; }
  .site-card .power-section { grid-area: power; flex-wrap: wrap; margin: 0; padding: 4px 0; gap: 2px 6px; }
  .site-card .power-reading { font-size: 1rem; }
  .site-card .direction { padding: 0; border: 0; }
  .site-card .direction-label { padding: 2px 4px; }
  .site-card .energy-grid { grid-area: energy; margin: 0; padding: 3px 0 2px 6px; column-gap: 5px; border: 0; border-inline-start: 1px solid var(--schot-line); }
  .site-card .energy-metric { padding-block: 4px; }
  .site-card .net-metric { grid-template-areas: "net-label net-label" "net-reading net-reading" "net-direction net-direction" "net-trend net-trend"; }
  .site-card .net-metric .energy-direction { justify-self: start; }
  .site-card .alarms-section, .site-card .site-footer { margin: 0; padding: 4px 0; border-top: 1px solid var(--schot-line); }
  .site-card .alarms-section { grid-area: alarm; }
  .site-card .site-footer { grid-area: source; align-content: center; justify-content: flex-end; }
}
