/* qabess - a utility-meter look: warm paper, ink, one amber "live power" accent. */
:root {
  --paper: #f4f1ea;
  --card: #fffdf8;
  --sunk: #ebe6dc;
  --ink: #1c1a16;
  --ink-2: #5d5850;
  --ink-3: #8f887c;
  --line: #ddd6c8;
  --live: #d9861c;
  --live-soft: #f6e3c4;
  --on: #23885b;
  --on-soft: #d5ecdf;
  --warn: #b8432a;
  --warn-soft: #f3d9d1;
  --radius-l: 22px;
  --radius-m: 14px;
  --radius-s: 10px;
  --shadow: 0 1px 0 rgba(28, 26, 22, .04), 0 8px 24px -12px rgba(28, 26, 22, .18);
  --tabs-h: 64px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14130f;
    --card: #1e1c17;
    --sunk: #282520;
    --ink: #f1ece2;
    --ink-2: #b8b0a2;
    --ink-3: #7f786c;
    --line: #34302a;
    --live: #f0a540;
    --live-soft: #3a2c16;
    --on: #4cc38a;
    --on-soft: #183326;
    --warn: #ef7a5c;
    --warn-soft: #3b1f17;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

html[data-telegram="true"] body { padding-bottom: 12px; }
html[data-telegram="true"] .tabs { display: none; }
html[data-telegram="true"] .top { min-height: 48px; }
html[data-telegram="true"] #view { max-width: 680px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body {
  font: 16px/1.45 system-ui, -apple-system, "SF Arabic", "Segoe UI", Tahoma, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  max-width: 560px;
  margin: 0 auto;
}
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
button { font: inherit; color: inherit; }
svg { fill: currentColor; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.update-banner { margin: 4px 12px 8px; padding: 10px 12px; border-radius: 12px; background: var(--live); color: #fff; text-align: center; }
.update-banner button { border: 0; background: transparent; color: inherit; font: inherit; font-weight: 700; cursor: pointer; margin-inline-start: 8px; }
.top h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.icon-btn { border: 0; background: transparent; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; color: var(--ink-2); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { background: var(--sunk); }

main { padding: 0 16px; }

/* strip chooser */
.strips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: none; }
.strips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 8px 14px; cursor: pointer; display: inline-flex; gap: 8px; align-items: center; font-size: 15px;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.dot.ok { background: var(--on); box-shadow: 0 0 0 3px var(--on-soft); }

/* live meter */
.meter {
  background: var(--card); border-radius: var(--radius-l); padding: 18px 18px 14px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.meter::after {               /* faint dial ticks: the "meter" texture */
  content: ""; position: absolute; top: -96px; left: -86px; width: 230px; height: 230px; border-radius: 50%;
  background: repeating-conic-gradient(from 200deg, var(--line) 0 1deg, transparent 1deg 9deg);
  mask: radial-gradient(circle, transparent 62%, #000 63%, #000 70%, transparent 71%);
  -webkit-mask: radial-gradient(circle, transparent 62%, #000 63%, #000 70%, transparent 71%);
  opacity: .5; pointer-events: none;
}
.meter-head { display: flex; justify-content: space-between; align-items: center; color: var(--ink-2); font-size: 14px; }
.meter-head .state { display: inline-flex; gap: 6px; align-items: center; }
.live { display: flex; align-items: baseline; gap: 8px; margin: 6px 0 2px; }
.live .w { font-size: 56px; font-weight: 700; letter-spacing: -.03em; line-height: 1; color: var(--ink); }
.live .unit { font-size: 18px; color: var(--live); font-weight: 600; }
.live.offline .w { color: var(--ink-3); }
.readings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; position: relative; z-index: 1; }
.reading { background: var(--sunk); border-radius: var(--radius-s); padding: 8px 6px; text-align: center; }
.reading b { display: block; font-size: 16px; }
.reading small { color: var(--ink-3); font-size: 12px; }
.money { display: flex; gap: 6px; margin-top: 8px; position: relative; z-index: 1; }
.money div { flex: 1; border: 1px dashed var(--line); border-radius: var(--radius-s); padding: 8px 10px; }
.money small { color: var(--ink-3); font-size: 12px; display: block; }
.money b { font-size: 17px; }

/* outlets */
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 22px 2px 10px; }
.section-title h2 { font-size: 17px; margin: 0; }
.all-btns { display: flex; gap: 6px; }
.pill {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px;
  font-size: 14px; cursor: pointer;
}
.pill:active { transform: scale(.97); }
.outlets { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.outlet {
  position: relative; text-align: start; border: 1px solid var(--line); background: var(--card);
  border-radius: var(--radius-m); padding: 14px 14px 12px; min-height: 132px; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
  transition: transform .15s var(--ease), background-color .25s var(--ease), border-color .25s var(--ease);
}
.outlet:active { transform: scale(.97); }
.outlet.on { background: var(--on-soft); border-color: transparent; }
.outlet.busy { opacity: .6; pointer-events: none; }
.outlet .ico { font-size: 26px; line-height: 1; }
.outlet .name { font-weight: 600; font-size: 16px; margin-top: 6px; }
.outlet .sub { color: var(--ink-2); font-size: 13px; display: flex; gap: 8px; flex-wrap: wrap; }
.outlet .w-now { color: var(--live); font-weight: 600; }
.outlet .badge { position: absolute; inset-block-start: 10px; inset-inline-end: 10px; display: flex; gap: 6px; align-items: center; }
.switch {
  width: 42px; height: 26px; border-radius: 999px; background: var(--line); position: relative;
  transition: background-color .2s var(--ease); flex: none;
}
.switch::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s var(--ease);
}
.on .switch, .switch.on { background: var(--on); }
.on .switch::after, .switch.on::after { transform: translateX(-16px); }
.lock { font-size: 13px; }
.more {
  border: 0; background: transparent; color: var(--ink-3); width: 32px; height: 32px; border-radius: 50%;
  position: absolute; inset-block-end: 6px; inset-inline-end: 6px; cursor: pointer; font-size: 20px; line-height: 1;
}
.more:active { background: var(--sunk); }
.timer-tag { font-size: 12px; background: var(--live-soft); color: var(--ink); border-radius: 999px; padding: 1px 8px; width: fit-content; }

.empty {
  background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius-l); padding: 26px 18px; text-align: center; color: var(--ink-2);
}
.empty code { direction: ltr; display: block; margin-top: 10px; font-size: 13px; background: var(--sunk); padding: 8px; border-radius: 8px; overflow-x: auto; }

/* lists (schedules, log) */
.list { background: var(--card); border-radius: var(--radius-m); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-size: 22px; font-weight: 700; min-width: 64px; }
.row .what { font-weight: 600; }
.row .when { color: var(--ink-3); font-size: 13px; }
.row .del { border: 0; background: transparent; color: var(--ink-3); font-size: 18px; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; }
.row.disabled .t, .row.disabled .what { color: var(--ink-3); }
.ev-ico { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--sunk); flex: none; font-size: 16px; }
.ev-ico.alert { background: var(--warn-soft); }
.ev-ico.ok { background: var(--on-soft); }
.day-head { font-size: 13px; color: var(--ink-3); margin: 16px 4px 6px; }

.primary {
  border: 0; background: var(--ink); color: var(--paper); border-radius: var(--radius-m); padding: 14px 18px;
  font-weight: 600; width: 100%; cursor: pointer; font-size: 16px;
}
.primary:active { transform: scale(.98); }
.ghost { border: 1px solid var(--line); background: transparent; border-radius: var(--radius-m); padding: 12px 16px; cursor: pointer; width: 100%; }
.danger { color: var(--warn); }

/* energy */
.seg { display: inline-flex; background: var(--sunk); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--card); box-shadow: var(--shadow); font-weight: 600; }
.chart { background: var(--card); border-radius: var(--radius-l); padding: 16px 14px 10px; box-shadow: var(--shadow); }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .bar { fill: var(--live); }
.chart .bar.today { fill: var(--ink); }
.chart .axis { fill: var(--ink-3); font-size: 10px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .cap { display: flex; justify-content: space-between; color: var(--ink-2); font-size: 14px; margin-bottom: 8px; }
.split { display: flex; flex-direction: column; gap: 10px; }
.split .item { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; }
.split .track { grid-column: 2 / 4; height: 8px; background: var(--sunk); border-radius: 999px; overflow: hidden; }
.split .fill { height: 100%; background: var(--live); border-radius: 999px; width: 0; transition: width .5s var(--ease); }
.budget .track { height: 10px; background: var(--sunk); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.budget .fill { height: 100%; background: var(--on); width: 0; transition: width .5s var(--ease); }
.budget .fill.hot { background: var(--warn); }

/* bottom tabs */
.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 5;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; max-width: 560px; margin: 0 auto;
  background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  border: 0; background: transparent; height: var(--tabs-h); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; color: var(--ink-3); font-size: 12px; cursor: pointer;
}
.tabs svg { width: 22px; height: 22px; }
.tabs button.active { color: var(--ink); font-weight: 600; }
.tabs button.active svg { color: var(--live); }

/* sheet */
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 88vh;
  border-radius: 24px 24px 0 0; background: var(--card); color: var(--ink); box-shadow: 0 -10px 40px rgba(0, 0, 0, .25);
}
.sheet::backdrop { background: rgba(20, 18, 14, .45); }
.sheet[open] { animation: rise .28s var(--ease); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet form { padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.grab { width: 40px; height: 5px; border-radius: 999px; background: var(--line); margin: 0 auto 4px; }
.sheet h3 { margin: 0; font-size: 19px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--ink-2); }
.field input, .field select {
  font: inherit; color: inherit; background: var(--sunk); border: 1px solid transparent; border-radius: var(--radius-s);
  padding: 12px; width: 100%;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--live); }
.icons { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.icons button { border: 1px solid var(--line); background: transparent; border-radius: var(--radius-s); font-size: 24px; padding: 8px 0; cursor: pointer; }
.icons button[aria-pressed="true"] { border-color: var(--live); background: var(--live-soft); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; cursor: pointer; }
.toggle-row small { display: block; color: var(--ink-3); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 7px 12px; cursor: pointer; font-size: 14px; }
.chips button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.hint { color: var(--ink-3); font-size: 13px; margin: 0; }

.toast {
  position: fixed; inset-inline: 16px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px); z-index: 10;
  max-width: 528px; margin: 0 auto; background: var(--ink); color: var(--paper); padding: 12px 16px; border-radius: var(--radius-m);
  box-shadow: var(--shadow); animation: rise .25s var(--ease);
}
.toast.bad { background: var(--warn); color: #fff; }
.toast[popover] { top: auto; height: auto; width: auto; border: 0; overflow: visible; }

.login { margin-top: 12vh; display: flex; flex-direction: column; gap: 14px; }
.login h2 { margin: 0; font-size: 26px; }

:focus-visible { outline: 2px solid var(--live); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* add-strip wizard */
.chip.add { border-style: dashed; color: var(--ink-2); }
.strip-art {
  position: relative; height: 64px; border-radius: 16px; background: var(--sunk); border: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 0 18px; direction: ltr;
}
.strip-art .sock { width: 30px; height: 30px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); box-shadow: inset 0 0 0 7px var(--sunk); }
.strip-art .led { margin-inline-start: auto; width: 12px; height: 12px; border-radius: 50%; background: var(--live); animation: blink3 3s infinite; }
@keyframes blink3 { 0%, 12% { opacity: 1; box-shadow: 0 0 0 6px var(--live-soft); } 20%, 100% { opacity: .15; box-shadow: none; } }
.steps-guide { margin: 0; padding-inline-start: 22px; display: flex; flex-direction: column; gap: 8px; }
.field.suffix { flex-direction: row; align-items: center; gap: 0; direction: ltr; background: var(--sunk); border-radius: var(--radius-s); padding-inline-start: 12px; }
.field.suffix span { color: var(--ink-2); font-size: 16px; }
.field.suffix input { background: transparent; text-transform: uppercase; letter-spacing: .08em; padding-inline-start: 2px; }
.cmd { display: block; direction: ltr; font-size: 12px; background: var(--sunk); padding: 10px; border-radius: 8px; overflow-x: auto; white-space: nowrap; }
.progress { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.progress li { display: flex; align-items: center; gap: 12px; color: var(--ink-3); }
.progress li.done { color: var(--ink); }
.progress li.now { color: var(--ink); font-weight: 600; }
.progress .mark { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 13px; flex: none; }
.progress li.done .mark { background: var(--on); border-color: var(--on); color: #fff; }
.progress li.now .mark { border-color: var(--live); border-top-color: transparent; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.row.pick { width: 100%; border: 0; background: transparent; text-align: start; cursor: pointer; font: inherit; color: inherit; }
.row.pick .what, .row.pick .when { display: block; }
.row.pick:active { background: var(--sunk); }
.row.pick:disabled { opacity: .5; cursor: default; }

.readings.in-sheet { grid-template-columns: repeat(auto-fit, minmax(68px, 1fr)); margin: 0 0 14px; }
.guard-trip { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius-s); padding: 8px 10px; margin: 8px 0 4px; font-size: 14px; position: relative; z-index: 1; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* home dashboard: rooms of tiles; a tile is an outlet card for any entity */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile {
  position: relative; text-align: start; border: 1px solid var(--line); background: var(--card);
  border-radius: var(--radius-m); padding: 14px 14px 12px; min-height: 120px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
  transition: transform .15s var(--ease), background-color .25s var(--ease), border-color .25s var(--ease), box-shadow .25s var(--ease);
}
.tile:active { transform: scale(.97); }
.tile:focus-visible { outline: 2px solid var(--live); outline-offset: 2px; }
.tile.on { background: var(--on-soft); border-color: transparent; }
.tile.on[data-glow] { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--glow) 55%, transparent), 0 8px 24px -10px var(--glow); }
.tile.busy { opacity: .6; pointer-events: none; }
.tile.offline { opacity: .55; }
.tile .ico { font-size: 26px; line-height: 1; }
.tile .name { font-weight: 600; font-size: 16px; margin-top: 6px; }
.tile .dev { color: var(--ink-3); font-size: 12px; }
.tile .sub { color: var(--ink-2); font-size: 13px; display: flex; gap: 8px; flex-wrap: wrap; }
.tile .w-now { color: var(--live); font-weight: 600; }
.tile .badge { position: absolute; inset-block-start: 10px; inset-inline-end: 10px; display: flex; gap: 6px; align-items: center; }
.tile .more { position: absolute; inset-block-end: 6px; inset-inline-end: 6px; }
.tile.sensor { cursor: default; background: var(--sunk); border-color: transparent; }
.tile.sensor .val { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.tile.sensor .val small { font-size: 14px; color: var(--live); margin-inline-start: 4px; font-weight: 600; }
.room + .room { margin-top: 4px; }
.room-meta { color: var(--ink-3); font-size: 13px; display: inline-flex; gap: 8px; align-items: center; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatches button { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); background: var(--c); cursor: pointer; }
.swatches button[aria-pressed="true"] { border-color: var(--ink); transform: scale(1.1); }
input[type="range"] { width: 100%; accent-color: var(--live); }
.kiosk-bar { display: flex; justify-content: center; margin: 24px 0 8px; }

/* wall tablet: no tab bar, bigger tiles, a clock */
body.kiosk { max-width: none; padding-bottom: 24px; }
body.kiosk .tabs { display: none; }
body.kiosk .tiles { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
body.kiosk .tile { min-height: 150px; padding: 18px; }
body.kiosk .tile .ico { font-size: 34px; }
body.kiosk .tile .name { font-size: 19px; }
body.kiosk main { padding: 0 24px; }
.kiosk-clock { display: flex; align-items: baseline; gap: 14px; margin: 4px 2px 14px; flex-wrap: wrap; }
.kiosk-clock b { font-size: 52px; letter-spacing: -.03em; line-height: 1; }
.kiosk-clock span { color: var(--ink-2); font-size: 18px; }
@media (prefers-reduced-motion: reduce) { .tile, .tile:active { transition: none; transform: none; } }
