:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --blue: #2563eb;
  --blue-soft: #e8efff;
  --green: #16a34a;
  --red: #dc2626;
  --radius: 20px;
  --shadow: 0 12px 32px rgba(15, 23, 42, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #131c2e;
    --text: #e6edf7;
    --muted: #93a2b8;
    --line: #223047;
    --blue-soft: #16233d;
    --shadow: 0 12px 32px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
  overflow-x: hidden;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

.app {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 16px calc(28px + env(safe-area-inset-bottom));
}

/* ---------- topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 34px; height: 34px; border-radius: 10px; }
.brand__name { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand__city { color: var(--muted); font-size: 13px; margin-top: -2px; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--blue);
  font-size: 22px;
  line-height: 1;
}

/* ---------- generic ---------- */

.content { animation: rise .32s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

h1 { font-size: 26px; line-height: 1.15; letter-spacing: -.02em; margin: 0 0 8px; }
h2 { font-size: 16px; margin: 0; letter-spacing: -.01em; }
p { margin: 0; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 14px;
  box-shadow: var(--shadow);
}

.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card__head .muted { font-size: 13px; }

.refresh {
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  padding: 6px;
  border-radius: 8px;
}
.refresh:active { background: var(--blue-soft); }

/* ---------- onboarding ---------- */

.hero { text-align: center; padding: 22px 8px 18px; }
.hero__icon {
  width: 92px; height: 92px;
  margin: 0 auto 18px;
  border-radius: 28px;
  background: var(--blue-soft);
  display: grid; place-items: center;
  color: var(--blue);
}
.hero__icon svg { width: 48px; height: 48px; }
.hero p { color: var(--muted); max-width: 340px; margin: 0 auto; }

.search {
  display: flex; align-items: center; gap: 10px;
  background: var(--card);
  border: 1.5px solid transparent;
  border-radius: 16px;
  padding: 0 14px;
  height: 54px;
  box-shadow: var(--shadow);
  transition: border-color .15s ease;
}
.search:focus-within { border-color: var(--blue); }
.search svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.search input {
  flex: 1; min-width: 0;
  border: 0; outline: 0; background: none;
  height: 100%;
  font-size: 16px;
}
.search input::placeholder { color: var(--muted); }

.results { margin-top: 12px; display: grid; gap: 8px; }
.result {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card);
  border-radius: 14px;
  padding: 14px 16px;
  text-align: left;
  box-shadow: 0 4px 14px rgba(15, 23, 42, .05);
  animation: rise .2s ease both;
}
.result:active { transform: scale(.99); }
.result__addr { display: block; font-weight: 600; font-size: 15px; }
.result__meta { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.result__plus {
  width: 32px; height: 32px; flex: none;
  border-radius: 10px;
  display: grid; place-items: center;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 20px;
}
.result--added { opacity: .55; }
.result--added .result__plus { background: var(--line); color: var(--muted); }

.state-note { text-align: center; color: var(--muted); font-size: 14px; padding: 18px 8px; }

/* ---------- chips ---------- */

.chips {
  display: flex; gap: 8px;
  overflow-x: auto;
  padding: 2px 0 4px;
  margin: 0 -16px 4px;
  padding-left: 16px; padding-right: 16px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(15, 23, 42, .05);
  border: 1.5px solid transparent;
}
.chip--active { background: var(--blue); color: #fff; }
.chip--add { color: var(--blue); font-size: 18px; padding: 6px 14px; }

/* ---------- status ---------- */

.status {
  position: relative;
  border-radius: 26px;
  padding: 22px 20px 20px;
  color: #fff;
  margin-top: 10px;
  overflow: hidden;
  box-shadow: 0 18px 38px rgba(15, 23, 42, .18);
}
.status::after {
  content: "";
  position: absolute;
  width: 220px; height: 220px;
  right: -70px; top: -90px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
}
.status--off { background: linear-gradient(155deg, #f05252 0%, #b91c1c 100%); }
.status--on { background: linear-gradient(155deg, #34d399 0%, #15803d 100%); }
.status--unknown { background: linear-gradient(155deg, #7c8aa0 0%, #334155 100%); }

.status__badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, .18);
  border: 1px solid rgba(255, 255, 255, .28);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 12px;
}

.status__row { display: flex; align-items: center; gap: 10px; position: relative; z-index: 1; }
.status__title { font-size: 32px; font-weight: 800; letter-spacing: -.03em; }
.status__sub { opacity: .82; font-size: 14px; margin-top: 2px; }
.status__meta {
  display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 12.5px; opacity: .78;
  margin-top: 14px;
}
.status__actions {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
  margin-top: 18px; position: relative; z-index: 1;
}
.btn {
  height: 50px;
  border-radius: 14px;
  font-size: 14.5px;
  font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  transition: transform .12s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; }
.btn--primary { background: #fff; color: #111827; }
.status--off .btn--primary { color: #b91c1c; }
.status--on .btn--primary { color: #15803d; }
.btn--ghost {
  background: rgba(255, 255, 255, .14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .32);
}

.status__pulse {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 0 rgba(255, 255, 255, .7);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,255,255,.55); }
  70% { box-shadow: 0 0 0 12px rgba(255,255,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}

/* ---------- history ---------- */

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.history li {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.history li:last-child { border-bottom: 0; }
.history__when { font-weight: 600; }
.history__duration { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ---------- subscriptions ---------- */

.subs { list-style: none; margin: 0; padding: 0; }
.subs li {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.subs li:last-child { border-bottom: 0; }
.subs__dot { width: 9px; height: 9px; border-radius: 50%; background: #94a3b8; flex: none; }
.subs__dot--on { background: var(--green); }
.subs__dot--off { background: var(--red); }
.subs__addr { flex: 1; font-size: 14px; font-weight: 500; }
.subs__remove {
  color: var(--muted);
  width: 34px; height: 34px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 18px;
}
.subs__remove:active { background: var(--blue-soft); }

/* ---------- auth / error ---------- */

.center {
  min-height: 78vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 10px;
  padding: 24px 8px;
}
.center img { width: 64px; height: 64px; border-radius: 18px; margin-bottom: 6px; }
.center p { color: var(--muted); max-width: 320px; }
.center .btn { margin-top: 14px; width: 100%; max-width: 280px; height: 48px; }
.center .btn--solid { background: var(--blue); color: #fff; }

/* ---------- skeleton ---------- */

.skeleton { padding: 18px 0; }
.sk {
  border-radius: 16px;
  background: linear-gradient(90deg, var(--line) 25%, color-mix(in srgb, var(--line) 50%, var(--card)) 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}
.sk--status { height: 218px; border-radius: 26px; }
.sk--line { height: 14px; margin-top: 12px; }
.sk--short { width: 55%; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- footer, toast, modal ---------- */

.footer {
  margin-top: 22px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.55;
  text-align: center;
  padding: 0 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: #111827;
  color: #fff;
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 13.5px;
  max-width: calc(100vw - 40px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 50;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
}
.toast--show { opacity: 1; transform: translate(-50%, 0); }

.modal {
  position: fixed; inset: 0;
  background: rgba(2, 6, 23, .55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 60;
  padding: 16px;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal__card {
  width: 100%; max-width: 420px;
  background: var(--card);
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 -10px 40px rgba(0,0,0,.25);
  animation: rise .2s ease;
}
.modal__card h3 { margin: 0 0 6px; font-size: 17px; }
.modal__card p { color: var(--muted); font-size: 14px; }
.modal__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.modal__actions .btn { height: 46px; }
.btn--danger { background: var(--red); color: #fff; }
.btn--plain { background: var(--blue-soft); color: var(--text); }

.demo-pill {
  position: fixed;
  top: 8px; left: 50%; transform: translateX(-50%);
  z-index: 40;
  background: #f59e0b;
  color: #111827;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 8px;
}

@media (max-width: 360px) {
  h1 { font-size: 23px; }
  .status__title { font-size: 28px; }
  .status__actions { grid-template-columns: 1fr; }
}
