:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --sidebar: #ececef;
  --card: #ffffff;
  --card-soft: #f3f4f6;
  --text: #111827;
  --muted: #6b7280;
  --border: rgba(0, 0, 0, 0.09);
  --accent: #007aff;
  --accent-soft: rgba(0, 122, 255, 0.12);
  --green: #10b981;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --danger: #ef4444;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pyidaungsu", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161618;
    --sidebar: #1e1e21;
    --card: #242428;
    --card-soft: #2c2c31;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #0a84ff;
    --accent-soft: rgba(10, 132, 255, 0.18);
    --warn-bg: rgba(146, 64, 14, 0.35);
    --warn-text: #fde68a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  height: 100%;
}

.native-window {
  display: grid;
  grid-template-columns: 224px 1fr;
  min-block-size: 100dvh;
}

/* NATIVE DESKTOP SIDEBAR */
.native-sidebar {
  background: var(--sidebar);
  border-inline-end: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
}

.brand-ico {
  border-radius: 8px;
  flex: none;
}

.brand-lines {
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
}

.brand-lines strong {
  font-size: 14px;
  font-weight: 700;
}

.brand-lines span {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-align: start;
}

.nav-item:hover {
  background: var(--border);
}

.nav-item[aria-selected="true"] {
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.conn-pill-box {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 600;
}

.conn-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  inline-size: 8px;
  block-size: 8px;
  border-radius: 50%;
  flex: none;
}
.status-dot.is-ok { background: var(--green); }
.status-dot.is-busy { background: #f59e0b; }
.status-dot.is-off { background: var(--muted); }

.footer-links {
  display: flex;
  gap: 6px;
}

/* MAIN AREA */
.native-main {
  padding: 20px 24px 32px;
  overflow-y: auto;
}

.native-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-block-end: 18px;
}

.native-header h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.device-id-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 4px 10px;
}

.device-name-field {
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  inline-size: 135px;
}

.fp-code {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.connect-two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
  align-items: start;
}

.connect-right-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.native-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.native-card h2 {
  margin: 0 0 10px;
  font-size: 14.5px;
  font-weight: 700;
}

.sub-h {
  margin: 14px 0 8px;
  font-size: 13px;
  color: var(--muted);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-block-end: 10px;
}

.card-head h2 { margin: 0; }

/* QR HERO */
.qr-hero-card {
  text-align: center;
}

.qr-stage {
  display: flex;
  justify-content: center;
  margin: 8px 0 12px;
}

.qr-frame {
  padding: 10px;
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid var(--border);
  display: inline-flex;
}

.room-code-display {
  margin: 6px 0 12px;
}

.room-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.room-code-display strong {
  font-family: var(--mono);
  font-size: 28px;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.copy-link-row, .join-row, .btn-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-bar {
  margin: 10px 0;
  flex-wrap: wrap;
}

.btn-bar-tight {
  display: flex;
  gap: 6px;
}

.hint-line {
  font-size: 11.5px;
  color: var(--muted);
  margin: 10px 0 0;
}

.or-divider {
  text-align: center;
  margin: 12px 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.native-input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.compact-select {
  width: auto;
  min-inline-size: 190px;
}

.code-input {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  min-block-size: 36px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  background: var(--card-soft);
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border-color: transparent;
}

.btn-soft {
  background: var(--card-soft);
  color: var(--text);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-sm {
  min-block-size: 28px;
  padding: 4px 10px;
  font-size: 12px;
}

.btn-lg {
  flex: 1;
  min-block-size: 46px;
  font-size: 14px;
}

.btn-block {
  width: 100%;
  min-block-size: 42px;
}

/* PEERS & LISTS */
.peers-stack, .scroll-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-block-size: 320px;
  overflow-y: auto;
}

.peer-row, .list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--card-soft);
  border: 1px solid var(--border);
}

.peer-title-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.peer-sub {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.pill-tag {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
}

.pill-tag.is-p2p {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.peer-actions {
  display: flex;
  gap: 6px;
}

.empty-card {
  padding: 14px;
  border-radius: 9px;
  background: var(--card-soft);
  color: var(--muted);
  font-size: 12.5px;
}

.empty-card strong { color: var(--text); }
.empty-card p { margin: 4px 0 0; }

/* SHARE DROP ZONE */
.drop-box {
  border: 2px dashed var(--accent);
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-block-end: 14px;
}

.drop-box.is-dragover {
  opacity: 0.85;
}

.drop-ico { font-size: 28px; }
.drop-box span { font-size: 12px; color: var(--muted); }

.text-send-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.text-send-box label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.warn-strip {
  margin-top: 8px;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 12px;
  font-weight: 600;
}

.toggle-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

/* VIDEO & CAMERA */
.video-frame, .camera-box {
  position: relative;
  background: #0b0b0d;
  border-radius: 10px;
  overflow: hidden;
  min-block-size: 230px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-frame video, .camera-box video {
  width: 100%;
  max-block-size: 320px;
  object-fit: cover;
  display: block;
}

.video-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  color: #9ca3af;
  font-size: 12.5px;
}

.scan-reticle {
  position: absolute;
  width: 170px;
  height: 170px;
  border: 2.5px solid #22d3ee;
  border-radius: 16px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

/* NATIVE DIALOGS */
dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  padding: 0;
  max-inline-size: min(92vw, 480px);
  inline-size: 100%;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

dialog:modal { overscroll-behavior: contain; }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); overflow: hidden; overscroll-behavior: contain; }

.dlg-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.dlg-head h1 { margin: 0; font-size: 15px; }
.dlg-body { padding: 16px; }

.clean-list {
  margin: 0;
  padding-inline-start: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}

/* COPY TIP */
.copy { position: relative; display: inline-flex; }
.copy .tip {
  position: absolute;
  inset-block-end: calc(100% + 4px);
  inset-inline-end: 0;
  background: #111827;
  color: #ffffff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 5px;
  opacity: 0;
  pointer-events: none;
}
.copy-button[data-copied] + .tip { opacity: 1; }

/* TOAST */
.toast-region {
  position: fixed;
  inset-block-end: 74px;
  inset-inline-end: 16px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toast-pill {
  background: #111827;
  color: #ffffff;
  padding: 8px 13px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
}

/* MOBILE BOTTOM NAVIGATION BAR */
.mobile-bottom-bar { display: none; }

@media (max-width: 760px) {
  .native-window {
    grid-template-columns: 1fr;
    padding-bottom: 68px;
  }
  .native-sidebar {
    display: none;
  }
  .native-main {
    padding: 14px 14px 20px;
  }
  .mobile-bottom-bar {
    position: fixed;
    inset-block-end: 0;
    inset-inline: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--sidebar);
    border-top: 1px solid var(--border);
    padding: 4px 4px max(4px, env(safe-area-inset-bottom));
    z-index: 40;
  }
  .mob-tab {
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    padding: 6px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
  }
  .mob-tab[aria-selected="true"] {
    color: var(--accent);
  }
}
