:root {
  --bg: #ffffff;
  --surface: #f6f8f7;
  --surface-hover: #eef4f1;
  --border: #d8e1dc;
  --border-strong: #b9c8c0;
  --ink: #132019;
  --muted: #52635a;
  --primary: #0b6e4f;
  --primary-hover: #08573e;
  --primary-soft: #e6f4ef;
  --accent: #f2a900;
  --accent-soft: #fef6df;
  --accent-ink: #7a5200;
  --danger: #c62828;
  --danger-hover: #a11f1f;
  --danger-soft: #fdecec;
  --neutral-soft: #edf1f4;
  --neutral-ink: #475569;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(19, 32, 25, 0.06), 0 1px 2px rgba(19, 32, 25, 0.04);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.muted {
  color: var(--muted);
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
  min-height: 44px;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  flex-shrink: 0;
}

.nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: auto;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}

.nav-link:hover {
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
}

.nav-link.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

/* Main container */
.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

/* Page header */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.page-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.btn:hover:not(:disabled) {
  background: var(--surface);
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #1c1500;
}

.btn-accent:hover:not(:disabled) {
  background: #dc9900;
  border-color: #dc9900;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface);
  color: var(--ink);
}

.btn-sm {
  min-height: 44px;
  padding: 0 12px;
  font-size: 13px;
}

.btn-inline {
  min-height: 36px;
  padding: 0 10px;
  font-size: 13px;
}

@media (max-width: 639px) {
  .btn-inline {
    min-height: 44px;
    padding: 0 12px;
  }
}

/* Segmented control */
.segmented {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}

.seg-btn {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--primary);
  color: #ffffff;
}

/* Chips & dots */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.chip-green {
  background: var(--primary-soft);
  color: var(--primary);
}

.chip-amber {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.chip-red {
  background: var(--danger-soft);
  color: var(--danger);
}

.chip-neutral {
  background: var(--neutral-soft);
  color: var(--neutral-ink);
}

.chip-info {
  background: #e0f2fe;
  color: #0369a1;
}

.select-compact {
  width: auto;
  min-width: 130px;
  min-height: 36px;
  padding: 4px 10px;
  font-size: 13px;
}

.diag-table-wrap {
  max-height: 380px;
  overflow-y: auto;
}

.diag-msg {
  word-break: break-word;
}

.nowrap {
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-online {
  background: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.dot-offline {
  background: #94a3b8;
}

.status-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  font-size: 13px;
}

/* Cards */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

/* Key-value grid */
.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.kv-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.kv-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 3px;
}

.kv-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  word-break: break-word;
}

/* Forms */
.form-card {
  max-width: 560px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}

.input, .select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
}

.input:focus, .select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-btn {
  min-height: 44px;
  min-width: 64px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.pill-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

/* Filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
  flex: 1 1 160px;
}

.filter-field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

/* Login */
.login-wrap {
  min-height: calc(100vh - 64px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 24px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.login-brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.btn-block {
  width: 100%;
}

.alert-error {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 14px;
}

/* Join result card */
.result-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: start;
}

.qr-box {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.qr-box svg {
  display: block;
  width: 184px;
  height: 184px;
}

.url-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.url-row .input {
  flex: 1 1 240px;
  font-family: var(--font-mono);
  font-size: 13px;
}

/* Data tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  text-align: left;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  padding: 0;
  white-space: nowrap;
}

.data-table th.sortable .sort-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  text-align: left;
}

.data-table th.sortable .sort-btn:hover {
  color: var(--ink);
  background: var(--surface-hover);
}

.data-table th.th-plain {
  padding: 12px;
}

.sort-ind {
  font-size: 10px;
  color: var(--primary);
  min-width: 10px;
}

.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr.row-click {
  cursor: pointer;
}

.data-table tbody tr.row-click:hover {
  background: var(--surface-hover);
}

.port-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.action-cell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* Copy CLI per-port menu */
.cli-menu {
  position: relative;
  display: inline-block;
}

.cli-menu > summary {
  list-style: none;
}

.cli-menu > summary::-webkit-details-marker {
  display: none;
}

.cli-menu[open] > summary {
  background: var(--surface-hover);
  border-color: var(--primary);
  color: var(--primary);
}

.cli-menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  min-width: 150px;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 18px rgba(19, 32, 25, 0.14);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cli-port-btn {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.cli-port-btn:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

@media (max-width: 639px) {
  .cli-menu-list {
    position: static;
    margin-top: 6px;
    box-shadow: none;
  }

  .cli-port-btn {
    min-height: 44px;
    padding: 0 12px;
  }
}

.dot-amber {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.empty-state {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
}

/* Mobile sort bar (shown only under 640px) */
.mobile-sort-bar {
  display: none;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.mobile-sort-bar .select {
  flex: 1;
}

.mobile-sort-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 50;
  background: var(--ink);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Responsive: Mobile < 640px */
@media (max-width: 639px) {
  .topbar {
    position: static;
  }

  .topbar-inner {
    padding: 8px 12px;
  }

  .main {
    padding: 14px 12px 40px;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }

  .qr-box {
    justify-self: center;
  }

  .mobile-sort-bar {
    display: flex;
  }

  .table-wrap {
    border: 0;
    background: transparent;
    overflow: visible;
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .data-table tr {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 10px 12px;
    margin-bottom: 10px;
  }

  .data-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid var(--surface);
    text-align: right;
  }

  .data-table td:last-child {
    border-bottom: 0;
    padding-bottom: 2px;
  }

  .data-table td::before {
    content: attr(data-label);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--muted);
    text-align: left;
    flex-shrink: 0;
  }

  .data-table td.cell-actions {
    flex-direction: column;
    align-items: stretch;
    text-align: left;
  }

  .data-table td.cell-actions::before {
    margin-bottom: 4px;
  }

  .action-cell {
    justify-content: flex-start;
  }

  .port-list {
    justify-content: flex-end;
  }

  .inv-target-bar {
    grid-template-columns: 1fr 1fr;
  }

  .inv-raw-form {
    grid-template-columns: 1fr 1fr;
  }
}

/* Inverter panel (v1.2) */
.inv-section {
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid var(--border);
}

.inv-section:first-of-type {
  padding-top: 0;
  margin-top: 0;
  border-top: 0;
}

.inv-dropzone {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 14px;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}

.inv-dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.inv-dropzone-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.inv-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.inv-wifi-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1.3fr) minmax(180px, 1.3fr) minmax(120px, 0.7fr) auto;
  gap: 10px;
  align-items: end;
}

.inv-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.inv-field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.inv-pwd-wrap {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.inv-pwd-wrap .input {
  flex: 1 1 auto;
  min-width: 0;
}

.inv-wifi-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.inv-raw-box {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
  white-space: pre-wrap;
}

.inv-target-bar {
  display: grid;
  grid-template-columns: minmax(150px, 1.2fr) minmax(90px, 0.6fr) minmax(95px, 0.6fr) minmax(150px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.inv-target-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* v1.16.5 session installer login card */
.inv-sess-login { margin-bottom: 14px; }
.inv-sess-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.inv-sess-form .inv-field { flex: 1 1 220px; }
.inv-sess-err { flex: 1 0 100%; margin: 0; font-size: 13px; font-weight: 600; color: var(--danger, #b42318); }
.inv-sess-ok { display: flex; align-items: center; gap: 10px; }
@media (max-width: 639px) {
  .inv-sess-form { flex-direction: column; align-items: stretch; }
  .inv-sess-form .inv-field { flex: none; }
}

.inv-login-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  padding: 12px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.inv-login-bar .inv-field {
  flex: 1 1 220px;
}

.inv-login-why {
  flex: 1 0 100%;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-ink);
}

.btn-icon {
  min-width: 44px;
  padding: 0 10px;
}

.btn-toggle.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.inv-subcard-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.inv-subcard-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.inv-raw-form {
  display: grid;
  grid-template-columns: minmax(120px, 0.9fr) minmax(100px, 0.8fr) minmax(90px, 0.7fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

@media (max-width: 900px) {
  .inv-wifi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .inv-wifi-actions {
    grid-column: 1 / -1;
  }

  .inv-target-bar {
    grid-template-columns: 1fr 1fr;
  }

  .inv-target-actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 639px) {
  .inv-wifi-grid {
    grid-template-columns: 1fr;
  }

  .inv-login-bar {
    grid-template-columns: 1fr;
  }

  .inv-raw-form {
    grid-template-columns: 1fr 1fr;
  }

  .inv-raw-form .btn {
    grid-column: 1 / -1;
  }
}

/* Join code display (v1.5) */
.join-code-box {
  margin-bottom: 16px;
}

.join-code-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
}

.join-code-display {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.1em;
  line-height: 1.2;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--border-strong);
  user-select: all;
}

.join-code-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* v1.10 phone Wi-Fi scan (PROTOCOL 13b) */
.alert-warn {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 600;
  margin: 8px 0;
}
.pws-panel {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface);
}
.pws-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: baseline;
  margin-bottom: 6px;
}
.pws-table { width: 100%; }
.pws-table th { text-align: left; }
.pws-sort {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.pws-sort[aria-pressed="true"] { color: var(--ink); }
.pws-row { cursor: pointer; }
.pws-row:hover, .pws-row:focus { background: var(--surface-hover); outline: none; }
.pws-inverter { background: var(--primary-soft); }
.pws-badge { margin-left: 6px; font-size: 11px; }
.pws-empty { padding: 8px 0; }
.pws-bars {
  display: inline-block;
  width: 14px;
  height: 10px;
  vertical-align: middle;
  background: linear-gradient(to right, var(--primary) 0 var(--pws-fill, 25%), var(--border) var(--pws-fill, 25%) 100%);
  border-radius: 2px;
}
.pws-bars-1 { --pws-fill: 25%; }
.pws-bars-2 { --pws-fill: 50%; }
.pws-bars-3 { --pws-fill: 75%; }
.pws-bars-4 { --pws-fill: 100%; }
.spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: pws-spin 0.8s linear infinite;
  vertical-align: -1px;
}
@keyframes pws-spin { to { transform: rotate(360deg); } }

.brand-logo { display: block; height: 24px; width: auto; }

/* ---- v1.12 step-by-step session flow ---- */
.wz-hide { display: none !important; }
.wz-wrap { margin: 0 0 16px; }
.wz-steps { list-style: none; display: flex; gap: 8px; margin: 0; padding: 0; counter-reset: none; flex-wrap: wrap; }
.wz-step { flex: 1 1 140px; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid #dfe3e8; border-radius: 10px; background: #fff; color: #6b7280; font-size: 14px; }
.wz-step[data-wz-go] { cursor: pointer; }
.wz-step[data-wz-go]:hover { border-color: #0054A6; }
.wz-num { flex: none; width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: #eef1f4; font-weight: 700; color: #4b5563; }
.wz-current { border-color: #0054A6; background: #eef5fc; color: #0f172a; font-weight: 600; }
.wz-current .wz-num { background: #0054A6; color: #fff; }
.wz-done .wz-num { background: #3C8C03; color: #fff; }
.wz-done { color: #374151; }
.wz-help-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.wz-help { margin: 0; font-size: 16px; color: #111827; }
.wz-waiting { display: flex; align-items: center; gap: 14px; }
.wz-spinner { width: 22px; height: 22px; border: 3px solid #dbe4ee; border-top-color: #0054A6; border-radius: 50%; animation: wz-spin 1s linear infinite; flex: none; }
@keyframes wz-spin { to { transform: rotate(360deg); } }
.wz-nav { display: flex; justify-content: space-between; margin: 8px 0 24px; }
.wz-qr { width: 180px; margin-top: 12px; }
.wz-qr svg { width: 100%; height: auto; }
#d-join-code-card .join-code-display { font-size: 40px; letter-spacing: 4px; }
.login-token { margin-top: 16px; font-size: 13px; color: #6b7280; }
.login-token summary { cursor: pointer; margin-bottom: 10px; }
.u-actions { white-space: nowrap; }
.u-actions .btn { margin-right: 6px; }
@media (max-width: 640px) {
  .wz-step .wz-label { display: none; }
  .wz-step { flex: 1 1 0; justify-content: center; }
}
.wz-help-warn { color: #9a3412; background: #fff7ed; border: 1px solid #fed7aa; border-radius: 8px; padding: 8px 12px; }
.wz-ended p { margin: 8px 0 0; }

/* ---- v1.14 Floating WebRTC call panel ---- */
.call-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 420px;
  max-width: calc(100vw - 24px);
  z-index: 60;
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.42);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.call-panel.hidden { display: none; }
.call-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.94);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.call-panel-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
}
.call-panel-meta strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.call-status {
  color: #cbd5e1;
  font-size: 12px;
}
.call-panel-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.call-timer {
  font-size: 12px;
  color: #e2e8f0;
}
.call-fs-btn {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  color: #f8fafc;
  min-height: 28px;
  padding: 2px 8px;
  font-size: 12px;
}
.call-qdot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.call-qdot-good { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25); }
.call-qdot-fair { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25); }
.call-qdot-poor { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.28); }
.call-qdot-idle { background: #94a3b8; }
.call-video-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #020617;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.call-video-stage:fullscreen {
  width: 100vw;
  height: 100vh;
  aspect-ratio: auto;
}
.call-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.call-video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 13px;
  pointer-events: none;
}
.call-video-placeholder.hidden { display: none; }
.call-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.96);
}
.call-ctrl-btn { flex: 1; }
@media (max-width: 639px) {
  .call-panel {
    right: 8px;
    left: 8px;
    bottom: 8px;
    width: auto;
  }
}

/* v1.15 Presence: "Phones online" card */
.presence-card .card-title { display: flex; align-items: center; gap: 8px; }
.presence-empty { padding: 12px 4px; color: var(--muted); font-weight: 600; }
.presence-table td.presence-action { text-align: right; white-space: nowrap; }
.presence-form { display: inline-flex; gap: 6px; align-items: center; }
.presence-form .input { width: 140px; padding: 4px 8px; }
@media (max-width: 720px) {
  .presence-table td.presence-action { text-align: left; }
  .presence-form .input { width: 100%; }
}

/* v1.16 Touch screens: no sticky hover highlight after a tap. */
@media (hover: none) {
  .data-table tbody tr.row-click:hover,
  .pws-row:hover,
  .data-table th.sortable .sort-btn:hover { background: transparent; }
}

/* v1.16 Phone screens (operator mode in the Android app WebView). Desktop unchanged. */
@media (max-width: 480px) {
  /* Header: logo + version + Sign out on one row, nav scrolls sideways below. */
  .topbar-inner { padding: 4px 10px; gap: 0 8px; flex-wrap: wrap; }
  .brand { gap: 6px; font-size: 15px; }
  .brand-name, .user-name, #user-role { display: none; }
  .user-bar { margin-left: auto; flex-wrap: nowrap; }
  .nav { order: 3; flex: 1 0 100%; margin: 0 -10px; padding: 0 6px; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-link { flex: 0 0 auto; padding: 0 10px; }

  .main { padding: 12px 10px 32px; }
  .card { padding: 12px; margin-bottom: 12px; }
  .page-title { font-size: 19px; }

  /* Page head + actions stack; buttons share the full width. */
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .page-actions { width: 100%; }
  .page-actions > .btn, .page-actions > .segmented { flex: 1 1 0; }
  .segmented .seg-btn { flex: 1; }
  .card-head .page-actions { width: auto; }
  .card-head .page-actions > .btn { flex: 0 0 auto; }
  #d-countdown { flex: 1 0 100%; justify-content: center; min-height: 32px; }

  .form-actions .btn, .join-code-actions .btn { flex: 1 1 0; }
  .join-code-row { flex-direction: column; align-items: stretch; }
  .join-code-display { text-align: center; }
  .url-row .btn { flex: 1 1 100%; }
  .pill-btn { flex: 1 1 0; min-width: 0; }

  .kv-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kv-item { padding: 8px 10px; }

  /* Wizard: steps as a vertical list, help + Back/Next full width. */
  .wz-steps { flex-direction: column; gap: 6px; }
  .wz-step { flex: none; justify-content: flex-start; min-height: 44px; padding: 8px 12px; }
  .wz-step .wz-label { display: inline; }
  .wz-help-row { flex-direction: column; align-items: stretch; }
  .wz-help { font-size: 15px; }
  .wz-nav { gap: 10px; }
  .wz-nav .btn { flex: 1 1 0; }
  .wz-qr { margin-left: auto; margin-right: auto; }

  /* Inverter Wi-Fi / login */
  .inv-dropzone { flex-direction: column; align-items: stretch; }
  .inv-wifi-actions .btn, .inv-target-actions .btn { flex: 1 1 0; }
  .inv-login-bar { flex-direction: column; align-items: stretch; }
  .inv-login-bar .inv-field { flex: none; }
  .inv-target-bar { grid-template-columns: 1fr; }

  /* Tables are cards (from the 639px rules); sort select stays on one row. */
  .mobile-sort-bar { flex-wrap: nowrap; }
  .mobile-sort-bar .btn { flex: 0 0 auto; }
  .select-compact { min-height: 44px; }
  .data-table td { min-height: 40px; }
  .presence-table td.presence-action { white-space: normal; }
  .presence-table td.presence-action > .btn { width: 100%; }
  .presence-form { display: flex; flex-wrap: wrap; width: 100%; }
  .presence-form .input { flex: 1 1 100%; width: 100%; min-height: 44px; }
  .presence-form .btn { flex: 1 1 0; }
  .pws-row td { padding-top: 12px; padding-bottom: 12px; }
  .pws-sort { min-height: 44px; }
  .u-actions { white-space: normal; }
  .u-actions .btn { margin: 0 6px 6px 0; }

  /* Inverter panel controls: 44px tap targets. */
  .iv-btn, .iv-tab, .iv-th { min-height: 44px; }
  .iv-pane { overflow-x: auto; }

  .toast { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); text-align: center; }

  /* Call: full screen, video fills it, large Mute / Hang up at the bottom. */
  .call-panel {
    top: 0; right: 0; bottom: 0; left: 0;
    width: 100%; max-width: none;
    height: 100vh; height: 100dvh;
    border: 0; border-radius: 0; box-shadow: none;
  }
  .call-panel-head { flex-wrap: wrap; padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px; }
  .call-panel-meta { font-size: 15px; }
  .call-timer, #call-net-info { font-size: 13px; }
  .call-fs-btn { display: none; }
  .call-video-stage { flex: 1 1 auto; min-height: 0; aspect-ratio: auto; cursor: default; }
  .call-controls { gap: 14px; padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px)); }
  .call-ctrl-btn { min-height: 60px; border-radius: 30px; font-size: 17px; }
}

/* Download app menu (v1.16.1) */
.nav-btn { border: 0; background: transparent; cursor: pointer; font-family: inherit; }
.dl-menu { position: fixed; z-index: 1000; min-width: 210px; padding: 6px; background: var(--surface, #fff); border: 1px solid var(--border, #d9dee5); border-radius: var(--radius-sm, 8px); box-shadow: 0 8px 24px rgba(15, 23, 42, .16); display: flex; flex-direction: column; gap: 2px; }
.dl-menu.hidden { display: none; }
.dl-menu-item { display: flex; align-items: center; min-height: 44px; padding: 0 12px; border: 0; border-radius: var(--radius-sm, 6px); background: transparent; color: var(--ink, #0f172a); font: inherit; font-size: 14px; font-weight: 600; text-align: left; cursor: pointer; text-decoration: none; }
.dl-menu-item:hover, .dl-menu-item:focus-visible { background: var(--primary-soft, #e8f0fb); color: var(--primary, #0b5cad); text-decoration: none; outline: none; }

/* ---- v1.16.2 Simple operator web ---- */
.dot-red { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.btn-lg { min-height: 48px; padding: 0 22px; font-size: 16px; }
body.simple-ui .adv-only,
body.simple-ui #call-net-info { display: none !important; }
.nav-btn.active { color: var(--primary); }
/* Operator Wi-Fi list: signal bars + name only (Security/Band stay for Advanced). */
body.simple-ui .pws-table th:nth-child(n+3),
body.simple-ui .pws-table td:nth-child(n+3) { display: none; }
body.simple-ui .pws-table th:first-child,
body.simple-ui .pws-table td:first-child { width: 48px; }
body.simple-ui .pws-table td { padding-top: 12px; padding-bottom: 12px; }
/* Inverter card: no ms / read-error counters for operators. */
body.simple-ui .iv-meta > span:nth-child(n+2) { display: none; }
.wz-ended .form-actions { margin-top: 12px; }

/* "More" menu: details.more-menu > summary.btn + div.more-pop */
.more-menu { position: relative; display: inline-block; }
.more-menu.hidden { display: none; }
.more-menu > summary { list-style: none; }
.more-menu > summary::-webkit-details-marker { display: none; }
.more-menu > summary::after { content: '\25BE'; margin-left: 6px; font-size: 12px; }
.more-pop { position: absolute; right: 0; top: calc(100% + 4px); z-index: 50; min-width: 220px; padding: 6px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(15, 23, 42, .16); display: flex; flex-direction: column; gap: 2px; }
.more-item { display: flex; align-items: center; min-height: 44px; padding: 0 12px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--ink); font: inherit; font-size: 15px; font-weight: 600; text-align: left; cursor: pointer; }
.more-item:hover:not(:disabled), .more-item:focus-visible { background: var(--primary-soft); outline: none; }
.more-item:disabled { color: var(--muted); opacity: .55; cursor: default; }
.more-item.hidden { display: none; }
.more-danger { color: var(--danger); }

/* Sessions: short list of cards */
.sess-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.sess-card { display: grid; grid-template-columns: minmax(0, 1fr) auto auto 16px; align-items: center; gap: 14px; min-height: 60px; padding: 10px 16px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--ink); text-decoration: none; }
.sess-card:hover { border-color: var(--primary); text-decoration: none; }
.sess-site { font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess-card .status-inline { font-size: 14px; }
.sess-time { min-width: 72px; justify-content: center; }
.sess-go { font-size: 24px; color: var(--muted); line-height: 1; }

/* Phones online: simple list */
.presence-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.presence-item { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 14px; min-height: 56px; padding: 6px 0; border-top: 1px solid var(--border); }
.presence-item:first-child { border-top: 0; }
.presence-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.presence-item .presence-action { text-align: right; }

/* Session page */
.wz-step { cursor: default; }
.wz-wait-line { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-weight: 600; color: var(--muted); }
#d-join-code-card .join-code-row { align-items: center; }
.wz-wrap > .alert-warn, .wz-wrap > .wz-help { margin: 10px 0 0; }
.wz-wrap > .wz-waiting { margin: 10px 0 0; }

@media (max-width: 480px) {
  /* 3 steps fit on one row on a phone */
  .wz-steps { flex-direction: row; gap: 4px; }
  .wz-step { flex: 1 1 0; flex-direction: column; justify-content: center; gap: 4px; padding: 8px 4px; min-height: 64px; text-align: center; font-size: 12px; }
  .wz-step .wz-label { display: block; line-height: 1.2; }

  .sess-card { grid-template-columns: minmax(0, 1fr) auto 12px; grid-template-areas: "site time go" "status time go"; row-gap: 2px; column-gap: 10px; padding: 10px 12px; }
  .sess-site { grid-area: site; }
  .sess-card .status-inline { grid-area: status; }
  .sess-time { grid-area: time; }
  .sess-go { grid-area: go; }

  .presence-item { grid-template-columns: minmax(0, 1fr) auto; }
  .presence-item .presence-action { grid-column: 1 / -1; }
  .presence-item .presence-action > .btn { width: 100%; }

  /* Sticky primary button at the bottom of the screen */
  body.simple-ui .sticky-actions { position: sticky; bottom: 0; z-index: 20; padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px)); background: rgba(255, 255, 255, .96); }
  .page-actions > .more-menu { flex: 0 0 auto; }
  #btn-call { flex: 1 1 0; }
  .page-head .page-actions > #d-countdown { flex: 0 0 auto; min-height: 44px; }
  .page-head .page-actions { flex-wrap: nowrap; }
  .page-title-row { flex-wrap: nowrap; min-width: 0; }
  .page-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* Advanced: long read-error / address chips wrap instead of widening the page. */
  #inv-snap-meta { min-width: 0; max-width: 100%; }
  #inv-snap-meta .chip, #d-scan-meta .chip { white-space: normal; word-break: break-all; }
}
.dl-menu-item.hidden { display: none; }
