/* Layout and the components' looks. The colours and sizes come from tokens.css; the shapes
 * mirror app/ios/Gofannon/Design/Components.swift (Card, Banner, the buttons, the fields). */

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
svg { display: block; }

/* One ring for everything that takes focus from the keyboard, and only then. */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

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

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

.noscript { padding: var(--xl); text-align: center; color: var(--text-secondary); }

/* ---------- the page ---------- */

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--gutter) var(--xxl);
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--l);
  min-height: 56px;
  padding: var(--s) 0;
}
.topbar .brand {
  font-weight: 600;
  font-size: var(--fs-body);
  color: var(--text);
}
.topbar .brand:hover { text-decoration: none; }
.topbar nav { margin-left: auto; display: flex; gap: var(--xs); }
.topbar nav a {
  padding: 6px 10px;
  border-radius: var(--r-small);
  font-size: var(--fs-subheadline);
  color: var(--text-secondary);
}
.topbar nav a:hover { text-decoration: none; background: var(--surface-sunken); }
.topbar nav a[aria-current="page"] { color: var(--text); background: var(--surface-sunken); }

.screen { display: flex; flex-direction: column; gap: var(--l); padding-top: var(--s); }

/* One column up to 720 px, two above: a desktop is wider than a phone. */
.columns { display: grid; grid-template-columns: 1fr; gap: var(--l); align-items: start; }
@media (min-width: 721px) {
  .columns { grid-template-columns: 1fr 1fr; }
  .columns > .span { grid-column: 1 / -1; }
}
.stack { display: flex; flex-direction: column; gap: var(--l); min-width: 0; }

.page-title {
  font-family: var(--font-rounded);
  font-size: var(--fs-title);
  font-weight: 600;
  line-height: 1.15;
}
.page-subtitle { font-size: var(--fs-subheadline); color: var(--text-secondary); }

.section-header {
  font-size: var(--fs-footnote);
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0 var(--xs);
  margin-bottom: calc(-1 * var(--xs));
}

.version { font-size: var(--fs-caption2); color: var(--text-tertiary); text-align: center; }

/* ---------- card ---------- */

.card {
  display: flex;
  flex-direction: column;
  gap: var(--m);
  padding: var(--l);
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--card-shadow);
  min-width: 0;
}
.card-title {
  display: flex;
  align-items: center;
  gap: var(--s);
  font-size: var(--fs-subheadline);
  font-weight: 600;
  color: var(--text-secondary);
}
.card-title .icon { color: var(--text-tertiary); }
.card-title .chip { margin-left: auto; }
.card-footnote { font-size: var(--fs-footnote); color: var(--text-tertiary); }

.chip {
  display: inline-block;
  padding: 3px var(--s);
  border-radius: 999px;
  font-size: var(--fs-caption2);
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-sunken);
  white-space: nowrap;
}

.hairline { height: 1px; background: var(--line); border: 0; margin: 0; }

/* ---------- rows and numbers ---------- */

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--m);
  font-size: var(--fs-subheadline);
}
.info-row .label { color: var(--text-secondary); }
.info-row .value { color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.info-row .value.mono { font-family: var(--font-mono); font-size: var(--fs-footnote); }

.big-value { display: flex; flex-direction: column; gap: var(--xs); }
.big-value .number {
  display: flex; align-items: baseline; gap: 3px;
  font-family: var(--font-rounded);
  font-size: var(--fs-big-value);
  font-weight: 300;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.big-value .unit { font-size: calc(var(--fs-big-value) * 0.4); font-weight: 400; color: var(--text-secondary); }
.big-value .caption { font-size: var(--fs-footnote); color: var(--text-tertiary); }

.small-value { display: flex; flex-direction: column; gap: 2px; }
.small-value .label { font-size: var(--fs-caption); color: var(--text-tertiary); }
.small-value .value { font-size: var(--fs-title3); font-variant-numeric: tabular-nums; }
.small-value .caption { font-size: var(--fs-caption2); color: var(--text-tertiary); }

.code-block {
  margin: 0;
  padding: var(--m);
  background: var(--surface-sunken);
  border-radius: var(--r-small);
  font-family: var(--font-mono);
  font-size: var(--fs-caption);
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
}

/* ---------- notices ---------- */

.banner {
  display: flex;
  gap: var(--m);
  align-items: flex-start;
  padding: var(--m);
  border-radius: calc(var(--r-card) - 4px);
  background: var(--surface-sunken);
  --tint: var(--text-secondary);
  --on-tint: var(--on-accent);
}
.banner.ok { background: var(--accent-soft); --tint: var(--accent); }
.banner.warning { background: var(--warning-soft); --tint: var(--warning); --on-tint: var(--on-warning); }
.banner.danger { background: var(--danger-soft); --tint: var(--danger); --on-tint: var(--surface); }
.banner .icon { color: var(--tint); flex: none; margin-top: 2px; }
.banner-body { display: flex; flex-direction: column; gap: var(--xs); min-width: 0; }
.banner-title { font-size: var(--fs-subheadline); font-weight: 500; color: var(--text); }
.banner-text { font-size: var(--fs-footnote); color: var(--text-secondary); }
.banner-action { margin-top: var(--xs); }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s);
  border: 0;
  cursor: pointer;
  background: none;
  transition: opacity 120ms ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: 0.35; cursor: default; }
.btn:not(:disabled):active { opacity: 0.7; }
.btn.full { width: 100%; }

/* the one action a screen puts forward */
.btn.primary {
  width: 100%;
  padding: 14px var(--l);
  border-radius: var(--r-control);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 500;
}
/* there, but does not shout */
.btn.secondary {
  width: 100%;
  padding: 12px var(--l);
  border-radius: var(--r-control);
  background: var(--surface-sunken);
  color: var(--tint, var(--text));
  font-size: var(--fs-subheadline);
  font-weight: 500;
}
/* a text button inside running content */
.btn.quiet {
  padding: 4px 0;
  color: var(--tint, var(--accent));
  font-size: var(--fs-footnote);
  font-weight: 500;
}
.btn.quiet:hover { text-decoration: underline; }
/* a small filled button inside a notice, in the notice's own colour */
.btn.filled-small {
  padding: var(--s) var(--m);
  border-radius: var(--r-small);
  background: var(--tint, var(--accent));
  color: var(--on-tint, var(--on-accent));
  font-size: var(--fs-footnote);
  font-weight: 600;
}
.btn.icon-btn {
  width: 36px; height: 36px;
  border-radius: 999px;
  color: var(--text-secondary);
}
.btn.icon-btn:hover { background: var(--surface-sunken); }

/* ---------- input ---------- */

.field { display: flex; flex-direction: column; gap: var(--xs); }
.field > .label { font-size: var(--fs-caption); color: var(--text-tertiary); }
.field .input {
  display: flex;
  align-items: center;
  gap: var(--s);
  padding: 11px var(--m);
  background: var(--surface-sunken);
  border-radius: var(--r-small);
}
.field .input:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.field input, .field select, .field textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: 0;
  background: none;
  font-size: var(--fs-body);
  color: var(--text);
}
.field input:focus { outline: none; }
.field .hint { font-size: var(--fs-caption); color: var(--text-tertiary); }

.select-plain {
  border: 0;
  padding: 6px 28px 6px 10px;
  border-radius: var(--r-small);
  background: var(--surface-sunken);
  font-size: var(--fs-subheadline);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B655E' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

/* ---------- waiting ---------- */

.working {
  display: flex;
  align-items: center;
  gap: var(--s);
  font-size: var(--fs-subheadline);
  color: var(--text-secondary);
}
.spinner {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- rows that lead somewhere ---------- */

.setting-row {
  display: flex;
  align-items: center;
  gap: var(--m);
  width: 100%;
  padding: 10px 0;
  border: 0;
  background: none;
  text-align: left;
  color: var(--text);
  cursor: pointer;
}
.setting-row:hover { text-decoration: none; }
.setting-row .plate {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  color: var(--accent);
  background: var(--accent-soft);
  flex: none;
}
.setting-row .title { flex: 1; }
.setting-row .detail {
  font-size: var(--fs-footnote); color: var(--text-tertiary); text-align: right;
  max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;   /* the title keeps its line */
}
.setting-row .chevron { color: var(--text-tertiary); flex: none; }

/* ---------- the modes ---------- */

.mode-row { display: flex; flex-direction: column; gap: 6px; }
.mode-row .buttons { display: flex; gap: var(--s); }
.mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 0;
  border: 0;
  border-radius: var(--r-small);
  background: var(--surface-sunken);
  color: var(--text);
  font-size: var(--fs-caption);
  font-weight: 500;
  cursor: pointer;
}
.mode-btn:disabled { cursor: default; opacity: 0.6; }
.mode-btn.selected.off { background: var(--text); color: var(--background); }
.mode-btn.selected.cool { background: var(--cooling); color: var(--on-cooling); }
.mode-btn.selected.heat { background: var(--heating); color: var(--on-heating); }
/* faded while the controller stands aside: the mode is what the pump was left at */
.mode-btn.selected.stood-down { opacity: 0.5; }
.mode-row .note { font-size: var(--fs-caption); color: var(--text-tertiary); }
.mode-row .note.sending { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }

/* ---------- the dial ---------- */

.dial { width: 100%; max-width: 270px; margin: 0 auto; position: relative; touch-action: none; }
.dial svg { width: 100%; height: auto; overflow: visible; }
.dial .handle { cursor: grab; }
.dial .handle:active { cursor: grabbing; }
.dial .centre { text-anchor: middle; fill: var(--text); }
.dial .word { font-size: 11px; letter-spacing: 0.3px; fill: var(--text-tertiary); }
.dial .target { font-family: var(--font-rounded); font-size: 56px; font-weight: 300; font-variant-numeric: tabular-nums; }
.dial .degree { font-family: var(--font-rounded); font-size: 13px; fill: var(--text-secondary); }
.dial .room { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.dial .step {
  position: absolute;
  bottom: 2%;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: none;
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.dial .step.minus { left: calc(50% - 53px); }
.dial .step.plus { left: calc(50% + 9px); }
.dial .step:disabled { opacity: 0.35; cursor: default; }

/* ---------- graph ---------- */

.graph { width: 100%; }
.graph svg { width: 100%; height: auto; overflow: visible; }
.graph .axis text { font-size: 10px; fill: var(--text-tertiary); }
.graph .axis line { stroke: var(--line); }
.graph .grid line { stroke: var(--line); stroke-dasharray: 2 3; }
.graph-legend { display: flex; flex-wrap: wrap; gap: var(--m); font-size: var(--fs-caption); color: var(--text-secondary); margin-top: var(--s); }
.graph-legend .swatch { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

/* ---------- sheet ---------- */

.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 10;
  padding: 0;
}
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow: auto;
  background: var(--background);
  border-radius: var(--r-card) var(--r-card) 0 0;
  padding: var(--l) var(--gutter) var(--xl);
  display: flex; flex-direction: column; gap: var(--l);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
}
@media (min-width: 721px) {
  .sheet-backdrop { align-items: center; padding: var(--xl); }
  .sheet { border-radius: var(--r-card); max-height: 85vh; }
}
.sheet-head { display: flex; align-items: center; gap: var(--m); }
.sheet-head h2 { font-size: var(--fs-title3); font-weight: 600; flex: 1; }

/* ---------- the home ---------- */

.home-head { display: flex; flex-direction: column; gap: var(--xs); padding: 0 var(--xs); }
.home-head .date { font-size: var(--fs-subheadline); color: var(--text-secondary); }
.home-head .sentence {
  font-family: var(--font-rounded);
  font-size: var(--fs-title);
  font-weight: 600;
  line-height: 1.15;
}
.home-head .under { font-size: var(--fs-subheadline); color: var(--text-secondary); }
.home-head .other-home {
  display: inline-flex; align-items: center; gap: var(--xs);
  margin-top: var(--xs);
  font-size: var(--fs-subheadline); font-weight: 500; color: var(--warning);
}
.home-head .other-home .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); }
.home-picker { display: flex; align-items: center; gap: var(--s); }

.el-line {
  display: flex; align-items: center; gap: var(--s);
  margin-top: var(--xs);
  padding: var(--s) var(--m);
  border-radius: var(--r-small);
  background: var(--energy-soft);
  font-size: var(--fs-footnote);
  color: var(--text-secondary);
}
.el-line:hover { text-decoration: none; }
.el-line .icon { color: var(--energy); }
.el-line b { color: var(--text); }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--m);
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 150px;
  padding: var(--m);
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--card-shadow);
  color: var(--text);
}
.tile:hover { text-decoration: none; }
.tile.dim { opacity: 0.75; }
.tile .top { display: flex; justify-content: space-between; align-items: flex-start; padding-bottom: var(--xs); }
.tile .top .chevron { color: var(--text-tertiary); opacity: 0.7; }
.tile .name { font-size: var(--fs-subheadline); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .big {
  display: flex; align-items: baseline; gap: 1px;
  font-family: var(--font-rounded);
  font-size: var(--fs-large-title);
  font-weight: 300;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.tile .big .unit { font-size: var(--fs-title3); color: var(--text-secondary); margin-left: 3px; }
.tile .big .deg { font-size: var(--fs-title2); }
.tile .status { display: flex; align-items: baseline; gap: 3px; font-size: var(--fs-caption); color: var(--text-tertiary); }
.tile .status.heating { color: var(--heating); }
.tile .status.cooling { color: var(--cooling); }
.tile .status.warning { color: var(--warning); }
.tile .status.danger { color: var(--danger); }
.tile .status.secondary { color: var(--text-secondary); }
.tile .status.sun { color: var(--sun); }
.tile .bolt {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%;
  color: var(--energy); background: var(--energy-soft);
}
.tile.new {
  align-items: center; justify-content: center; gap: var(--s);
  background: none; box-shadow: none;
  border: 1.5px dashed var(--line);
  color: var(--accent);
  font-size: var(--fs-caption); font-weight: 600; text-align: center;
}

.day-row {
  display: flex; align-items: baseline; gap: var(--s);
  padding: var(--s) 0;
  font-size: var(--fs-footnote);
}
.day-row .when { min-width: 40px; font-size: var(--fs-caption); color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.day-row .icon { flex: none; align-self: center; }
.day-row + .day-row { border-top: 1px solid var(--line); }

.weather-line { display: flex; align-items: center; gap: var(--s); font-size: var(--fs-subheadline); }
.weather-line .temp { font-weight: 600; }
.weather-line .detail { font-size: var(--fs-caption); color: var(--text-secondary); }
.weather-now { display: flex; align-items: center; gap: var(--l); }
.weather-now .temp { font-family: var(--font-rounded); font-size: var(--fs-title); font-weight: 300; line-height: 1.1; }
.weather-now .feels { font-size: var(--fs-caption); color: var(--text-tertiary); }
.weather-now .right { margin-left: auto; text-align: right; font-size: var(--fs-caption); color: var(--text-secondary); }
.weather-hours { display: flex; }
.weather-hours .hour { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: var(--fs-caption); }
.weather-hours .hour .h { font-size: var(--fs-caption2); color: var(--text-tertiary); }
.weather-hours .hour .t { font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- sign in ---------- */

.signin { max-width: 480px; margin: 0 auto; padding-top: var(--xl); }
.signin .brand-title { font-size: var(--fs-large-title); font-weight: 600; }
.signin .intro { color: var(--text-secondary); margin-top: var(--s); }

/* ---------- diagnostics ---------- */

.diag-list { display: flex; flex-direction: column; gap: 2px; font-family: var(--font-mono); font-size: var(--fs-caption); }
.diag-list .failed { color: var(--danger); }
