/* Solar dashboard, Eon Home design system. Every colour, size, radius and shadow comes from theme.css: nothing in this
   file holds a raw colour value, and colours are the semantic tokens (--surface, --text, --accent, ...) so that light and
   dark are both covered. No inline styles anywhere (CSP style-src 'self'); everything is class based. Mobile first: a
   375px frame with 20px gutters (a 335px column). The frame, header, navigation and mode sheet are in css/shell.css. */

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
  font-weight: var(--weight-regular);
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: var(--weight-semibold);
  color: var(--text);
}

h1 {
  font-size: var(--text-xl-size);
  line-height: var(--text-xl-line);
}

h2 {
  font-size: var(--text-lg-size);
  line-height: var(--text-lg-line);
}

h3 {
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
}

p {
  margin: var(--space-4) 0;
}

a {
  color: var(--accent);
  font-weight: var(--weight-medium);
}

a:hover {
  color: var(--accent-hover);
}

code,
.mono {
  font-family: var(--font-mono);
  font-size: 0.9em;
  overflow-wrap: anywhere;
}

.table-wrap .mono {
  overflow-wrap: normal;
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  box-shadow: var(--focus-ring-brand);
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--surface);
  padding: var(--space-8) var(--space-16);
  z-index: 100;
}

.skip:focus {
  left: 8px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.muted {
  color: var(--text-2);
}

.small {
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
}

.right {
  text-align: right;
}

.num {
  font-variant-numeric: tabular-nums;
}

/* Stacked blocks: 12px apart inside a card, 24px apart between the sections of a screen. */
.stack > * + * {
  margin-top: var(--space-12);
}

/* The first block that is actually there sits flush under the header: a hidden block or an empty slot (Settings' notice) before
   it must not push it down. `where()` keeps the specificity of the plain `* + *` rule this replaces. */
main > section.stack > :where(:not([hidden], .set-invalid:empty)) ~ * {
  margin-top: var(--space-24);
}

.set-invalid:empty {
  display: none;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-8);
  align-items: center;
}

.row.between {
  justify-content: space-between;
}

/* One ink, no reversed version: in dark the mark sits on a white tile (--logo-tile, --logo-pad), in light on the page. */
.logomark {
  flex: none;
  box-sizing: content-box;
  padding: var(--logo-pad);
  border-radius: var(--logo-radius);
  background: var(--logo-tile);
  fill: var(--logo-ink);
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-24);
}

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-12);
  padding: var(--space-16);
  min-width: 0;
}

/* Free text (agent briefs, override reasons, proposal arguments, URLs and tokens) has no break points of its own: let
   it wrap anywhere instead of widening the page. Tables keep their natural column widths and scroll inside their own
   wrapper (see .table-wrap). */
.card,
.notice,
.toast,
dialog,
footer.site {
  overflow-wrap: anywhere;
}

.card > h2,
.card > .card-head {
  margin-bottom: var(--space-12);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-8);
  align-items: center;
  justify-content: space-between;
}

.card-head h2 {
  margin: 0;
}

/* The fine grain on summary cards (a 154px tile at 60%), behind the content. */
.grain {
  position: relative;
  isolation: isolate;
}

.grain::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: url('/img/grain-texture.webp') 0 0 / 154px 154px;
  opacity: var(--grain-opacity);
  pointer-events: none;
}

/* Round-cornered tile that frames one icon: white, gray-200 border, brand-600 icon. */
.featured {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-10);
  background: var(--surface-raised);
  box-shadow: var(--shadow-xs);
  color: var(--accent);
}

.featured.sm {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-8);
}

.featured.circle {
  border-radius: var(--radius-full);
}

/* ---------- figures: the number is the hero, the unit follows in a lighter weight ---------- */

/* A figure shrinks and breaks (last resort) instead of running out of its card when the text is enlarged. */
.fig {
  min-width: 0;
  overflow-wrap: anywhere;
}

.fig-num {
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

.fig-unit {
  font-weight: var(--weight-regular);
  font-size: 0.7em;
}

.key {
  color: var(--accent);
}

/* ---------- buttons ---------- */

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  min-height: 40px;
  padding: 0 var(--space-16);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-12);
  background: var(--surface-raised);
  box-shadow: var(--shadow-xs);
  color: var(--text-strong);
  font: inherit;
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition:
    background-color 150ms,
    box-shadow 150ms,
    border-color 150ms;
}

button:hover:not(:disabled) {
  background: var(--btn-hover);
}

/* Disabled controls go to gray-100 fills; the text is gray-500 (not gray-400) so it stays readable (--text-disabled). */
button:disabled {
  background: var(--fill);
  border-color: var(--border);
  box-shadow: none;
  color: var(--text-disabled);
  cursor: not-allowed;
}

button.primary {
  background: var(--accent-solid);
  border-color: var(--accent-solid-edge);
  box-shadow: var(--shadow-sm);
  color: var(--text-on-accent);
}

button.primary:hover:not(:disabled) {
  background: var(--accent-solid-hover);
  border-color: var(--accent-solid-hover);
}

button.primary:disabled {
  background: var(--fill);
  border-color: var(--border);
  box-shadow: none;
  color: var(--text-disabled);
}

button.danger {
  background: var(--crit-solid);
  border-color: var(--crit-solid);
  box-shadow: var(--shadow-sm);
  color: var(--text-on-accent);
}

button.danger:hover:not(:disabled) {
  background: var(--crit-solid-hover);
  border-color: var(--crit-solid-hover);
}

button.danger:disabled {
  background: var(--fill);
  border-color: var(--border);
  box-shadow: none;
  color: var(--text-disabled);
}

button.link {
  min-height: 0;
  padding: 0 var(--space-2);
  border: 0;
  background: none;
  box-shadow: none;
  color: var(--accent);
}

button.link:hover:not(:disabled) {
  background: none;
  color: var(--accent-hover);
  text-decoration: underline;
}

button.small {
  min-height: 36px;
  padding: 0 var(--space-12);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
}

button.link.small {
  min-height: 0;
}

/* Touch targets: these look small, but the part that answers a tap is at least 44px tall (and 44px wide for the shortest words).
   The extra is an invisible extension of the button, sized from the button itself (a taller button gets less, none from 44px),
   so nothing moves and neighbours are not covered more than they need to be. */
button.link,
button.small,
.legend button {
  position: relative;
}

button.link::after,
button.small::after,
.legend button::after {
  content: '';
  position: absolute;
  inset-block: calc(-1 * max(0px, (44px - 100%) / 2));
  inset-inline: calc(-1 * max(var(--space-2), (44px - 100%) / 2));
}

/* ---------- inputs: gray-50 fill, a 3:1 edge (--control-border), radius 8, 44px tall, label above ---------- */

label {
  display: block;
  margin-bottom: var(--space-6);
  color: var(--text-2);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
  font-weight: var(--weight-medium);
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--space-10) var(--space-14);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-8);
  background: var(--surface-2);
  box-shadow: var(--shadow-xs);
  color: var(--text);
  font: inherit;
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--fill);
  color: var(--text-disabled);
  cursor: not-allowed;
}

input[type='checkbox'] {
  flex: none;
  width: 20px;
  min-height: 0;
  height: 20px;
  margin: 0 var(--space-8) 0 0;
  padding: 0;
  accent-color: var(--accent-solid);
  box-shadow: none;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

.field {
  min-width: 0;
}

.field.check label {
  display: flex;
  align-items: center;
  min-height: 44px;
  margin: 0;
  color: var(--text);
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
}

.hint {
  display: block;
  margin-top: var(--space-6);
  color: var(--text-2);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
}

.fields {
  display: grid;
  gap: var(--space-16) var(--space-12);
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: var(--space-12) var(--space-16) var(--space-16);
  border: 1px solid var(--border);
  border-radius: var(--radius-12);
}

legend {
  padding: 0 var(--space-6);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
  font-weight: var(--weight-semibold);
}

/* A field that failed its check: red edge, and the reason right under it (forms.js sets aria-invalid and aria-describedby). */
input[aria-invalid='true'],
select[aria-invalid='true'],
textarea[aria-invalid='true'],
.input-wrap:has([aria-invalid='true']) {
  border-color: var(--crit);
}

.field-error {
  display: flex;
  align-items: flex-start;
  gap: var(--space-6);
  margin-top: var(--space-6);
  color: var(--crit-text);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
  font-weight: var(--weight-medium);
}

.field-error > .eh-icon {
  flex: none;
  margin-top: var(--space-2);
}

.form-msg {
  min-height: var(--text-sm-line);
  margin: var(--space-8) 0 0;
  font-size: var(--text-sm-size);
}

.form-msg.error {
  color: var(--crit-text);
}

.form-msg.ok {
  color: var(--ok-text);
}

progress {
  display: block;
  width: 100%;
  height: var(--space-8);
  border: 0;
  border-radius: var(--radius-full);
  background: var(--accent-weak);
  appearance: none;
  -webkit-appearance: none;
  overflow: hidden;
}

progress::-webkit-progress-bar {
  background: var(--accent-weak);
}

progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: var(--radius-full);
}

progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: var(--radius-full);
}

/* ---------- notices (the old .badge is a chip: see css/components.css) ---------- */

.notice {
  margin: 0;
  padding: var(--space-12) var(--space-14);
  border: 1px solid var(--border);
  border-radius: var(--radius-12);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
}

/* A notice built with notice() in dom.js: a status icon, then the text. */
.notice.has-icon {
  display: flex;
  align-items: flex-start;
  gap: var(--space-10);
}

.notice-body {
  min-width: 0;
}

.notice > .eh-icon {
  flex: none;
  margin-top: var(--space-2);
}

.notice.warn {
  background: var(--warn-weak);
}

.notice.warn > .eh-icon {
  color: var(--warn-text);
}

.notice.crit {
  background: var(--crit-weak);
}

.notice.crit > .eh-icon {
  color: var(--crit-text);
}

.notice.ok {
  background: var(--ok-weak);
}

.notice.ok > .eh-icon {
  color: var(--ok-text);
}

.notice.info > .eh-icon {
  color: var(--text-strong);
}

/* a notice that is a list (plan warnings) */
ul.notice {
  display: block;
  padding-left: var(--space-32);
}

ul.notice li + li {
  margin-top: var(--space-4);
}

/* ---------- usage cards (flexible loads) ---------- */

.usage-head {
  display: flex;
  align-items: center;
  gap: var(--space-12);
}

.usage-head .grow {
  flex: 1;
  min-width: 0;
}

.usage-head h3 {
  font-size: var(--text-md-size);
}

.usage-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: var(--space-12);
  padding-top: var(--space-12);
  border-top: 1px solid var(--border);
}

.usage-stat {
  min-width: 0;
}

.usage-stat + .usage-stat {
  padding-left: var(--space-16);
  border-left: 1px solid var(--border);
}

.usage-stat .label {
  color: var(--text-2);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
}

.usage-stat .value {
  color: var(--text);
  font-size: var(--text-lg-size);
  line-height: var(--text-lg-line);
}

/* ---------- tables ---------- */

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  overflow-wrap: normal;
  /* Scroll shadows: a soft edge on the side that has more to scroll to (pure CSS, no script). */
  background:
    linear-gradient(to right, var(--surface) 30%, transparent) left center / 28px 100% no-repeat local,
    linear-gradient(to left, var(--surface) 30%, transparent) right center / 28px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, var(--border-strong), transparent) left center / 10px 100%
      no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, var(--border-strong), transparent) right center / 10px 100%
      no-repeat scroll;
}

.table-wrap:focus-visible {
  outline-offset: -3px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
}

caption {
  text-align: left;
  padding-bottom: var(--space-8);
}

th,
td {
  text-align: left;
  padding: var(--space-10) var(--space-8);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

td.num,
th.num {
  text-align: right;
  white-space: nowrap;
}

tr.lookahead td {
  color: var(--text-2);
}

tr.frozen td,
tr.current td {
  background: var(--surface-2);
}

/* The column is narrower than any plan table: the reason is shown under the mode and the Reason column is dropped;
   a hint says the rest is a swipe away. */
.plan-table .col-reason {
  display: none;
}

.slot-reason {
  display: block;
  margin-top: var(--space-2);
  min-width: 11em;
  max-width: 15em;
  white-space: normal;
  overflow-wrap: break-word;
  color: var(--text-2-strong);
}

.swipe-hint {
  display: block;
}

tr.detail td {
  background: var(--surface-2);
}

.mode-chip {
  display: inline-block;
  padding: 0 var(--space-8);
  border-radius: var(--radius-6);
  background: var(--fill);
  color: var(--text-strong);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

.mode-chip.GRID_CHARGE {
  background: var(--band-charge);
  color: var(--accent-weak-text);
}

.mode-chip.FORCE_EXPORT {
  background: var(--band-export);
  color: var(--warn-text);
}

.mode-chip.HOLD {
  background: var(--band-hold);
  color: var(--text-strong);
}

/* ---------- charts ---------- */

.chart-block + .chart-block {
  margin-top: var(--space-24);
}

.chart-title {
  margin-bottom: var(--space-4);
  color: var(--text);
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
  font-weight: var(--weight-semibold);
}

.chart-frame {
  position: relative;
  height: 200px;
  width: 100%;
}

.chart-frame.tall {
  height: 260px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-6);
  margin: var(--space-4) 0 var(--space-6);
  padding: 0;
  list-style: none;
}

.legend button {
  gap: var(--space-6);
  min-height: 28px;
  padding: 0 var(--space-10);
  border-color: var(--control-border);
  border-radius: var(--radius-full);
  box-shadow: none;
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
  font-weight: var(--weight-medium);
}

.legend button[aria-pressed='false'] {
  opacity: 0.45;
  text-decoration: line-through;
}

.swatch {
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 3px solid currentColor;
}

.swatch.dashed {
  border-top-style: dashed;
}

.swatch.band {
  height: 10px;
  border-top: 0;
  opacity: 0.6;
  background: currentColor;
}

.band-key {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-12);
  margin: 0 0 var(--space-16);
  color: var(--text-2);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
}

.band-key span::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: var(--space-6);
  vertical-align: -2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-4);
}

.band-key .charge::before {
  background: var(--band-charge);
}

.band-key .export::before {
  background: var(--band-export);
}

.band-key .hold::before {
  background: var(--band-hold);
}

.c-import {
  color: var(--series-import);
}

.c-export {
  color: var(--series-export);
}

.c-pv {
  color: var(--series-pv);
}

.c-load {
  color: var(--series-load);
}

.c-soc {
  color: var(--series-soc);
}

/* ---------- lists ---------- */

ul.plain,
ol.plain {
  margin: 0;
  padding: 0;
  list-style: none;
}

ul.plain > li + li {
  margin-top: var(--space-8);
}

ul.bullets > li {
  position: relative;
  padding-left: var(--space-16);
}

ul.bullets > li::before {
  content: '';
  position: absolute;
  left: var(--space-4);
  top: var(--space-8);
  width: var(--space-4);
  height: var(--space-4);
  border-radius: var(--radius-full);
  background: var(--text-3);
}

.check-item {
  display: flex;
  gap: var(--space-8);
  align-items: flex-start;
}

.check-item .icon {
  display: inline-flex;
  flex: none;
  margin-top: var(--space-2);
}

.check-item.pass .icon {
  color: var(--ok);
}

.check-item.fail .icon {
  color: var(--crit);
}

.check-item.unknown .icon {
  color: var(--warn);
}

.timeline {
  margin: 0;
  padding: 0 0 0 var(--space-14);
  list-style: none;
  border-left: 2px solid var(--border);
  font-size: var(--text-sm-size);
}

.timeline li {
  margin: 0 0 var(--space-6);
  padding-left: var(--space-8);
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
  max-height: 340px;
  overflow-y: auto;
}

.bubble {
  max-width: 92%;
  padding: var(--space-10) var(--space-14);
  border-radius: var(--radius-12);
  background: var(--fill);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent-weak);
}

/* ---------- bottom sheet (dialog) and toasts ---------- */

dialog {
  /* A sheet is the raised surface: what sits inside it (inputs, rules, chips) steps one shade on in dark. */
  --surface-2: var(--surface-2-raised);
  --border: var(--border-raised);
  --fill: var(--fill-raised);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  margin: auto auto 0;
  padding: var(--space-24) var(--space-20) calc(var(--space-24) + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  border: 0;
  border-radius: var(--radius-24) var(--radius-24) 0 0;
  background: var(--surface-raised);
  box-shadow: none;
  color: var(--text);
}

dialog::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  margin: calc(-1 * var(--space-12)) auto var(--space-16);
  border-radius: var(--radius-full);
  background: var(--border);
}

dialog > h2 {
  margin-bottom: var(--space-12);
  font-size: var(--text-xl-size);
  line-height: var(--text-xl-line);
}

dialog::backdrop {
  background: var(--scrim);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-8);
  margin-top: var(--space-16);
}

.dialog-actions button {
  min-height: 44px;
}

.toasts {
  position: fixed;
  right: var(--space-20);
  bottom: calc(
    56px + var(--space-16) + var(--space-12) + env(safe-area-inset-bottom, 0px)
  ); /* above the floating bar */
  left: var(--space-20);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

/* Two standing live regions inside the stack (index.html): a polite one for confirmations, an assertive one for errors. They
   exist before any toast does, so a screen reader announces each message once, and the toasts themselves carry no role. */
.toast-lane {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-8);
  width: 100%;
}

.toast-lane:not(:empty) + .toast-lane:not(:empty) {
  margin-top: var(--space-8);
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-10);
  max-width: 440px;
  padding: var(--space-12) var(--space-14);
  border: 1px solid var(--border);
  border-radius: var(--radius-12);
  background: var(--surface-raised);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
}

.toast > .eh-icon {
  flex: none;
  margin-top: var(--space-2);
  color: var(--text-strong);
}

.toast.ok > .eh-icon {
  color: var(--ok);
}

.toast.error > .eh-icon {
  color: var(--crit);
}

footer.site {
  margin-top: var(--space-32);
  padding-top: var(--space-12);
  border-top: 1px solid var(--border);
  color: var(--text-2);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
