:root {
  --bg: #ffffff;
  --text: #1c1c1e;
  --hint: #8e8e93;
  --link: #2481cc;
  --button: #2481cc;
  --button-text: #ffffff;
  --secondary-bg: #f2f2f7;
  --border: rgba(0, 0, 0, 0.08);
  --success: #34c759;
  --danger: #ff3b30;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f10;
    --text: #ffffff;
    --hint: #98989e;
    --link: #64b5ef;
    --button: #2481cc;
    --button-text: #ffffff;
    --secondary-bg: #1c1c1e;
    --border: rgba(255, 255, 255, 0.08);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#app { padding: 16px; max-width: 560px; margin: 0 auto; }

.center { text-align: center; }
.muted { color: var(--hint); }
.small { font-size: 12px; }
.mt { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }

.card {
  background: var(--secondary-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
}

.icon { font-size: 40px; margin-bottom: 8px; }

.label { font-size: 12px; color: var(--hint); text-transform: uppercase; letter-spacing: .03em; }
.value { font-size: 16px; font-weight: 600; margin-top: 2px; }
.value.big { font-size: 18px; }

.pill {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: monospace;
  margin-top: 8px;
}

.status {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.status.on { background: rgba(52, 199, 89, .15); color: var(--success); }
.status.off { background: rgba(255, 59, 48, .15); color: var(--danger); }

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-top: 6px;
}
.bar-fill { height: 100%; background: var(--link); border-radius: 999px; }

.qr { width: 200px; height: 200px; border-radius: 12px; background: #fff; padding: 8px; }

.btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: var(--button);
  color: var(--button-text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn.secondary { background: var(--border); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 8px; font-size: 13px; width: auto; }

input, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  margin-top: 6px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.list-item:last-child { border-bottom: none; }

.searchbar {
  position: sticky;
  top: var(--top-inset);
  background: var(--bg);
  padding: 4px 0 10px;
  z-index: 5;
}

.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tab {
  flex: 1;
  text-align: center;
  padding: 8px;
  border-radius: 10px;
  background: var(--secondary-bg);
  font-size: 13px;
  cursor: pointer;
}
.tab.active { background: var(--button); color: var(--button-text); }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end;
  z-index: 50;
}
.modal {
  background: var(--bg);
  width: 100%;
  border-radius: 16px 16px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 85vh;
  overflow-y: auto;
}
.field { margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--hint); }

/* status dot */
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--hint);
  opacity: .5;
  margin-right: 8px;
}
.dot.on { background: var(--success); opacity: 1; }

/* modal animation + header */
.modal-backdrop { opacity: 0; transition: opacity .25s ease; }
.modal-backdrop.open { opacity: 1; }
.modal { transform: translateY(100%); transition: transform .3s cubic-bezier(.2, .8, .2, 1); }
.modal-backdrop.open .modal { transform: translateY(0); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 18px; word-break: break-all; }
.modal-close {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border: none; border-radius: 50%;
  background: var(--secondary-bg);
  color: var(--hint);
  font-size: 16px;
  cursor: pointer;
}

.qr { cursor: pointer; }

/* ---- safe areas (iPhone island / Telegram header) ---- */
:root {
  --top-inset: calc(env(safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
}
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }
body {
  padding-top: var(--top-inset);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px));
}
/* opaque strip so scrolled content never shows behind the island */
body::before {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--top-inset);
  background: var(--bg);
  z-index: 4;
}
button, .list-item, .tab { touch-action: manipulation; }
input, select, textarea { font-size: 16px; }

/* ---- skeletons ---- */
.sk {
  display: block;
  background: var(--text);
  opacity: .1;
  border-radius: 6px;
  animation: sk-pulse 1.2s ease-in-out infinite;
}
@keyframes sk-pulse { 0%, 100% { opacity: .07; } 50% { opacity: .16; } }
.list-item.no-click { cursor: default; }
.searchbar .sk { margin-top: 2px; }

/* ---- checkboxes ---- */
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 15px;
  color: var(--text);
}
.check-row input[type="checkbox"] {
  width: 20px; height: 20px;
  margin: 0;
  flex-shrink: 0;
}
input:disabled { opacity: .55; }
.val { text-align: right; word-break: break-word; }
