:root {
  color-scheme: light dark;
  --bg: #f5f5f7; --card: #fff; --text: #1d1d1f; --soft: #6e6e73; --line: #e2e2e7;
  --accent: #2563eb; --accent-text: #fff; --ok: #1f9d55; --warn: #d97706; --bad: #c62828; --chip: #e9e9ee;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(0, 0, 0, .05);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1012; --card: #1b1c1f; --text: #f2f2f4; --soft: #a0a0a8; --line: #2e3035; --accent: #5b8def; --accent-text: #0b1020;
    --ok: #37c978; --warn: #f0a23b; --bad: #ff6b6b; --chip: #26272b; --shadow: 0 1px 2px rgba(0, 0, 0, .5); }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 1100px; margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px 8px; }
.title { display: flex; align-items: center; gap: 10px; }
.title h1 { font-size: 22px; line-height: 1.15; }
.title p { color: var(--soft); font-size: 14px; }
main { max-width: 1100px; margin: 0 auto; padding: 0 16px calc(48px + env(safe-area-inset-bottom)); }

.quiet { background: none; border: 1px solid var(--line); border-radius: 9px; padding: 7px 12px; font-size: 14px; }
.quiet:hover:not(:disabled) { background: var(--chip); }
.quiet.danger { color: var(--bad); }
.primary { display: block; width: 100%; background: var(--accent); color: var(--accent-text); border: 0; border-radius: 11px; padding: 12px 16px;
  font-weight: 600; text-align: center; text-decoration: none; }
.primary:hover:not(:disabled) { filter: brightness(1.08); }

.tools { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0 10px; }
#search, #new-label, .card input { width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 11px 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; background: var(--chip); border: 0; border-radius: 999px; padding: 6px 13px; font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--text); color: var(--bg); }

.notice { background: color-mix(in srgb, var(--warn) 16%, transparent); border-radius: 10px; padding: 10px 14px; margin: 6px 0; font-size: 14px; }
.loading, .empty, .hint { color: var(--soft); padding: 28px 4px; text-align: center; }
.hint { padding: 14px 4px 0; text-align: left; }
.section { font-size: 15px; font-weight: 600; color: var(--soft); margin: 22px 2px 10px; }
.count { font-weight: 400; margin-left: 8px; opacity: .8; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 7px; min-height: 112px; padding: 14px 6px 10px;
  background: var(--card); border: 1px solid transparent; border-radius: 14px; box-shadow: var(--shadow); text-align: center; }
.tile:hover { border-color: var(--line); }
.tile.connected { border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.tile .name { font-size: 13px; font-weight: 500; line-height: 1.2; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .caption { font-size: 11px; color: var(--soft); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.logo { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; background: #fff; overflow: hidden; border: 1px solid var(--line); }
.logo img { width: 30px; height: 30px; object-fit: contain; }
.logo.big { width: 54px; height: 54px; border-radius: 12px; }
.logo.big img { width: 38px; height: 38px; }
.letter { font-weight: 700; font-size: 19px; color: #555; }
.badge { position: absolute; top: 8px; right: 8px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff; }
.badge.ok { background: var(--ok); }
.badge.warn { background: var(--warn); }
.more { display: block; margin: 18px auto 0; background: var(--chip); border: 0; border-radius: 999px; padding: 9px 18px; }

dialog { width: min(540px, calc(100vw - 20px)); max-height: min(86vh, 760px); padding: 0; border: 0; border-radius: 18px; background: var(--card); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35); overflow: auto; }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.sheet-head { display: flex; gap: 14px; align-items: flex-start; padding: 20px 20px 6px; }
.sheet-head > div { flex: 1; min-width: 0; }
.sheet-head h2 { font-size: 20px; }
.sheet-head p { color: var(--soft); font-size: 14px; margin-top: 2px; }
.close { flex: none; width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--chip); font-size: 13px; }
#sheet-body { padding: 8px 20px 22px; }
#sheet-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--soft); margin: 16px 0 8px; }
.accounts { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 13px; }
.accounts li { padding: 12px 14px; }
.accounts li + li { border-top: 1px solid var(--line); }
.who { display: flex; gap: 10px; align-items: flex-start; }
.who > div { min-width: 0; }
.who strong { display: block; overflow-wrap: anywhere; }
.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); margin-top: 7px; }
.attention .dot { background: var(--warn); }
.fine { display: block; color: var(--soft); font-size: 13px; }
.reason { color: var(--warn); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 0 19px; }
.actions .quiet { padding: 5px 11px; font-size: 13px; }
.add { margin-top: 6px; }
.add .fine { margin-bottom: 10px; }
.add input { margin-bottom: 10px; }
.setup { background: var(--chip); border-radius: 12px; padding: 12px 14px; margin-top: 14px; font-size: 14px; }

.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 2147483647; max-width: calc(100vw - 32px);
  background: #222; color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .3); }
.toast.good { background: #17703d; }
.toast.bad { background: #a12222; }

.center { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.card { width: min(380px, 100%); background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 28px 24px; display: grid; gap: 12px; text-align: center; }
.card h1 { font-size: 22px; }
.card p { color: var(--soft); font-size: 15px; }
.card label { text-align: left; font-size: 14px; color: var(--soft); margin-bottom: -6px; }
.card img { margin: 0 auto; }
.problem { color: var(--bad) !important; }

@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 88dvh; }
  #search, #new-label, .card input { font-size: 16px; }
}
