/* ============================================================================
   RF433 Cloud Panel — modern, minimalist, animated.
   Dark, glassy surfaces; one accent; spring micro-interactions.
   ========================================================================== */
:root {
  --bg:        #07080c;
  --bg-2:      #0c0e15;
  --surface:   rgba(255,255,255,.045);
  --surface-2: rgba(255,255,255,.07);
  --border:    rgba(255,255,255,.09);
  --border-2:  rgba(255,255,255,.14);
  --text:      #f3f5f9;
  --muted:     #8b90a0;
  --faint:     #5a5f6e;
  --accent:    #5b8cff;
  --accent-2:  #8b6cff;
  --on:        #32d74b;
  --on-glow:   rgba(50,215,75,.45);
  --danger:    #ff453a;
  --warn:      #ffd60a;
  --radius:    20px;
  --radius-sm: 14px;
  --ease:      cubic-bezier(.22,.61,.36,1);
  --spring:    cubic-bezier(.34,1.56,.64,1);
  --shadow:    0 18px 50px -12px rgba(0,0,0,.7);
  --sat:       env(safe-area-inset-top);
  --sab:       env(safe-area-inset-bottom);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none;
  overflow-x: hidden;
}
/* ambient glow */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(120% 80% at 80% -10%, rgba(91,140,255,.16), transparent 60%),
    radial-gradient(90% 70% at 0% 0%, rgba(139,108,255,.13), transparent 55%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 40%);
}
button, input, select { font-family: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
::-webkit-scrollbar { width: 0; height: 0; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- login --- */
#login {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: rgba(7,8,12,.6); backdrop-filter: blur(8px);
}
.login-card {
  width: 100%; max-width: 360px; padding: 34px 26px 26px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 26px;
  box-shadow: var(--shadow);
  animation: pop .55s var(--spring) both;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand .logo {
  width: 46px; height: 46px; border-radius: 14px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-size: 24px;
  box-shadow: 0 8px 24px -6px rgba(91,140,255,.6);
}
.brand h1 { font-size: 19px; font-weight: 650; letter-spacing: .2px; }
.brand p  { font-size: 13px; color: var(--muted); }
.field { position: relative; margin-bottom: 14px; }
.field input {
  width: 100%; padding: 15px 16px; font-size: 16px;
  background: rgba(0,0,0,.25); border: 1px solid var(--border-2); border-radius: 14px;
  transition: border-color .2s, box-shadow .2s; outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(91,140,255,.18); }
.btn {
  width: 100%; padding: 15px; font-size: 16px; font-weight: 600; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 10px 26px -8px rgba(91,140,255,.7);
  transition: transform .12s var(--ease), opacity .2s, box-shadow .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; }
.btn.ghost { background: var(--surface-2); color: var(--text); box-shadow: none; border: 1px solid var(--border); }
.btn.danger { background: rgba(255,69,58,.12); color: var(--danger); box-shadow: none; border: 1px solid rgba(255,69,58,.3); }
.btn.sm { padding: 11px 14px; font-size: 14px; }
.login-err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 2px 2px 12px; transition: opacity .2s; }
.shake { animation: shake .4s; }

/* ---------------------------------------------------------------- app ----- */
#app { display: flex; flex-direction: column; min-height: 100%; opacity: 0; }
#app.show { animation: appin .5s var(--ease) both; }

header {
  position: sticky; top: 0; z-index: 30;
  padding: calc(14px + var(--sat)) 18px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: rgba(8,9,14,.72); backdrop-filter: blur(18px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}
.htitle { display: flex; align-items: center; gap: 11px; min-width: 0; }
.htitle .logo {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-size: 18px;
  box-shadow: 0 6px 16px -6px rgba(91,140,255,.7);
}
.htitle .meta { min-width: 0; }
.htitle .meta b { font-size: 16px; font-weight: 650; display: block; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.htitle .meta span { font-size: 12px; color: var(--muted); }
.hright { display: flex; align-items: center; gap: 14px; flex: 0 0 auto; }
.hclock { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--muted); }

/* connection pill */
.conn { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted);
  padding: 6px 11px 6px 9px; border-radius: 100px; background: var(--surface); border: 1px solid var(--border);
  transition: color .3s, border-color .3s; }
.conn .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); position: relative; transition: background .3s; }
.conn.online { color: var(--on); border-color: rgba(50,215,75,.25); }
.conn.online .dot { background: var(--on); }
.conn.online .dot::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%;
  border: 2px solid var(--on); animation: ping 1.8s var(--ease) infinite; }
.conn.offline { color: var(--danger); border-color: rgba(255,69,58,.22); }
.conn.offline .dot { background: var(--danger); }

main { flex: 1; padding: 16px 16px 120px; max-width: 720px; width: 100%; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.view.active > * { animation: rise .5s var(--ease) both; }
.view.active > *:nth-child(2) { animation-delay: .04s; }
.view.active > *:nth-child(3) { animation-delay: .08s; }
.view.active > *:nth-child(4) { animation-delay: .12s; }
.view.active > *:nth-child(5) { animation-delay: .16s; }

.seclbl { font-size: 12px; color: var(--faint); text-transform: uppercase; letter-spacing: .6px;
  font-weight: 600; padding: 20px 6px 9px; }
.hint { font-size: 13px; color: var(--muted); padding: 8px 6px 4px; line-height: 1.5; }
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 13px 15px; border-radius: var(--radius-sm);
  font-size: 13.5px; line-height: 1.45; margin-bottom: 14px; }
.banner.warn { background: rgba(255,214,10,.09); color: #f0d678; border: 1px solid rgba(255,214,10,.2); }
.banner.off  { background: rgba(255,69,58,.09); color: #ff8c84; border: 1px solid rgba(255,69,58,.22); }
.banner .bi { font-size: 16px; line-height: 1.2; }

/* ---- cards / rows ---- */
.group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; backdrop-filter: blur(8px); }
.group + .group { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 14px; padding: 15px 17px; position: relative;
  border-bottom: 1px solid var(--border); transition: background .15s; }
.row:last-child { border-bottom: 0; }
.row.tap { cursor: pointer; }
.row.tap:active { background: var(--surface-2); }
.row .txt { flex: 1; min-width: 0; }
.row .nm  { font-size: 16.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 13px; color: var(--muted); margin-top: 2px; transition: color .3s; }
.row .sub.on { color: var(--on); }
.row .ico { width: 38px; height: 38px; flex: 0 0 auto; border-radius: 11px; display: grid; place-items: center;
  font-size: 19px; background: var(--surface-2); transition: background .3s, box-shadow .3s, color .3s; }
.row .ico.lit { background: rgba(50,215,75,.16); color: var(--on); box-shadow: 0 0 0 1px rgba(50,215,75,.3), 0 0 22px -4px var(--on-glow); }
.chev { color: var(--faint); font-size: 17px; flex: 0 0 auto; }

/* ---- the toggle ---- */
.tgl { position: relative; width: 52px; height: 32px; border-radius: 100px; flex: 0 0 auto;
  background: rgba(255,255,255,.14); transition: background .35s var(--ease); }
.tgl::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.45);
  transition: transform .4s var(--spring), width .2s var(--ease); }
.tgl.on { background: linear-gradient(135deg, var(--on), #28b33e); box-shadow: 0 0 22px -4px var(--on-glow); }
.tgl.on::after { transform: translateX(20px); }
.tgl:active::after { width: 30px; }
.tgl.wait { opacity: .5; pointer-events: none; }

.press { padding: 10px 18px; font-size: 14.5px; font-weight: 600; border-radius: 12px; flex: 0 0 auto;
  background: var(--surface-2); border: 1px solid var(--border-2); color: var(--text);
  transition: transform .12s var(--ease), background .2s; }
.press:active { transform: scale(.93); background: var(--accent); border-color: var(--accent); }

.add-btn { width: 100%; margin-top: 16px; padding: 15px; border-radius: var(--radius-sm); font-size: 15.5px; font-weight: 600;
  background: var(--surface); border: 1px dashed var(--border-2); color: var(--accent);
  transition: transform .12s var(--ease), background .2s, border-color .2s; }
.add-btn:active { transform: scale(.985); background: var(--surface-2); }

/* offline = last-known state; dim it and block toggles so it reads as unverified */
.stale { opacity: .5; transition: opacity .3s; }
.stale .tgl, .stale .press { pointer-events: none; }
.empty { text-align: center; color: var(--muted); padding: 46px 22px; }
.empty .big { font-size: 40px; margin-bottom: 12px; opacity: .7; }

/* ---- forms ---- */
.frow { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 17px; min-height: 54px; border-bottom: 1px solid var(--border); }
.frow:last-child { border-bottom: 0; }
.frow label { font-size: 15.5px; }
.frow .val { color: var(--muted); font-size: 14.5px; font-variant-numeric: tabular-nums; }
.frow input[type=text], .frow input[type=password], .frow input[type=number], .frow input[type=time], .frow select {
  background: transparent; border: 0; text-align: right; font-size: 15.5px; color: var(--accent);
  outline: none; -webkit-appearance: none; max-width: 60%; }
.frow input.l { text-align: left; color: var(--text); }
.frow select { text-align-last: right; }
.frow .unit { color: var(--faint); font-size: 13px; margin-left: 3px; }
option { background: #16181f; color: var(--text); }

/* day chips */
.days { display: flex; justify-content: space-between; gap: 6px; padding: 15px 14px; }
.day { flex: 1; height: 40px; border-radius: 12px; background: var(--surface-2); color: var(--muted);
  font-size: 13px; font-weight: 600; display: grid; place-items: center;
  transition: background .18s var(--ease), color .18s, transform .12s; }
.day.on { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.day:active { transform: scale(.9); }

.log { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11.5px; line-height: 1.7;
  color: var(--muted); padding: 14px 16px; max-height: 260px; overflow-y: auto; word-break: break-word; }
.log .t { color: var(--accent); }

/* ---- bottom tab bar ---- */
nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 8px 12px calc(8px + var(--sab)); display: flex; gap: 6px; justify-content: center;
  background: rgba(8,9,14,.78); backdrop-filter: blur(18px) saturate(1.4); border-top: 1px solid var(--border); }
.tab { flex: 1; max-width: 150px; padding: 7px 4px 6px; border-radius: 14px; text-align: center; color: var(--muted);
  transition: color .2s, background .2s; }
.tab .ic { font-size: 21px; display: block; line-height: 24px; }
.tab .lb { font-size: 10.5px; font-weight: 600; margin-top: 1px; }
.tab.active { color: var(--accent); background: var(--surface); }

/* ---- sheet / modal ---- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
  opacity: 0; visibility: hidden; transition: opacity .3s var(--ease), visibility .3s; }
.overlay.show { opacity: 1; visibility: visible; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; max-height: 90%; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--border); border-bottom: 0; border-radius: 28px 28px 0 0;
  padding: 10px 18px calc(28px + var(--sab)); margin: 0 auto; max-width: 560px;
  transform: translateY(110%); transition: transform .42s var(--spring); }
.sheet.show { transform: translateY(0); }
.handle { width: 40px; height: 5px; border-radius: 3px; background: var(--border-2); margin: 6px auto 16px; }
.sheet h2 { font-size: 19px; font-weight: 650; text-align: center; margin-bottom: 16px; }
.sheet .group { background: var(--surface-2); }
.step { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px; font-size: 14px; line-height: 1.6; margin-bottom: 12px; color: var(--text); }
.step b { color: var(--accent); }
.sheet .btn, .sheet .add-btn { margin-top: 12px; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; bottom: calc(86px + var(--sab)); transform: translateX(-50%) translateY(20px);
  z-index: 80; background: rgba(20,22,30,.95); border: 1px solid var(--border-2); color: var(--text);
  padding: 12px 20px; border-radius: 100px; font-size: 14px; font-weight: 500; box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transition: opacity .25s, transform .35s var(--spring), visibility .25s;
  display: flex; align-items: center; gap: 8px; max-width: 88%; }
.toast.show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: rgba(255,69,58,.5); }
.toast.ok .ti { color: var(--on); }

/* ---- property plan (primary view) ---- */
.planbox { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; backdrop-filter: blur(8px); }
/* The scheme is big and comfortable: it fills the screen height and pans
   horizontally when wider than the viewport (true on phones). */
#planwrap { position: relative; display: flex; align-items: center;
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
#planwrap.stale { opacity: .5; transition: opacity .3s; }
#planwrap.stale .sw { pointer-events: none; }
#plan { flex: 0 0 auto; margin: auto; display: block; width: auto;
  height: 64vh;                          /* fallback for browsers without dvh */
  height: clamp(360px, 64dvh, 780px);    /* large, easy-to-use scheme */
  touch-action: pan-x;                   /* swipe to pan the scheme sideways */
  -webkit-user-select: none; user-select: none; }
.sw { cursor: pointer; touch-action: none; }   /* circles stay solid tap / hold targets */
/* Move mode shows the whole plan (fit to width) so a circle can be placed precisely. */
#planwrap.moving { overflow: hidden; }
#planwrap.moving #plan { width: 100%; height: auto; margin: 0; touch-action: none; }
#planbar { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-top: 1px solid var(--border); }
#planhint { flex: 1; font-size: 12.5px; color: var(--muted); line-height: 1.35; }
#movebar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 14px; font-size: 13.5px; line-height: 1.3; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
#movebar .mb { flex: 0 0 auto; background: #fff; color: var(--accent); border-radius: 9px;
  padding: 7px 16px; font-size: 14px; font-weight: 600; }

/* skeleton */
.skel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.skline { height: 56px; border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.05), transparent);
  background-size: 200% 100%; animation: sweep 1.3s infinite; }
.skline:last-child { border-bottom: 0; }

/* ---- keyframes ---- */
@keyframes pop   { from { opacity: 0; transform: scale(.92) translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes appin { from { opacity: 0; transform: scale(1.01); } to { opacity: 1; transform: none; } }
@keyframes rise  { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes ping  { 0% { transform: scale(1); opacity: .7; } 80%,100% { transform: scale(2.1); opacity: 0; } }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%,60%{transform:translateX(-7px)} 40%,80%{transform:translateX(7px)} }
@keyframes sweep { from { background-position: 200% 0; } to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .05ms !important; }
}

/* ---- scheme sizing on small / large screens ---- */
/* Phones: let the scheme go edge-to-edge so it's as big as possible. */
@media (max-width: 640px) {
  #view-switches .planbox {
    margin-left: -16px; margin-right: -16px;
    border-left: 0; border-right: 0; border-radius: 0;
  }
}
/* Large screens: give the scheme a roomier column (other tabs stay narrow). */
@media (min-width: 820px) {
  main:has(#view-switches.active) { max-width: 1100px; }
}
