/* Same look as the Sema4 web app (sema4/web/style.css): dark, few words, large targets; the
   card is a rectangle with a coloured left edge - bright green working, quieter green on but
   idle, orange queued, grey off - the name and the two controls (star, switch) on top, watts
   and state below. */

:root {
  --bg: #12151a;
  --card: #1b2027;
  --card-hi: #232a33;
  --line: #2e3742;
  --text: #e8edf3;
  --dim: #93a1b1;
  --green: #34c759;
  --green-on: #6a9f74;
  --amber: #ffb020;
  --red: #ff453a;
  --grey: #5b6673;
  --radius: 18px;
  /* WebKitGTK (Linux desktop shell) paints native <select> light unless told dark
     (owner, 11/10/2026: "Cos'è" dropdown white). */
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 clamp(15px, 2.4vw, 19px)/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
/* The page is the viewport and never scrolls as a whole. On home the plugs and the
   buttons take three quarters and scroll inside that area; "what happened" is the
   bottom quarter and scrolls on its own (owner, 18/9/2026). The wizard card, if taller
   than the screen, scrolls in main. */
html, body { height: 100%; }
body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); display: flex; flex-direction: column; overflow: hidden; }
/* One content width for every page that shares this stylesheet (home, download, …). */
main {
  flex: 1; min-height: 0; width: 100%; max-width: 900px; margin: 0 auto;
  padding: clamp(.8rem, 2vw, 1.4rem); display: grid; gap: 1.2rem;
  grid-template-rows: minmax(0, 1fr); align-content: start;
  overflow-y: auto;
}
main.home {
  grid-template-rows: minmax(0, 3fr) minmax(0, 1fr);
  overflow: hidden;
  align-content: stretch;
}
.home-plugs { min-height: 0; display: flex; flex-direction: column; gap: .8rem; overflow: hidden; }
.home-plugs .tiles, .events ol {
  overscroll-behavior: contain;
  overflow-anchor: none;
}
.home-plugs .tiles { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--grey) transparent; }
.home-plugs .row { flex: none; margin-top: 0; }
.events { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.events ol { flex: 1; min-height: 0; overflow-y: scroll; scrollbar-width: auto; scrollbar-color: var(--dim) transparent; }
.home-plugs .tiles::-webkit-scrollbar, .events ol::-webkit-scrollbar { width: 10px; }
.events ol::-webkit-scrollbar-thumb, .home-plugs .tiles::-webkit-scrollbar-thumb {
  background: var(--dim); border-radius: 5px;
}

/* Header as in sema4: 32px light and title, the flag at the right, a line under.
   Pull-to-refresh lives here only — not on the plugs list (owner, 29/9/2026). */
header {
  display: flex; flex-direction: column;
  border-bottom: 1px solid var(--line);
  touch-action: pan-y;
}
.header-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; padding: .8rem clamp(.8rem, 2vw, 1.4rem);
}
/* Slot above the title: grows while you pull, holds the spinner */
.pull-slot {
  display: flex; align-items: center; justify-content: center;
  height: 0; overflow: hidden;
  transition: height .15s ease-out;
}
header.pulling .pull-slot { transition: none; }
.pull-spin {
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--green);
  opacity: 0; transform: rotate(0deg);
  transition: opacity .12s;
}
header.pulling .pull-spin,
header.refreshing .pull-spin { opacity: 1; }
header.pull-armed .pull-spin,
header.refreshing .pull-spin {
  animation: pull-spin .7s linear infinite;
}
@keyframes pull-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .pull-slot { transition: none; }
  header.pull-armed .pull-spin,
  header.refreshing .pull-spin { animation: none; border-top-color: var(--amber); }
}
h1 { font-size: 32px; margin: 0; letter-spacing: .04em; display: flex; align-items: center; gap: .45rem; line-height: 1; }
h1 a { color: inherit; text-decoration: none; display: flex; align-items: center; gap: .45rem; }
/* Cropped viewBox so the traffic light fills the box (full 0..64 left it tiny
   in the middle — owner, 15/10/2026). */
h1 .logo { width: 48px; height: 48px; flex: none; display: block; }
h1 .lite { color: var(--amber); font-weight: 400; font-size: .7em; margin-left: .25rem; }
h2 { font-size: 1em; margin: 0 0 .6rem; color: var(--dim); font-weight: 600; }
p { margin: .5rem 0; }
.muted { color: var(--dim); }

.head-right { display: flex; align-items: center; gap: .6rem; flex: none; }
.lang { position: relative; flex: none; }
.flag-btn { padding: .5rem .6rem; min-height: 0; display: flex; align-items: center; }
.flag { width: 30px; height: 20px; border-radius: 4px; display: block; object-fit: cover; }
.lang-list {
  position: absolute; right: 0; top: calc(100% + .4rem); z-index: 5; margin: 0; padding: .3rem; list-style: none;
  background: var(--card-hi); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  min-width: 10rem;
}
.lang-list li { display: flex; align-items: center; gap: .6rem; padding: .6rem .7rem; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.lang-list li:hover { background: var(--card); }

/* --- controls, as in sema4 --- */
button {
  font: inherit; color: var(--text); background: var(--card-hi);
  border: 1px solid var(--line); border-radius: 12px;
  padding: .7rem 1rem; min-height: 2.9rem; cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; }
button.primary { background: #1e4d2b; border-color: var(--green); }
button.amber, a.button-link.amber {
  background: #4a3818; border-color: var(--amber);
}
button.wide { width: 100%; margin-top: .6rem; }
button.big { font-size: 1.1em; padding: .9rem 1.2rem; }
button.danger { color: var(--red); }
/* Same footprint as button.wide.big when the CTA is a link (download page). */
a.button-link {
  display: flex; align-items: center; justify-content: center;
  font: inherit; color: var(--text); text-decoration: none;
  border: 1px solid var(--line); border-radius: 12px;
  padding: .9rem 1.2rem; min-height: 2.9rem; cursor: pointer;
  box-sizing: border-box;
}
a.button-link.wide { width: 100%; margin-top: .6rem; }
a.button-link.big { font-size: 1.1em; }
.row { display: flex; gap: .6rem; margin-top: .6rem; align-items: stretch; }
.row > button, .row > input { flex: 1; }
/* Row actions must not use button.wide's margin-top (misaligned the gear, owner 11/10/2026). */
.row > button.wide { margin-top: 0; width: auto; }
/* No fill/border: a filled square looked lighter than the disabled “max 4” sibling
   on desktop (owner, 11/10/2026). Gear SVG is inlined — WebKitGTK skips sprite <use>. */
.row > .icon-btn {
  flex: none; width: 2.9rem; min-height: 2.9rem; margin-top: 0; padding: 0;
  display: grid; place-items: center;
  background: transparent; border: 0;
}
.row > .icon-btn .icon { width: 1.55rem; height: 1.55rem; color: var(--text); }
.pass-row { display: flex; gap: .5rem; align-items: stretch; margin-top: 0; }
.pass-row input { flex: 1; min-width: 0; }
.pass-row .eye-btn {
  flex: none; width: 2.9rem; padding: 0; display: grid; place-items: center;
}
.pass-row .eye-btn .icon { width: 1.35rem; height: 1.35rem; color: var(--dim); }

input { font: inherit; color: var(--text); background: var(--card-hi); border: 1px solid var(--line); border-radius: 12px; padding: .7rem .9rem; width: 100%; min-height: 2.9rem; }
label { display: block; margin: .8rem 0 .25rem; color: var(--dim); font-size: .9em; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; }
.chips button { padding: .5rem .8rem; min-height: 2.4rem; border-radius: 999px; }
.chips button.sel { border-color: var(--green); background: #1e4d2b; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-top: .4rem; }
.seg button { flex: 1; border: 0; border-radius: 0; background: transparent; padding: .55rem .9rem; min-height: 2.4rem; }
.seg button.sel { background: var(--card-hi); font-weight: 650; }
.hint { color: var(--dim); font-size: .85em; margin-top: .4rem; }

/* --- the switch: big enough for a thumb, position = relay --- */
.sw { flex: none; display: inline-block; cursor: pointer; }
.sw-input { position: absolute; opacity: 0; width: 0; height: 0; }
.sw-track {
  display: block; width: 3.4rem; height: 1.9rem; border-radius: 999px;
  background: #3a4150; border: 1px solid var(--line); position: relative; transition: background .15s;
}
.sw-track::after {
  content: ""; position: absolute; top: .15rem; left: .15rem;
  width: 1.5rem; height: 1.5rem; border-radius: 50%; background: #e8ecf1; transition: transform .15s;
}
.sw-input:checked + .sw-track { background: var(--green); border-color: var(--green); }
.tile.ready .sw-input:checked + .sw-track { background: var(--green-on); border-color: var(--green-on); }
.sw-input:checked + .sw-track::after { transform: translateX(1.5rem); }
.sw-input:disabled + .sw-track { opacity: .35; cursor: default; }
.mode { display: flex; align-items: center; gap: .8rem; }
.mode-name { font-weight: 700; }

/* --- the cards --- */
.tiles {
  display: grid; gap: clamp(.7rem, 1.6vw, 1.1rem);
  grid-template-columns: minmax(0, 1fr);
  /* One plug must not stretch to fill the home column (owner, 30/9/2026). */
  align-content: start;
}
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.tile {
  position: relative; text-align: left; background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-left: 12px solid var(--grey);
  border-radius: var(--radius); padding: clamp(.7rem, 2.6vw, 1rem) clamp(.75rem, 2.8vw, 1.1rem);
  display: flex; flex-direction: column; gap: .3rem;
  align-self: start; height: auto;
}
.tile .head { display: flex; align-items: flex-start; justify-content: space-between; gap: .6rem; }
.tile .ctl { flex: none; display: flex; align-items: center; gap: .5rem; margin: -.15rem -.2rem 0 0; }
.tile .body { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-top: auto; }
.tile .info { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.tile .name { display: block; font-size: 1.35em; font-weight: 650; line-height: 1.15; overflow-wrap: anywhere; }
.tile .watt { font-variant-numeric: tabular-nums; font-size: 1.9em; font-weight: 300; white-space: nowrap; }
.tile .watt small { font-size: .45em; color: var(--dim); font-weight: 400; }
.tile .state { display: flex; align-items: center; gap: .45rem; font-weight: 650; font-size: 1.15em; white-space: nowrap; }
.tile button.state { padding: 0; min-height: 0; border: 0; background: transparent; color: inherit; font: inherit; font-weight: 650; font-size: 1.15em; cursor: pointer; align-self: flex-start; }
.tile .why { color: var(--dim); font-size: .85em; }
.tile .why:empty { display: none; }
.tile .why.bad { color: var(--red); font-weight: 600; }
.tile .connect { align-self: flex-end; }

.tile.running { border-left-color: var(--green); background: linear-gradient(105deg, #17351f, var(--card) 65%); }
.tile.ready { border-left-color: var(--green-on); background: linear-gradient(105deg, #1a2e20, var(--card) 65%); }
.tile.waiting { border-left-color: var(--amber); background: linear-gradient(105deg, #3a2c0c, var(--card) 65%); }
.tile.off { border-left-color: var(--grey); }
.tile.unknown { border-left-color: var(--line); }
.tile.unknown .name, .tile.unknown .watt { opacity: .55; }
.running .state { color: #6ee98a; }
.ready .state { color: #9bc4a3; }
.waiting .state, .tile.waiting button.state { color: #ffc554; }

.dot { width: .85rem; height: .85rem; border-radius: 50%; background: var(--grey); flex: none; }
.running .dot { background: var(--green); }
.ready .dot { background: var(--green-on); }
.waiting .dot { background: var(--amber); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

button.star {
  width: 2.4rem; height: 2.4rem; min-height: 0; padding: 0;
  border: 0; background: transparent; color: var(--dim); font-size: 1.5rem; line-height: 1;
}
button.star.lit { color: var(--amber); text-shadow: 0 0 10px rgba(255, 159, 10, .55); }

/* --- events, cards, wizard --- */
.row { margin-top: 0; }
.events ol { list-style: none; padding-left: 0; margin: 0; }
.events li { padding: .45rem 0; border-bottom: 1px solid var(--line); display: flex; gap: .8rem; font-size: .9em; }
.events li:last-child { border-bottom: 0; }   /* no line under the bottom row (owner, 12/10/2026) */
.events li time { color: var(--dim); white-space: nowrap; font-variant-numeric: tabular-nums; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; margin-top: .8rem; }
.card h2 { margin-top: 0; }
.steps { color: var(--dim); font-size: .85em; margin-top: .8rem; overflow-wrap: anywhere; }
.progress { height: 8px; background: var(--card-hi); border-radius: 4px; overflow: hidden; margin: .6rem 0; }
.progress > div { height: 100%; background: var(--green); width: 0; transition: width .3s; }
.status-line { display: flex; align-items: center; gap: .6rem; margin: .5rem 0; }
.status-line .dot.ok { background: var(--green); }
.status-line .dot.busy { background: var(--amber); animation: pulse 1s ease-in-out infinite; }
.status-line .dot.bad { background: var(--red); }

/* The panel as in sema4: a box at the top of the screen, one setting per line */
.sheet { position: fixed; inset: 0; background: #000a; z-index: 10; display: flex; align-items: flex-start; justify-content: center; padding: 1rem; }
.sheet-box {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  width: min(40rem, 100%); max-height: calc(100vh - 2rem); overflow-y: auto;
  padding: 1rem clamp(.9rem, 2vw, 1.4rem) 1.4rem; box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.sheet-head h2 { margin: 0; color: var(--text); font-size: 1.2em; }
#sheet-close { font-size: 1.4em; line-height: 1; padding: .3rem .7rem; }
.field { display: grid; grid-template-columns: minmax(5.5rem, 8rem) minmax(0, 1fr); gap: .3rem .8rem; align-items: center; margin: 1rem 0; }
.field > label { color: var(--dim); font-size: .9em; margin: 0; }
.field .hint { grid-column: 2; color: var(--dim); font-size: .8em; margin: 0; }
.field .mode input { flex: 1; min-width: 0; }
.tile { cursor: pointer; }
@media (max-width: 480px) { .field { grid-template-columns: 5.5rem minmax(0, 1fr); gap: .3rem .6rem; } }
.pin-row { display: flex; gap: .6rem; margin: 1rem 0; }
.pin-row button { flex: 1; }
.foot { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1.2rem; }
.foot .hint { margin: 0; color: var(--dim); font-size: .8em; overflow-wrap: anywhere; }
.foot .hint b { color: var(--text); font-weight: 700; }

/* In-app help (Settings → Help) */
.help { display: flex; flex-direction: column; gap: .75rem; }
.help > button.wide { margin: 0; }
.help-h { margin: .6rem 0 0; font-size: 1.05em; color: var(--text); }
.help p { margin: 0; color: var(--text); line-height: 1.45; }
.help-ul { margin: 0; padding-left: 1.2rem; color: var(--text); line-height: 1.45; }
.help-ul li { margin: .25rem 0; }
.help-pre {
  margin: 0; padding: .75rem .8rem; overflow-x: auto;
  background: #0c0e12; border: 1px solid var(--line); border-radius: 10px;
  font: 500 .72rem/1.35 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color: #d4e0c8; white-space: pre;
}
.help-fig { margin: .25rem 0; }
.help-fig img {
  display: block; width: 100%; max-height: 14rem; object-fit: contain;
  background: #0c0e12; border: 1px solid var(--line); border-radius: 10px;
}
.help-fig figcaption { margin-top: .35rem; color: var(--dim); font-size: .85em; }
.help-fig.missing .help-fig-miss {
  padding: .9rem; border: 1px dashed var(--line); border-radius: 10px;
  background: #0c0e12; color: var(--dim); font-size: .9em;
}
.help-fig.missing .help-fig-miss .muted { margin-top: .35rem; font-size: .85em; }
.toast { position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%); background: var(--card-hi); border: 1px solid var(--line); color: var(--text); padding: .85rem 1.1rem; border-radius: 12px; z-index: 40; max-width: min(92vw, 28rem); font-size: 1rem; line-height: 1.35; white-space: pre-wrap; word-break: break-word; max-height: 40vh; overflow: auto; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.toast.bad { background: #b91c1c; color: #fff; border-color: #991b1b; }
.field input.num { width: 4.5rem; flex: none; text-align: center; padding: .5rem .4rem; }

/* The appliance drawing on the card (sema4's icons.svg), in the corner the switch left free */
.icons { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.tile .icon { width: 2.9rem; height: 2.9rem; margin-right: -.1rem; color: var(--dim); opacity: .8; }
.running .icon { color: #6ee98a; }
.ready .icon { color: #9bc4a3; }
.waiting .icon { color: #ffc554; }
/* Same grey as input; appearance:none so WebKitGTK does not tint the closed
   control brown (owner, 11/10/2026). Native arrow goes away with that — draw a
   chevron with CSS gradients (data-URI SVG is often invisible in WebKitGTK). */
select {
  font: inherit; color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: .7rem 2.4rem .7rem .9rem; width: 100%; min-height: 2.9rem;
  -webkit-appearance: none; appearance: none;
  background-color: var(--card-hi);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--dim) 50%),
    linear-gradient(135deg, var(--dim) 50%, transparent 50%);
  background-position:
    calc(100% - 1.15rem) calc(50% - 0.12rem),
    calc(100% - 0.75rem) calc(50% - 0.12rem);
  background-size: 0.4rem 0.4rem, 0.4rem 0.4rem;
  background-repeat: no-repeat;
}
select option { background-color: var(--card-hi); color: var(--text); }
.mode.wrap { flex-wrap: wrap; }
.field .mode input.num { flex: none; }
