:root {
  --bg: #f4f7f9;
  --bg-2: #e8eef2;
  --panel: #ffffff;
  --panel-2: #f8fafb;
  --text: #18242b;
  --text-dim: #62717b;
  --muted: #8b99a3;
  --line: #dbe4e9;
  --line-strong: #c6d3da;
  --brand: #00a884;
  --brand-dark: #007a66;
  --accent: #00c7b1;
  --danger: #cc3d4a;
  --ok: #1a9f72;
  --warn: #d99100;
  --radius: 18px;
  --shadow: 0 18px 45px rgba(28, 45, 56, 0.12);
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', 'Noto Sans Thai', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background:
    linear-gradient(90deg, rgba(0, 168, 132, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(0, 168, 132, 0.06) 1px, transparent 1px),
    radial-gradient(circle at 12% 14%, rgba(0, 199, 177, 0.18), transparent 32%),
    linear-gradient(180deg, #f9fbfc, var(--bg));
  background-size: 42px 42px, 42px 42px, auto, auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(115deg, transparent 0 48%, rgba(0, 122, 102, 0.06) 48% 52%, transparent 52% 100%),
    radial-gradient(circle at 75% 18%, rgba(0, 168, 132, 0.12), transparent 28%);
  z-index: 0;
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  gap: 14px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-copy { display: grid; gap: 2px; }
.brand-name { font-size: 20px; font-weight: 800; letter-spacing: -0.03em; color: var(--text); }
.brand-sub { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.12em; }

.room-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(28, 45, 56, 0.08);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  min-width: 0;
}
.room-pill span:last-child { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); transition: background 0.2s; }
.dot.online { background: var(--ok); box-shadow: 0 0 0 4px rgba(26, 159, 114, 0.14); }

.stage {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 18px 24px;
}

.radar {
  position: relative;
  width: min(88vw, 64vh, 620px);
  height: min(88vw, 64vh, 620px);
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(248, 250, 251, 0.78));
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  overflow: hidden;
  flex: 0 0 auto;
}

.radar::before {
  content: '';
  position: absolute;
  inset: 54px;
  border-radius: 50%;
  background: conic-gradient(from 225deg, rgba(0, 168, 132, 0.18), transparent 28%, transparent 100%);
  animation: sweep 7s linear infinite;
}

.radar-header {
  position: absolute;
  top: 18px;
  left: 20px;
  right: 20px;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.13em;
}
.radar-header b { color: var(--brand-dark); font-weight: 800; }

.radar-rings { position: absolute; inset: 42px; display: grid; place-items: center; }
.radar-rings span {
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(0, 122, 102, 0.18);
  background: rgba(0, 168, 132, 0.018);
}
.radar-rings span:nth-child(1) { width: 38%; height: 38%; }
.radar-rings span:nth-child(2) { width: 66%; height: 66%; }
.radar-rings span:nth-child(3) { width: 94%; height: 94%; }

@keyframes sweep { to { transform: rotate(360deg); } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -50%) scale(0.72); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideUp { from { transform: translateY(28px); opacity: 0; } }
@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } }

.self {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  text-align: center;
  width: 140px;
  min-height: 140px;
  padding: 18px;
  border-radius: 28px;
  background: linear-gradient(180deg, #ffffff, #f5f8f9);
  border: 1px solid var(--line-strong);
  box-shadow: 0 22px 46px rgba(20, 48, 58, 0.14);
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}
.self:hover, .self:focus-visible { transform: translateY(-2px); border-color: var(--brand); box-shadow: 0 24px 52px rgba(0, 122, 102, 0.18); outline: none; }
.self-icon, .peer-avatar, .xfer-icon, .toast-icon, .logo {
  display: grid;
  place-items: center;
}
.self-icon { width: 54px; height: 54px; border-radius: 16px; background: rgba(0, 168, 132, 0.1); margin-bottom: 10px; }
.self-name { max-width: 100%; font-size: 14px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.self-hint { margin-top: 4px; color: var(--muted); font-size: 10px; letter-spacing: 0.13em; }

.peers { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.peer {
  position: absolute;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  animation: pop 0.25s ease-out;
  pointer-events: auto;
}
.peer-avatar {
  position: relative;
  width: 76px;
  height: 76px;
  border-radius: 22px;
  background: linear-gradient(180deg, #ffffff, #f3f7f8);
  border: 1px solid var(--line-strong);
  box-shadow: 0 16px 30px rgba(28, 45, 56, 0.14);
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}
.peer:hover .peer-avatar,
.peer.drag-over .peer-avatar {
  transform: translateY(-3px);
  border-color: var(--brand);
  box-shadow: 0 18px 38px rgba(0, 122, 102, 0.22);
}
.peer-label { max-width: 130px; font-size: 12px; font-weight: 800; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-device { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; }
.peer-ring { position: absolute; inset: -5px; border-radius: 25px; border: 3px solid transparent; pointer-events: none; }
.peer.busy .peer-ring { border-top-color: var(--brand); border-right-color: var(--accent); animation: spin 0.8s linear infinite; }

.empty-hint {
  position: relative;
  z-index: 2;
  max-width: 470px;
  margin-top: 18px;
  padding: 16px 18px;
  text-align: center;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 12px 28px rgba(28, 45, 56, 0.08);
}
.quick-actions {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 12px 28px rgba(28, 45, 56, 0.08);
}
.quick-actions span {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.btn-primary:disabled, .btn-ghost:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  box-shadow: none;
}
.empty-title { font-size: 15px; font-weight: 800; }
.empty-sub { margin: 6px 0 14px; color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.empty-hint.hide { display: none; }

.btn-primary, .btn-ghost {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.18s, background 0.18s;
}
.btn-primary { color: #fff; background: linear-gradient(180deg, var(--brand), var(--brand-dark)); box-shadow: 0 10px 20px rgba(0, 122, 102, 0.22); }
.btn-primary:hover { box-shadow: 0 12px 24px rgba(0, 122, 102, 0.28); }
.btn-ghost { color: var(--text); background: #fff; border: 1px solid var(--line-strong); }
.btn-primary:active, .btn-ghost:active { transform: scale(0.98); }
.btn-full { width: 100%; }

.footer { position: relative; z-index: 1; padding: 14px; text-align: center; color: var(--muted); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }

.tray {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  width: min(92vw, 410px);
  max-height: 62vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: var(--shadow);
  animation: slideUp 0.25s ease-out;
}
.tray-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.08em; }
.tray-close { border: none; border-radius: 8px; padding: 4px 8px; background: var(--panel-2); color: var(--text-dim); cursor: pointer; }
.tray-close:hover { color: var(--text); background: var(--bg-2); }
.tray-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding: 10px; }

.xfer { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; }
.xfer-icon { width: 42px; height: 42px; flex-shrink: 0; border-radius: 12px; background: rgba(0, 168, 132, 0.09); }
.xfer-body { flex: 1; min-width: 0; }
.xfer-name { font-size: 13px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xfer-meta { margin-top: 2px; color: var(--text-dim); font-size: 11px; }
.xfer-bar { height: 6px; margin-top: 9px; overflow: hidden; background: #d9e4e8; border-radius: 999px; }
.xfer-fill { width: 0; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), var(--accent)); transition: width 0.15s linear; }
.xfer.done .xfer-fill { background: var(--ok); }
.xfer.error .xfer-fill { background: var(--danger); }
.xfer-action a { color: var(--brand-dark); font-size: 12px; font-weight: 900; text-decoration: none; }

.toast-wrap { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 10px; width: min(92vw, 420px); }
.toast { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 16px; box-shadow: var(--shadow); animation: slideDown 0.25s ease-out; }
.toast-icon { width: 42px; height: 42px; flex-shrink: 0; border-radius: 12px; background: rgba(0, 168, 132, 0.1); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-size: 13px; font-weight: 900; }
.toast-sub { color: var(--text-dim); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast-btns { display: flex; gap: 8px; }
.toast-btns button { border: none; border-radius: 9px; padding: 8px 12px; font-family: inherit; font-size: 12px; font-weight: 900; cursor: pointer; }
.t-accept { color: #fff; background: var(--brand-dark); }
.t-decline { color: var(--text); background: var(--bg-2); }

.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: rgba(19, 33, 40, 0.42); backdrop-filter: blur(6px); }
.modal-card { width: min(92vw, 430px); padding: 24px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 20px; box-shadow: var(--shadow); animation: slideUp 0.22s ease-out; }
.modal-card h3 { font-size: 18px; font-weight: 900; }
.modal-sub { margin: 8px 0 16px; color: var(--text-dim); font-size: 13px; line-height: 1.55; }
.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0 14px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; }
.divider::before, .divider::after { content: ''; height: 1px; flex: 1; background: var(--line); }
.room-input input { width: 100%; padding: 13px 14px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: 10px; outline: none; font: inherit; font-size: 15px; }
.room-input input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(0, 168, 132, 0.12); }
.pin-input { margin-top: 10px; }
.pin-help { margin-top: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-note { margin-top: 16px; padding: 12px; color: var(--text-dim); background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; text-align: center; font-size: 12px; }
.invite-row { display: flex; justify-content: center; gap: 12px; margin-top: 10px; }
.link-button { border: none; background: none; color: var(--brand-dark); cursor: pointer; font: inherit; font-weight: 900; }
.modal-footnote { margin-top: 14px; color: var(--muted); font-size: 11px; line-height: 1.5; }

.icon { position: relative; width: 28px; height: 28px; color: var(--brand-dark); }
.icon::before, .icon::after { content: ''; position: absolute; box-sizing: border-box; }
.logo { width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(180deg, var(--brand), var(--brand-dark)); box-shadow: 0 12px 26px rgba(0, 122, 102, 0.26); }
.logo::before { width: 24px; height: 14px; border: 4px solid #fff; border-left: 0; border-right: 0; top: 14px; left: 9px; }
.logo::after { width: 8px; height: 8px; border-radius: 50%; background: #fff; top: 17px; left: 17px; box-shadow: -12px 0 0 rgba(255,255,255,0.55), 12px 0 0 rgba(255,255,255,0.55); }
.icon-ap::before, .icon-endpoint::before { inset: 5px; border: 2px solid currentColor; border-radius: 8px; }
.icon-ap::after { width: 6px; height: 6px; border-radius: 50%; background: currentColor; left: 11px; top: 11px; box-shadow: 0 10px 0 currentColor; }
.icon-endpoint::after { width: 10px; height: 2px; background: currentColor; left: 9px; bottom: 4px; box-shadow: 0 4px 0 currentColor; }
.icon-workstation::before { width: 24px; height: 16px; border: 2px solid currentColor; border-radius: 4px; left: 2px; top: 4px; }
.icon-workstation::after { width: 14px; height: 2px; background: currentColor; left: 7px; bottom: 4px; box-shadow: 4px -4px 0 -1px currentColor; }
.icon-phone::before { width: 15px; height: 24px; border: 2px solid currentColor; border-radius: 5px; left: 7px; top: 2px; }
.icon-phone::after { width: 5px; height: 2px; border-radius: 2px; background: currentColor; left: 12px; bottom: 5px; }
.icon-file-generic::before, .icon-file-image::before, .icon-file-video::before, .icon-file-audio::before, .icon-file-pdf::before, .icon-file-archive::before, .icon-file-doc::before, .icon-file-sheet::before { width: 20px; height: 24px; border: 2px solid currentColor; border-radius: 4px; left: 4px; top: 2px; background: rgba(255,255,255,0.45); }
.icon-file-generic::after, .icon-file-doc::after { width: 10px; height: 2px; background: currentColor; left: 9px; top: 10px; box-shadow: 0 5px 0 currentColor, 0 10px 0 currentColor; }
.icon-file-image::after { width: 12px; height: 8px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); left: 8px; top: 11px; }
.icon-file-video::after { width: 0; height: 0; border-top: 6px solid transparent; border-bottom: 6px solid transparent; border-left: 9px solid currentColor; left: 11px; top: 8px; }
.icon-file-audio::after { width: 8px; height: 10px; border-left: 3px solid currentColor; border-bottom: 3px solid currentColor; border-radius: 0 0 0 7px; left: 11px; top: 8px; }
.icon-file-pdf::after { content: 'PDF'; position: absolute; left: 7px; top: 11px; font-size: 7px; font-weight: 900; color: currentColor; }
.icon-file-archive::after { width: 5px; height: 18px; background: repeating-linear-gradient(180deg, currentColor 0 2px, transparent 2px 4px); left: 12px; top: 5px; }
.icon-file-sheet::after { width: 14px; height: 12px; border: 2px solid currentColor; left: 7px; top: 9px; background: linear-gradient(90deg, transparent 45%, currentColor 45% 55%, transparent 55%), linear-gradient(180deg, transparent 45%, currentColor 45% 55%, transparent 55%); }
.icon-inbound::before { width: 18px; height: 18px; border: 2px solid currentColor; border-radius: 6px; left: 5px; top: 7px; }
.icon-inbound::after { width: 10px; height: 10px; border-right: 3px solid currentColor; border-bottom: 3px solid currentColor; transform: rotate(45deg); left: 9px; top: 3px; }
.icon-alert { color: var(--danger); }
.icon-alert::before { width: 0; height: 0; border-left: 13px solid transparent; border-right: 13px solid transparent; border-bottom: 24px solid currentColor; left: 1px; top: 2px; }
.icon-alert::after { width: 3px; height: 10px; background: #fff; left: 13px; top: 11px; box-shadow: 0 13px 0 #fff; }

body.dragging::after {
  content: 'DROP FILE ON AN ENDPOINT';
  position: fixed;
  inset: 14px;
  z-index: 50;
  display: grid;
  place-items: center;
  color: var(--brand-dark);
  background: rgba(0, 168, 132, 0.08);
  border: 2px dashed var(--brand);
  border-radius: 28px;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.08em;
  pointer-events: none;
}

@media (max-width: 560px) {
  html, body { overflow: auto; }
  body { min-height: 100svh; }
  .topbar { padding: 14px 16px; align-items: stretch; gap: 10px; flex-wrap: wrap; }
  .brand { min-width: 0; flex: 1 1 160px; }
  .brand-name { font-size: 18px; }
  .brand-sub { display: none; }
  .logo { width: 38px; height: 38px; }
  .room-pill { flex: 1 1 100%; justify-content: center; width: 100%; max-width: none; font-size: 12px; }
  .stage { justify-content: flex-start; padding: 4px 12px 96px; }
  .radar {
    width: min(94vw, calc(100svh - 230px), 430px);
    height: min(94vw, calc(100svh - 230px), 430px);
    min-width: 280px;
    min-height: 280px;
    border-radius: 50%;
  }
  .radar::before { inset: 36px; }
  .radar-rings { inset: 30px; }
  .radar-header { top: 14px; left: 14px; right: 14px; font-size: 8px; letter-spacing: 0.08em; }
  .self { width: 112px; min-height: 112px; padding: 14px; border-radius: 22px; }
  .self-icon { width: 44px; height: 44px; }
  .peer-avatar { width: 62px; height: 62px; border-radius: 18px; }
  .peer-label { max-width: 92px; font-size: 11px; }
  .peer-device { display: none; }
  .empty-hint { width: min(94vw, 430px); margin-top: 12px; padding: 14px; }
  .quick-actions { width: min(94vw, 430px); margin-top: 12px; border-radius: 18px; align-items: stretch; flex-direction: column; gap: 8px; }
  .quick-actions .btn-primary { width: 100%; }
  .quick-actions span { text-align: center; }
  .empty-sub br { display: none; }
  .footer { display: none; }
  .tray { left: 10px; right: 10px; bottom: 10px; width: auto; max-height: 48vh; border-radius: 16px; }
  .toast-wrap { top: 10px; width: calc(100vw - 20px); }
  .toast { align-items: flex-start; }
  .toast-btns { flex-direction: column; }
  .modal { padding: 12px; align-items: end; }
  .modal-card { width: 100%; max-height: calc(100svh - 24px); overflow-y: auto; border-radius: 18px; padding: 20px; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; }
  .invite-row { flex-direction: column; gap: 8px; }
}

@media (max-height: 700px) and (max-width: 560px) {
  .radar {
    width: min(86vw, calc(100svh - 190px), 360px);
    height: min(86vw, calc(100svh - 190px), 360px);
    min-width: 240px;
    min-height: 240px;
  }
  .self { width: 98px; min-height: 98px; }
  .self-icon { width: 38px; height: 38px; margin-bottom: 6px; }
  .self-hint { display: none; }
  .peer-avatar { width: 54px; height: 54px; }
  .empty-hint { font-size: 12px; }
}
