:root {
  --bg: #080808;
  --surface: #1a1a1a;
  --surface-deep: #101010;
  --line: #2a2a2a;
  --text: #ededed;
  --muted: #777;
  --green: #2dd6a0;
  --green-bg: #07533f;
  --yellow: #e3b44f;
  --red: #f06a73;
  --radius: 14px;
  --content-width: 1360px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  padding: 22px 20px 44px;
  color: var(--text);
  background: var(--bg);
}
button, input { font: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }

.header {
  margin: 0 auto 42px;
  text-align: center;
}
.header h1 {
  margin: 0;
  color: #fff;
  font-size: clamp(27px, 3vw, 36px);
  line-height: 1.1;
  letter-spacing: -.025em;
}
.header p {
  margin: 9px 0 4px;
  color: #8a8a8a;
  font-size: 16px;
}
.header a {
  color: #777;
  font-size: 13px;
  text-decoration: underline;
}

.grid {
  width: min(var(--content-width), calc(100% - 40px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.card {
  min-width: 0;
  min-height: 168px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 14px 38px rgba(0,0,0,.18);
}
.card-full { grid-column: 1 / -1; min-height: 0; }
.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}
.card-title h2 {
  margin: 0;
  color: #f3f3f3;
  font-size: 18px;
  font-weight: 650;
}
.address {
  margin: 0;
  color: #777;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 25px;
  padding: 4px 16px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-online { color: var(--green); background: var(--green-bg); }
.badge-connecting { color: var(--yellow); background: #5b4210; }
.badge-offline { color: var(--red); background: #5b1b21; }
.counter-hidden { display: none; }

.device-list, .pin-list { display: grid; gap: 8px; }
.device-list:empty, .pin-list:empty { min-height: 70px; }
.device {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  min-height: 54px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface-deep);
}
.device-icon {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}
.device > div:nth-child(2) {
  position: relative;
  min-width: 0;
  padding-left: 17px;
}
.device > div:nth-child(2)::before {
  content: "";
  position: absolute;
  left: 0;
  top: .5em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}
.device-name {
  overflow: hidden;
  color: #efefef;
  font-size: 15px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.device-id {
  margin-top: 4px;
  color: #666;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  overflow-wrap: anywhere;
}
.device-id[hidden] { display: none; }
.device-state { text-align: right; }
.state-badge {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--green);
  background: var(--green-bg);
  font-size: 10px;
  font-weight: 650;
}
.state-badge.waiting { color: #aaa; background: #252525; }
.state-badge.processing, .state-badge.pin { color: var(--yellow); background: #4d3912; }
.state-badge.completed, .state-badge.ready, .state-badge.active { color: var(--green); background: var(--green-bg); }
.rename-button {
  width: 34px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  color: #777;
  border: 1px solid #303030;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
}
.rename-button:hover { color: var(--green); border-color: #3b5e54; }
.rename-button svg { width: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.empty-state {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #646464;
  text-align: center;
}
.empty-mark { display: none; }
.empty-state strong { display: block; color: #707070; font-size: 14px; font-weight: 450; }
.empty-state span { display: none; }

.button {
  min-height: 34px;
  padding: 6px 18px;
  color: #e2e2e2;
  border: 1px solid #333;
  border-radius: 7px;
  background: #1a1a1a;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
}
.button:hover { background: #252525; }
.button:active { transform: scale(.97); }
.button-primary { color: #eafff8; border-color: #12664f; background: #07533f; }

.pin-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  padding: 13px 14px;
  border-radius: 7px;
  background: var(--surface-deep);
}
.pin-value { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; font-weight: 700; }
.pin-meta { display: inline; margin-left: 10px; color: #bbb; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.pin-time { color: #666; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }

.event-list {
  min-height: 112px;
  max-height: 270px;
  margin: 0;
  padding: 12px 18px;
  overflow-y: auto;
  border-radius: 7px;
  background: #050505;
  list-style: none;
  scrollbar-color: #8a8a8a #202020;
}
.event-list li {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  gap: 10px;
  padding: 5px 0;
  color: #a7b0be;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.event-list li span::before { content: "> "; color: #777; }
.event-list li.success span::before { color: var(--green); }
.event-list li.warning span::before { color: var(--yellow); }
.event-list li.error span::before { color: var(--red); }
.event-list time { color: #666; }

.footer-note {
  width: min(var(--content-width), calc(100% - 40px));
  margin: 18px auto 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  color: #555;
  font-size: 11px;
}
.footer-note > span:first-child { margin-right: auto; }

.rename-dialog {
  width: min(450px, calc(100% - 28px));
  padding: 0;
  color: var(--text);
  border: 1px solid #343434;
  border-radius: 12px;
  background: #191919;
  box-shadow: 0 28px 90px rgba(0,0,0,.7);
}
.rename-dialog::backdrop { background: rgba(0,0,0,.76); }
.rename-dialog form { padding: 24px; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.dialog-header h2 { margin: 0; font-size: 18px; }
.dialog-close { width: 32px; height: 32px; color: #888; border: 0; background: transparent; font-size: 22px; cursor: pointer; }
.rename-dialog label { display: grid; gap: 7px; margin-top: 14px; color: #bbb; font-size: 12px; }
.rename-dialog input { width: 100%; height: 42px; padding: 0 11px; color: #eee; border: 1px solid #333; border-radius: 7px; background: #0d0d0d; }
.rename-dialog input[readonly] { color: #777; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.rename-dialog p { margin: 12px 0 0; color: #777; font-size: 11px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }

.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 20; display: grid; gap: 8px; }
.toast { min-width: 240px; max-width: 390px; padding: 12px 14px; color: #eee; border: 1px solid #333; border-left: 3px solid var(--green); border-radius: 8px; background: #181818; box-shadow: 0 16px 50px rgba(0,0,0,.45); font-size: 12px; }
.toast.error { border-left-color: var(--red); }

@media (max-width: 820px) {
  body { padding: 18px 12px 32px; }
  .header { margin-bottom: 28px; }
  .grid { width: 100%; grid-template-columns: 1fr; gap: 14px; }
  .card, .card-full { grid-column: 1; padding: 20px; }
  .footer-note { width: 100%; flex-wrap: wrap; }
}

@media (max-width: 520px) {
  .card-title { align-items: flex-start; }
  .device { grid-template-columns: minmax(0, 1fr) auto; }
  .device-state { grid-column: 1; padding-left: 17px; text-align: left; }
  .rename-button { grid-column: 2; grid-row: 1 / span 2; }
  .footer-note > span:first-child { width: 100%; }
}
