.at-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity .25s;
  padding: 16px;
}
.at-overlay-active { opacity: 1; }

.at-modal {
  background: var(--surface, #fff);
  border: 1px solid var(--line, #dbe7ec);
  border-radius: 12px;
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
  overflow: hidden;
}

.at-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line, #dbe7ec);
}
.at-header-left { display: flex; align-items: center; gap: 8px; }
.at-header-left svg { color: var(--accent, #4aa6a2); flex-shrink: 0; }
.at-header-left h3 { margin: 0; font-size: 15px; color: var(--text, #405761); }
.at-close {
  background: none; border: none; font-size: 20px; cursor: pointer;
  color: var(--muted, #7f929b); padding: 2px 6px; border-radius: 6px;
}
.at-close:hover { background: var(--line, #dbe7ec); color: var(--text, #405761); }

.at-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  scrollbar-width: thin;
}
.at-body::-webkit-scrollbar { width: 5px; }
.at-body::-webkit-scrollbar-thumb { background: var(--line-strong, #c8d8df); border-radius: 4px; }

.at-progress-wrap { margin-bottom: 14px; }
.at-progress-bar {
  height: 6px;
  background: var(--line, #dbe7ec);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}
.at-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent, #4aa6a2);
  border-radius: 3px;
  transition: width .3s ease;
}
.at-progress-text { font-size: 12px; color: var(--muted, #7f929b); }

.at-cards { display: flex; flex-direction: column; gap: 10px; }

.at-card {
  border: 1px solid var(--line, #dbe7ec);
  border-radius: 8px;
  overflow: hidden;
}
.at-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--surface-2, #f7fbfc);
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #405761);
  border-bottom: 1px solid var(--line, #dbe7ec);
}
.at-card-body { padding: 10px 12px; font-size: 13px; color: var(--text, #405761); }
.at-card-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.at-card-detail { color: var(--muted, #7f929b); margin-top: 4px; font-size: 12px; }
.at-card-error { color: var(--red, #d45b68); margin-top: 6px; font-size: 12px; }

.at-icon { font-size: 10px; line-height: 1; }
.at-ok { color: var(--green, #42a76f); }
.at-warn { color: var(--yellow, #c99635); }
.at-fail { color: var(--red, #d45b68); }
.at-pending { color: var(--faint, #9aaab1); }

.at-level-bar {
  display: inline-block;
  width: 60px;
  height: 6px;
  background: var(--line, #dbe7ec);
  border-radius: 3px;
  overflow: hidden;
  vertical-align: middle;
  margin-right: 4px;
}
.at-level-fill {
  height: 100%;
  background: var(--green, #42a76f);
  border-radius: 3px;
  transition: width .15s;
}

.at-waveform-wrap { margin-top: 6px; }
.at-waveform {
  width: 100%;
  height: 40px;
  border-radius: 6px;
  background: var(--surface-3, #eef6f8);
}

.at-echo-prompt {
  margin-top: 8px;
  padding: 6px 10px;
  background: var(--accent-soft, #e5f6f4);
  border-radius: 6px;
  font-size: 12px;
  color: var(--accent-strong, #2f7d79);
}

.at-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  margin-top: 6px;
}
.at-stat { display: flex; justify-content: space-between; font-size: 12px; }
.at-stat-label { color: var(--muted, #7f929b); }
.at-stat-value { color: var(--text, #405761); font-weight: 500; }

.at-diagnostics {
  margin-top: 14px;
  border-top: 1px solid var(--line, #dbe7ec);
  padding-top: 12px;
}
.at-diag-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #405761);
  margin-bottom: 8px;
}
.at-diag-item {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text, #405761);
}
.at-diag-item.fail { background: rgba(212,91,104,0.08); }
.at-diag-item.warn { background: rgba(201,150,53,0.08); }
.at-diag-item.ok { background: rgba(66,167,111,0.06); }
.at-diag-item strong { display: block; margin-bottom: 2px; }
.at-diag-item ul { margin: 4px 0 0; padding-left: 16px; }
.at-diag-item li { margin-bottom: 2px; }

.at-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line, #dbe7ec);
}
.at-btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--line, #dbe7ec);
  transition: background .15s, opacity .15s;
}
.at-btn:disabled { opacity: .45; cursor: default; }
.at-btn-primary {
  background: var(--accent, #4aa6a2);
  color: #fff;
  border-color: var(--accent, #4aa6a2);
}
.at-btn-primary:hover:not(:disabled) { background: var(--accent-strong, #2f7d79); }
.at-btn-secondary {
  background: var(--surface-2, #f7fbfc);
  color: var(--text, #405761);
}
.at-btn-secondary:hover:not(:disabled) { background: var(--surface-3, #eef6f8); }

body[data-client-theme="night"] .at-modal { background: #1e293b; border-color: rgba(255,255,255,0.08); }
body[data-client-theme="night"] .at-header { border-color: rgba(255,255,255,0.08); }
body[data-client-theme="night"] .at-header-left h3 { color: #e2e8f0; }
body[data-client-theme="night"] .at-close { color: #94a3b8; }
body[data-client-theme="night"] .at-close:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }
body[data-client-theme="night"] .at-body { color: #cbd5e1; }
body[data-client-theme="night"] .at-progress-bar { background: rgba(255,255,255,0.08); }
body[data-client-theme="night"] .at-card { border-color: rgba(255,255,255,0.08); }
body[data-client-theme="night"] .at-card-header { background: rgba(255,255,255,0.04); color: #e2e8f0; border-color: rgba(255,255,255,0.08); }
body[data-client-theme="night"] .at-card-body { color: #cbd5e1; }
body[data-client-theme="night"] .at-card-detail { color: #94a3b8; }
body[data-client-theme="night"] .at-level-bar { background: rgba(255,255,255,0.08); }
body[data-client-theme="night"] .at-waveform { background: rgba(255,255,255,0.04); }
body[data-client-theme="night"] .at-echo-prompt { background: rgba(74,166,162,0.12); color: #5ec4be; }
body[data-client-theme="night"] .at-stat-label { color: #94a3b8; }
body[data-client-theme="night"] .at-stat-value { color: #e2e8f0; }
body[data-client-theme="night"] .at-diagnostics { border-color: rgba(255,255,255,0.08); }
body[data-client-theme="night"] .at-diag-title { color: #e2e8f0; }
body[data-client-theme="night"] .at-diag-item { color: #cbd5e1; }
body[data-client-theme="night"] .at-diag-item.fail { background: rgba(212,91,104,0.12); }
body[data-client-theme="night"] .at-diag-item.warn { background: rgba(201,150,53,0.12); }
body[data-client-theme="night"] .at-diag-item.ok { background: rgba(66,167,111,0.1); }
body[data-client-theme="night"] .at-footer { border-color: rgba(255,255,255,0.08); }
body[data-client-theme="night"] .at-btn { border-color: rgba(255,255,255,0.1); }
body[data-client-theme="night"] .at-btn-secondary { background: rgba(255,255,255,0.06); color: #cbd5e1; }
body[data-client-theme="night"] .at-btn-secondary:hover:not(:disabled) { background: rgba(255,255,255,0.1); }

body[data-client-theme="night"] .at-overlay { background: rgba(0,0,0,0.7); }

body.mobile-layout #audioTestButton {
  position: static;
  width: 100%;
  min-width: 0;
  max-width: none;
  height: 32px;
  min-height: 0;
  max-height: none;
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  z-index: auto;
}

body.mobile-layout .room-head:has(#roomProfileButton[hidden]) #audioTestButton {
  right: auto;
}

.at-device-selectors {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.at-device-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.at-device-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #405761);
  min-width: 70px;
  flex-shrink: 0;
}
.at-device-select {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--line, #dbe7ec);
  border-radius: 6px;
  background: var(--surface, #fff);
  color: var(--text, #405761);
  font-size: 12px;
  cursor: pointer;
  outline: none;
  min-width: 0;
}
.at-device-select:focus { border-color: var(--accent, #4aa6a2); }
body[data-client-theme="night"] .at-device-select { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.1); color: #cbd5e1; }
body[data-client-theme="night"] .at-device-label { color: #e2e8f0; }

.at-confirm-area {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line, #dbe7ec);
  border-radius: 8px;
  background: var(--surface-2, #f7fbfc);
}
.at-confirm-text {
  font-size: 13px;
  color: var(--text, #405761);
  margin-bottom: 10px;
  line-height: 1.5;
}
.at-confirm-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.at-btn-confirm-yes {
  background: var(--green, #42a76f);
  color: #fff;
  border: 1px solid var(--green, #42a76f);
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.at-btn-confirm-yes:hover { background: #36905d; }
.at-btn-confirm-no {
  background: var(--surface-3, #eef6f8);
  color: var(--text, #405761);
  border: 1px solid var(--line, #dbe7ec);
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.at-btn-confirm-no:hover { background: var(--line, #dbe7ec); }

body[data-client-theme="night"] .at-confirm-area { background: rgba(255,255,255,0.04); border-color: rgba(255,255,255,0.08); }
body[data-client-theme="night"] .at-confirm-text { color: #cbd5e1; }
body[data-client-theme="night"] .at-btn-confirm-no { background: rgba(255,255,255,0.06); color: #cbd5e1; border-color: rgba(255,255,255,0.1); }
body[data-client-theme="night"] .at-btn-confirm-no:hover { background: rgba(255,255,255,0.1); }

@media (max-width: 480px) {
  .at-modal { max-height: 90vh; border-radius: 10px; }
  .at-stats-grid { grid-template-columns: 1fr; }
}
