:root {
  color-scheme: light;
  --ink: #20283b;
  --muted: #5b667d;
  --line: #e0e5ee;
  --surface: #fff;
  --bg: #f4f6fa;
  --accent: #5345c8;
  --accent-hover: #4538b0;
  --navy: #20243e;
  font-family: Inter, 'Segoe UI', system-ui, sans-serif;
  font-synthesis: none;
  line-height: 1.48;
  color: var(--ink);
  background: var(--bg);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 300px; min-height: 100vh; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #7768eb; outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
a { color: inherit; text-decoration: none; }
.muted, .hint { color: var(--muted); }
.skip-link { position: absolute; top: -100%; padding: 10px; background: #fff; z-index: 2; }
.skip-link:focus { top: 6px; left: 6px; }
.icon-library { position: absolute; height: 0; width: 0; pointer-events: none; }
.icon { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; fill: none; flex: 0 0 auto; }
.wrap { width: min(1200px, calc(100% - 64px)); margin-inline: auto; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-content { min-height: 70px; display: flex; align-items: center; gap: clamp(16px, 3.1vw, 44px); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 750; white-space: nowrap; letter-spacing: -.025em; }
.brand b { font-weight: 600; color: var(--muted); }
.brand-mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; color: white; font-size: 18px; font-weight: 800; background: var(--accent); }
.navigation { display: flex; align-items: center; gap: 5px; }
.navigation button, .icon-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 11px; border: 1px solid transparent; border-radius: 8px; color: var(--muted); background: transparent; font-size: .89rem; font-weight: 680; white-space: nowrap; }
.navigation button[aria-pressed='true'] { background: #eeeafd; color: #493ab4; }
.navigation button:not([aria-pressed='true']):hover, .icon-button:hover { color: var(--ink); background: var(--bg); }
.icon-button { width: 38px; height: 38px; padding: 0; }
.top-actions { display: flex; align-items: center; gap: 9px; margin-left: auto; }
.badge { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; background: #edf0f6; color: #505c75; border-radius: 99px; padding: 3px 9px; font-weight: 690; font-size: .75rem; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 100%; background: currentColor; }
.badge.online { background: #e2f6ec; color: #166443; }
.badge.offline { background: #fff0e4; color: #95511b; }

.main { padding-block: 32px 18px; }
.hero { position: relative; isolation: isolate; overflow: hidden; display: flex; align-items: end; justify-content: space-between; gap: 28px; padding: 31px 32px; border-radius: 17px; color: #fff; background: linear-gradient(108deg, #20243e 15%, #302655 63%, #3f3070); }
.hero::after { content: ''; z-index: -1; position: absolute; inset: 0; background: repeating-radial-gradient(circle at 89% 122%, transparent 0 33px, rgba(207, 195, 255, .13) 34px 35px); mask-image: linear-gradient(90deg, transparent 30%, #000); }
.eyebrow { display: inline-flex; gap: 8px; align-items: center; color: #c7baff; font-size: .71rem; font-weight: 730; letter-spacing: .12em; }
.eyebrow::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #b7a6ff; }
.hero h1 { margin: 4px 0 8px; font-size: clamp(2rem, 4vw, 3rem); letter-spacing: -.06em; font-weight: 750; line-height: 1.13; }
.hero p { max-width: 570px; color: #ebe8f7; font-size: .94rem; }
.primary, .secondary, .danger { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 9px; padding: 9px 13px; min-height: 39px; font-weight: 680; font-size: .88rem; }
.primary { color: white; background: var(--accent); }
.primary:hover { background: var(--accent-hover); }
.hero .primary { background: #f3efff; color: #352575; white-space: nowrap; padding-inline: 15px; }
.hero .primary:hover { background: #fff; }
.secondary { background: #fff; border-color: var(--line); color: var(--ink); }
.secondary:hover { background: var(--bg); }
.danger { color: #a12345; background: #ffeff3; }
.danger:hover { background: #ffdee7; }

.stats { display: grid; gap: 14px; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-block: 16px 20px; }
.stat { display: flex; align-items: center; gap: 13px; background: #fff; padding: 15px; border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.tile { display: grid; place-items: center; flex: 0 0 auto; width: 40px; height: 40px; border-radius: 10px; background: #edf0f8; color: #4c60a0; }
.tile.violet { color: #5640b1; background: #eee8ff; }
.tile.blue { color: #255f9d; background: #e6f2ff; }
.tile.green { color: #197359; background: #e1f5ed; }
.stat h2 { color: var(--muted); font-size: .78rem; font-weight: 640; }
.stat strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; line-height: 1.22; }
.stat-detail { color: var(--muted); font-size: .76rem; margin-left: 4px; }

.surface { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.toolbar, .tools { display: flex; align-items: center; gap: 10px; }
.toolbar { justify-content: space-between; padding: 16px 19px; }
.toolbar h2, .source-card h2 { font-size: 1.04rem; letter-spacing: -.015em; }
.toolbar p { margin-top: 1px; color: var(--muted); font-size: .8rem; }
.tools .icon-button { border-color: var(--line); }
.search { display: flex; align-items: center; gap: 7px; padding: 0 10px; min-height: 38px; color: var(--muted); border: 1px solid var(--line); border-radius: 8px; }
.search:focus-within { border-color: var(--accent); }
.search input { border: 0; outline: none; width: 155px; max-width: 100%; background: transparent; color: var(--ink); padding: 6px 0; font-size: .83rem; }
.device-grid { display: grid; grid-template-columns: minmax(164px, 1.35fr) minmax(158px, 1.25fr) minmax(128px, .9fr) 157px; gap: 12px; align-items: center; padding-inline: 19px; }
.list-head { padding-block: 9px; background: #f6f7fb; color: var(--muted); border-top: 1px solid var(--line); font-size: .76rem; font-weight: 700; }
.list-head span:last-child { text-align: right; }
.device-row { padding-block: 12px; border-top: 1px solid var(--line); min-height: 68px; }
.device-name, .source-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.device-name .tile { width: 34px; height: 34px; border-radius: 8px; }
.device-name .icon { width: 18px; height: 18px; }
.device-name h3 { font-size: .89rem; font-weight: 740; overflow-wrap: anywhere; }
.device-name p, .device-source small { color: var(--muted); font-size: .76rem; overflow-wrap: anywhere; }
.device-source { display: grid; justify-items: start; gap: 3px; }
.chips, .row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.chips small { color: var(--muted); font-size: .76rem; }
.chip { display: inline-flex; align-items: center; min-height: 27px; border-radius: 6px; padding: 2px 7px; color: #414c67; background: #eef1f7; font-size: .77rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-actions { justify-content: end; }
.text-button { border: 0; border-radius: 6px; color: #4b3bb4; background: transparent; font-size: .78rem; font-weight: 700; padding: 5px 6px; }
.text-button:hover { background: #f0ecfe; }
.switch { position: relative; width: 35px; height: 21px; border-radius: 50px; border: 0; background: #8a95aa; flex: 0 0 auto; }
.switch::after { position: absolute; content: ''; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: white; transition: transform .15s; }
.switch[aria-checked='true'] { background: var(--accent); }
.switch[aria-checked='true']::after { transform: translateX(14px); }
.empty { padding: 25px 20px; text-align: center; color: var(--muted); font-size: .89rem; }
.footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding-block: 17px; font-size: .76rem; color: var(--muted); }

.source-note { margin-block: 16px; border: 1px solid #d8dcf1; border-radius: 12px; background: #eeeffc; padding: 12px 15px; color: #41496a; font-size: .88rem; }
.source-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 14px; }
.source-grid > .empty { grid-column: 1 / -1; }
.source-card { display: grid; gap: 12px; padding: 15px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.source-card p { font-size: .78rem; color: var(--muted); }
.source-card code { display: block; padding: 6px 8px; border-radius: 6px; background: var(--bg); color: #414c67; font-size: .81rem; overflow-wrap: anywhere; }
.source-card .badge { margin-left: auto; }
.source-name h2, .source-name p { overflow-wrap: anywhere; }
.source-card-footer { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.source-card-footer .text-button { color: #a12345; }

dialog { width: min(520px, calc(100% - 24px)); max-height: calc(100dvh - 24px); border: 1px solid var(--line); border-radius: 15px; padding: 19px; color: var(--ink); background: white; box-shadow: 0 20px 80px #10163540; }
dialog::backdrop { background: #14192f80; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.dialog-heading h2 { font-size: 1.23rem; letter-spacing: -.025em; }
.dialog-actions { margin-top: 17px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.dialog-actions > span { flex: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.form-grid .full { grid-column: 1 / -1; }
.binding-fields { display: grid; gap: 9px; background: var(--bg); padding: 10px; border-radius: 8px; }
.form-grid label, .auth-card label { display: grid; gap: 5px; color: #35405a; font-size: .81rem; font-weight: 680; }
.form-grid label .muted { font-size: .75rem; }
.form-grid input:not([type='checkbox']), .form-grid select, .auth-card input { width: 100%; min-height: 38px; border: 1px solid #cdd4e2; border-radius: 8px; background: white; color: var(--ink); padding: 6px 9px; font-weight: 450; }
.form-grid input[type='checkbox'] { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { font-size: .77rem; }
#state-device-name, #kettle-device-name { margin: -7px 0 12px; font-size: .84rem; }
.form-error { color: #a12345; background: #ffeff3; border-radius: 7px; padding: 8px; margin-top: 9px; font-size: .85rem; }
.notice { position: fixed; z-index: 3; bottom: 20px; right: 20px; max-width: calc(100% - 40px); padding: 10px 16px; border-radius: 9px; color: white; background: var(--navy); box-shadow: 0 5px 20px #25294336; font-size: .88rem; }
.notice.error { background: #882342; }

.auth-page { display: grid; place-items: center; padding: 18px; background: radial-gradient(ellipse at 18% 15%, #e9e3fe, transparent 65%), var(--bg); }
.auth-card { width: min(410px, 100%); background: #fff; padding: 24px; border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 12px 40px #20154514; }
.auth-card h1 { margin-top: 15px; font-size: 1.6rem; line-height: 1.17; letter-spacing: -.035em; }
.auth-card > p { margin-block: 8px 16px; color: var(--muted); font-size: .91rem; }
.auth-card form { display: grid; gap: 12px; }

@media (max-width: 850px) {
  .wrap { width: calc(100% - 34px); }
  .device-grid { grid-template-columns: minmax(140px, 1.2fr) minmax(120px, 1fr) minmax(106px, .8fr) 150px; }
}
@media (max-width: 630px) {
  .wrap { width: calc(100% - 24px); }
  .topbar-content { flex-wrap: wrap; gap: 4px; padding-top: 8px; }
  .navigation { width: 100%; order: 3; padding-bottom: 6px; }
  .navigation button { padding-inline: 8px; }
  .main { padding-top: 14px; }
  .hero { display: grid; justify-items: start; gap: 15px; padding: 17px; border-radius: 12px; }
  .stats { gap: 5px; margin-block: 9px 10px; }
  .stat { padding: 7px; gap: 4px; align-items: start; flex-direction: column; }
  .stat .tile { width: 25px; height: 25px; border-radius: 6px; }
  .stat .icon { width: 16px; height: 16px; }
  .stat h2 { font-size: .7rem; line-height: 1.2; }
  .toolbar { flex-wrap: wrap; padding: 9px 12px; }
  .tools { width: 100%; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .list-head { display: none; }
  .device-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 7px; padding: 9px 12px; }
  .device-name { grid-column: 1 / -1; }
  .device-source { justify-items: end; text-align: right; }
  .row-actions { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { .switch::after { transition: none; } }
