:root {
  --bg-dark: #0a0a0a;
  --bg-surface: #161618;
  --bg-surface-2: #212124;

  --text-primary: #f2f2f2;
  --text-secondary: #a0a0a0;

  /* Stable Blue Accent */
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;

  --danger-color: #ef4444;
  --danger-hover: #dc2626;

  --success-color: #10b981;

  --font-main: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", monospace;
}

body {
  margin: 0;
  font-family: var(--font-main);
  background-color: var(--bg-dark);
  background-image: radial-gradient(circle at 50% 0%, #1f2937 0%, #0a0a0a 70%);
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body.waiting-page {
  min-height: 100vh;
  height: auto;
  overflow-y: auto;
  align-items: flex-start;
}

body.waiting-page #app {
  min-height: 100vh;
  height: auto;
  justify-content: flex-start;
}

#app {
  width: 100%;
  max-width: 420px;
  padding: 16px;
  /* Reduced from 24px */
  position: relative;
  box-sizing: border-box;
  height: 100vh;
  /* Full height */
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* Center vertically */
}

/* Card Styling */
.card {
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  padding: 24px 20px;
  /* Reduced from 40px 30px */
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

h1,
h2,
h3 {
  margin: 0 0 0.5rem 0;
}

/* Tighter margins */
h2 {
  margin-bottom: 1rem;
  font-size: 1.5rem;
}

/* Smaller h2 */

.pulse-ring {
  width: 40px;
  /* Smaller ring */
  height: 40px;
  margin: 0 auto 15px;
  /* Reduced margin */
}

/* Token Display Compact */
.token-display {
  margin: 15px 0;
  /* Reduced from 30px */
  padding: 10px;
  /* Reduced from 20px */
}

#my-token {
  font-size: 2.5rem;
  /* Reduced from 3.5rem */
}

/* QR Code Canvas Size Control */
#qrcode {
  width: 150px !important;
  height: 150px !important;
  margin-top: 10px !important;
}

p {
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Inputs */
input {
  background: var(--bg-surface-2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-radius: 12px;
  padding: 16px;
  width: 100%;
  box-sizing: border-box;
  font-size: 1.1rem;
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  font-family: var(--font-mono);
  /* Monospace numbers */
  letter-spacing: 2px;
}

input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

/* Buttons */
button {
  border: none;
  cursor: pointer;
  font-family: var(--font-main);
  font-weight: 600;
  transition: all 0.2s ease;
}

.primary-btn {
  background: var(--primary-color);
  color: white;
  width: 100%;
  padding: 18px;
  border-radius: 16px;
  font-size: 1.1rem;
  margin-bottom: 1rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.primary-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.primary-btn:active {
  transform: scale(0.98);
}

.secondary-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  width: 100%;
  padding: 16px;
  border-radius: 16px;
  font-size: 1.1rem;
  margin-top: 1rem;
}

.secondary-btn:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.03);
}

.divider {
  margin: 20px 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.divider::before,
.divider::after {
  content: "";
  display: block;
  height: 1px;
  width: 30px;
  background: rgba(255, 255, 255, 0.1);
}

/* Token Display */
.token-display {
  margin: 30px 0;
  padding: 20px;
  background: var(--bg-surface-2);
  border-radius: 16px;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.token-label {
  display: block;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

#my-token {
  font-family: var(--font-mono);
  font-size: 3.5rem;
  margin: 0;
  color: var(--primary-color);
  letter-spacing: 4px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
}

.modal-content {
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 40px;
  border-radius: 24px;
  text-align: center;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.pulse-ring {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--primary-color);
  margin: 0 auto 30px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
  animation: pulse-blue 2s infinite;
}

.pulse-ring::before,
.pulse-ring::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: inherit;
  opacity: 0.6;
  z-index: -1;
  animation: ripple 2s infinite cubic-bezier(0, 0.2, 0.8, 1);
}

.pulse-ring::after {
  animation-delay: 1s;
}

@keyframes ripple {
  0% {
    transform: scale(1);
    opacity: 0.6;
  }

  100% {
    transform: scale(2.5);
    opacity: 0;
  }
}

@keyframes pulse-blue {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
  }

  70% {
    transform: scale(1);
    box-shadow: 0 0 0 20px rgba(59, 130, 246, 0);
  }

  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
  }
}

.modal-buttons {
  display: flex;
  gap: 15px;
  margin-top: 30px;
}

.modal-btn {
  flex: 1;
  padding: 15px;
  border-radius: 12px;
  font-weight: 600;
}

.modal-btn.answer {
  background: var(--success-color);
  color: white;
}

.modal-btn.decline {
  background: var(--bg-surface-2);
  color: var(--text-secondary);
}

/* Status Bar */
#waiting-screen {
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.status-bar {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.5);
  padding: 8px 16px;
  border-radius: 50px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(5px);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
}

.status-dot.connected {
  background: var(--success-color);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
}

.status-dot.disconnected {
  background: var(--danger-color);
}

/* Video Interface */
/* Video Interface */
/* Video Interface */
.video-container {
  width: 100%;
  height: 100vh;
  background: black;
  position: fixed;
  /* Use fixed to guarantee full screen */
  top: 0;
  left: 0;
  z-index: 100;
  display: block;
  /* Default to block, rely on inner sections */
  overflow: hidden;
}

#remote-video,
#local-video {
  position: static;
  height: auto;
  width: auto;
  border: none;
}

#remote-video,
#local-video {
  position: static;
  height: auto;
  width: auto;
  border: none;
}



/* Sketch Layout */
.top-section {
  width: 100%;
  height: 55%;
  position: relative;
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.bottom-section {
  width: 100%;
  height: 45%;
  display: flex;
  flex-direction: row;
}

.local-video-wrapper {
  flex: 1;
  position: relative;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.controls-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 15px;
  padding: 10px;
  background: #1a1a1a;
}

.toggles-row {
  display: flex;
  gap: 20px;
}

/* Video Elements */
#remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#local-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 0;
  background: #222;
}

/* Overrides */
.swipe-container {
  max-width: 90%;
  transform: scale(0.9);
  /* Slightly smaller in this layout if needed */
}




/* Updated Control Buttons */
.control-btn.icon-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(255, 255, 255, 0.2);
  /* Glassy */
  backdrop-filter: blur(10px);
  color: white;
  border: none;
  transition: all 0.2s ease;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.control-btn.icon-btn.success {
  background: #10b981;
  /* Green Camera */
}

.control-btn.icon-btn.primary {
  background: #3b82f6;
  /* Blue Mic */
}

.control-btn.icon-btn.danger {
  background: #ef4444;
  /* Red Hangup */
  width: 70px;
  height: 70px;
  /* Slightly larger */
}

.control-btn.icon-btn:active {
  transform: scale(0.95);
}

/* Swipe Slider */
.swipe-container {
  position: relative;
  width: 100%;
  max-width: 320px;
  height: 64px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(5px);
  border-radius: 32px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  /* Prevent scroll while swiping */
}

.swipe-text {
  position: absolute;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: rgba(255, 255, 255, 0.6);
  font-weight: 500;
  font-size: 1.1rem;
  pointer-events: none;
  text-transform: lowercase;
}

.swipe-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 0%;
  /* Animates */
  height: 100%;
  background: var(--primary-color);
  transition: width 0.1s linear;
}

.swipe-handle {
  position: absolute;
  top: 4px;
  left: 4px;
  /* Start padding */
  width: 56px;
  height: 56px;
  background: white;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--primary-color);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  cursor: grab;
  transition: transform 0.1s linear;
}

.swipe-handle:active {
  cursor: grabbing;
  transform: scale(0.95);
}

.swipe-container.unlocked .swipe-bg {
  width: 100% !important;
  transition: width 0.3s ease;
  background: var(--success-color);
}

.swipe-container.unlocked .swipe-text {
  content: "unlocked";
  color: white;
}

.swipe-container.unlocked .swipe-handle {
  color: var(--success-color);
}

/* Scanner Styles */
.scanner-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.header-actions {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 20px;
  margin-bottom: 20px;
}

.header-actions h2 {
  margin: 0;
}

#reader {
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.1);
  background: black;
}

#result-container {
  width: 100%;
  margin-top: 20px;
  padding: 20px;
  background: var(--bg-surface-2);
  border-radius: 16px;
  border: 1px solid var(--success-color);
}

.scanned-text {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  color: var(--success-color);
  word-break: break-all;
  margin: 20px 0;
}

/* QR entry and waiting URL */
.qr-request-card,
.qr-invite-card {
  gap: 12px;
}

.secondary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  text-decoration: none;
}

.qr-code-surface {
  align-self: center;
  padding: 12px;
  background: #fff;
  border-radius: 16px;
}

#request-qrcode {
  display: block;
  max-width: 100%;
  height: auto !important;
}

.url-value {
  margin: 0;
  color: var(--primary-color);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.text-small {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.guest-url-panel {
  width: 100%;
  margin: 8px 0;
  text-align: left;
}

.call-details {
  width: 100%;
  margin: 16px 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.28);
  text-align: left;
}

.call-details summary {
  padding: 13px 16px;
  color: var(--text-primary);
  cursor: pointer;
  font-weight: 700;
}

.call-details summary:focus-visible {
  outline: 3px solid rgba(96, 165, 250, 0.65);
  outline-offset: -3px;
}

.call-details-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0 16px 14px;
}

.call-details-list div {
  min-width: 0;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
}

.call-details-list dt {
  color: var(--text-secondary);
  font-size: 0.78rem;
}

.call-details-list dd {
  margin: 5px 0 0;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

@media (max-width: 420px) {
  .call-details-list { grid-template-columns: 1fr; }
}

.guest-url-panel label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.guest-url-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.guest-url-row input {
  min-width: 0;
  text-align: left;
  letter-spacing: 0;
  font-size: 0.85rem;
  padding: 12px;
}

.copy-btn {
  flex: 0 0 auto;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--primary-color);
  color: #fff;
}

.copy-btn:focus-visible,
.secondary-link:focus-visible,
.qr-request-card button:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.45);
  outline-offset: 2px;
}

@media (max-width: 420px) {
  .guest-url-row {
    flex-direction: column;
  }

  .copy-btn {
    min-height: 48px;
  }
}

/* Admin monitor */
.admin-page {
  align-items: flex-start;
  overflow: auto;
}

#admin-app {
  width: 100%;
  max-width: 1440px;
  min-height: 100vh;
  height: auto;
  padding: 18px 20px 28px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-header,
.admin-section-heading,
.admin-key-row,
.admin-actions {
  display: flex;
  align-items: center;
}

.admin-header,
.admin-section-heading {
  justify-content: space-between;
  gap: 12px;
}

.admin-header h1,
.admin-header p,
.admin-section h2,
.admin-section p,
.admin-login h2,
.admin-login p {
  margin-top: 0;
}

.admin-header h1 {
  margin-bottom: 4px;
  font-size: clamp(1.5rem, 3vw, 2.15rem);
}

.admin-eyebrow {
  margin-bottom: 4px;
  color: var(--primary-color);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.admin-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.admin-action-btn {
  width: auto;
  min-height: 40px;
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
}

.admin-login {
  gap: 0;
  padding: 10px 14px;
  border-radius: 16px;
  text-align: left;
}

.admin-login-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-login-summary h2 {
  margin-bottom: 2px;
  font-size: 1rem;
}

.admin-login-summary p {
  margin-bottom: 0;
}

.admin-key-panel {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.admin-key-row {
  gap: 8px;
}

.admin-key-row input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  text-align: left;
  letter-spacing: 0;
}

.admin-message {
  min-height: 0;
  margin: 8px 0 0;
  color: var(--success-color);
}

.admin-message:empty {
  display: none;
}

.admin-message.is-error {
  color: var(--danger-color);
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.admin-stat {
  min-height: 76px;
  box-sizing: border-box;
  padding: 14px 16px;
  border-radius: 14px;
  justify-content: space-between;
  text-align: left;
}

.admin-stat span {
  color: var(--text-secondary);
  font-size: 0.78rem;
}

.admin-stat strong {
  color: var(--primary-color);
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 500;
}

.admin-section {
  min-width: 0;
  padding: 14px 16px;
  border-radius: 16px;
  text-align: left;
}

.admin-section-heading {
  margin-bottom: 8px;
}

.admin-section-heading h2 {
  margin-bottom: 2px;
  font-size: 1.1rem;
}

.admin-section-heading p {
  margin-bottom: 0;
}

.admin-badge,
.status-chip {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  font-size: 0.72rem;
  white-space: nowrap;
}

.status-in-call,
.status-connected {
  background: rgba(16, 185, 129, 0.18);
  color: var(--success-color);
}

.status-waiting,
.status-created {
  background: rgba(59, 130, 246, 0.18);
  color: var(--primary-color);
}

.status-connecting,
.status-signaling {
  background: rgba(234, 179, 8, 0.18);
  color: #eab308;
}

.admin-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  min-width: 700px;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.admin-table th,
.admin-table td {
  padding: 7px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
  vertical-align: top;
  line-height: 1.3;
}

.admin-table th {
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.admin-table code {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.74rem;
}

.admin-table .text-small {
  font-size: 0.72rem;
  line-height: 1.2;
}

.user-agent-cell {
  max-width: 260px;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.admin-empty {
  padding: 18px 10px !important;
  color: var(--text-secondary);
  text-align: center !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 760px) {
  #admin-app {
    padding: 14px 10px 24px;
  }

  .admin-header,
  .admin-section-heading,
  .admin-key-row {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-actions {
    justify-content: flex-start;
  }

  .admin-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-key-row .admin-action-btn {
    width: 100%;
    min-height: 44px;
  }

  .admin-login-summary {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-login-summary .admin-action-btn {
    width: 100%;
    min-height: 44px;
  }
}

@media (max-width: 420px) {
  .admin-stats {
    grid-template-columns: 1fr;
  }

  .admin-stat {
    min-height: 76px;
  }
}

/* Tablet / Desktop Optimization */
@media (min-width: 768px) {
  #app {
    max-width: 768px;
  }

  .card {
    padding: 60px 40px;
  }

  h1 {
    font-size: 3rem;
  }

  h2 {
    font-size: 2.5rem;
  }

  input {
    font-size: 2rem;
    letter-spacing: 4px;
    padding: 24px;
  }

  .primary-btn,
  .secondary-btn {
    font-size: 1.25rem;
    padding: 24px;
  }

  #my-token {
    font-size: 6rem;
  }

  .video-container {
    max-height: 80vh;
    border-width: 8px;
  }

  /* Reset Tablet Override for Local Video since we want split everywhere */
  /* Reset Tablet Override for Local Video since we want split everywhere */
  #local-video {
    /* height: 50%; <- This was causing the issue */
    height: 100%;
    /* Ensure it fills the wrapper */
    bottom: auto;
    right: auto;
  }
}

/* One-way video intercom call screen */
.video-container {
  --call-surface: #10101f;
  --call-control: #20222b;
  width: min(100%, 420px);
  height: 100dvh;
  max-height: 860px;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  box-sizing: border-box;
  padding: max(18px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background: var(--call-surface);
  border: 1px solid rgba(59, 130, 246, 0.28);
  border-radius: clamp(0px, 3vw, 24px);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.58);
  color: #f6f7fb;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.call-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  color: #d8d9e1;
  font-size: 0.86rem;
  font-weight: 600;
}

.call-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success-color);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.55);
}

.video-container .top-section {
  width: 100%;
  height: clamp(210px, 37dvh, 330px);
  margin-top: 4px;
  border: 0;
  border-radius: 18px;
  background: #0c0d19;
  overflow: hidden;
}

.video-container #remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 180ms ease;
}

.caller-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: auto;
  width: 104px;
  height: 104px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.3);
}

.video-state-label {
  position: absolute;
  inset: auto 16px 14px;
  margin: 0;
  color: rgba(255, 255, 255, 0.58);
  font-size: 0.82rem;
  text-align: center;
}

body.remote-video-visible #remote-video {
  opacity: 1;
}

body.remote-video-visible .caller-placeholder,
body.remote-video-visible .video-state-label {
  opacity: 0;
  pointer-events: none;
}

.call-duration {
  display: block;
  margin: 14px auto 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.video-container .bottom-section {
  width: 100%;
  height: auto;
  display: block;
}

.video-container .local-video-wrapper {
  display: none;
}

.video-container .controls-area {
  display: flex;
  gap: 14px;
  padding: 0;
  background: transparent;
}

.video-container .toggles-row {
  display: flex;
  justify-content: center;
  gap: clamp(36px, 14vw, 66px);
  width: 100%;
}

.video-container .control-btn.icon-btn {
  position: relative;
  width: 56px;
  height: 56px;
  margin-bottom: 31px;
  background: var(--call-control);
  box-shadow: none;
  color: #f4f5f8;
}

.video-container #camera-btn::after,
.video-container #mute-btn::after,
.video-container #disconnect-btn::after {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
}

.video-container #camera-btn::after { content: "開啟影像"; }
.video-container #camera-btn.is-active::after { content: "關閉影像"; }
.video-container #mute-btn::after { content: "麥克風"; }
.video-container #mute-btn.muted::after { content: "取消靜音"; }

.video-container .control-btn.icon-btn.danger,
.video-container #disconnect-btn {
  width: 70px;
  height: 70px;
  margin: 0 auto 31px;
  background: #d71826;
}

.video-container #disconnect-btn::after { content: "掛斷"; }

.video-container .swipe-container {
  order: 3;
  width: 100%;
  max-width: none;
  height: 72px;
  transform: none;
  border-radius: 999px;
  background: linear-gradient(180deg, #0cb259, #008c45);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 8px 24px rgba(0, 143, 70, 0.25);
}

.video-container .swipe-text {
  color: white;
  font-size: clamp(1.4rem, 7vw, 2rem);
  font-weight: 750;
  letter-spacing: 0.05em;
  text-transform: none;
}

.video-container .swipe-bg,
.video-container .swipe-handle {
  display: none;
}

.video-container.caller-view #camera-btn,
.video-container.caller-view .swipe-container {
  display: none;
}

.video-container.caller-view .toggles-row {
  justify-content: center;
}

button:focus-visible,
.swipe-container:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 3px;
}

@media (orientation: landscape) and (max-height: 660px) {
  .video-container {
    max-width: 760px;
    display: grid !important;
    grid-template-columns: minmax(220px, 1.15fr) minmax(220px, 0.85fr);
    grid-template-rows: auto 1fr;
    column-gap: 22px;
  }

  .call-status { grid-column: 1 / -1; }
  .video-container .top-section { grid-row: 2; height: 100%; min-height: 220px; }
  .call-duration { position: absolute; top: 24px; right: 24px; margin: 0; }
  .video-container .bottom-section { grid-column: 2; grid-row: 2; align-self: center; }
}

@media (prefers-reduced-motion: reduce) {
  .video-container #remote-video { transition: none; }
}

/* Phone portrait: remote video is always the first, topmost region. */
@media (orientation: portrait) {
  .video-container {
    flex-direction: column;
    padding: 0 14px max(14px, env(safe-area-inset-bottom));
  }

  .video-container .call-status {
    position: absolute;
    z-index: 2;
    top: max(12px, env(safe-area-inset-top));
    left: 14px;
    min-height: 30px;
    padding: 0 12px;
    border-radius: 999px;
    background: rgba(7, 8, 15, 0.72);
    backdrop-filter: blur(8px);
  }

  .video-container .top-section {
    order: 0;
    flex: 0 0 clamp(260px, 45dvh, 390px);
    width: calc(100% + 28px);
    height: auto;
    margin: 0 -14px;
    border-radius: 0 0 18px 18px;
  }

  .video-container .call-duration {
    order: 1;
  }

  .video-container .bottom-section {
    order: 2;
  }
}

/* Control center workspace */
.control-center {
  --admin-border: rgba(255, 255, 255, 0.1);
  --admin-surface: rgba(22, 22, 24, 0.88);
  --admin-surface-raised: rgba(33, 33, 36, 0.78);
  max-width: 1480px;
  gap: 18px !important;
}

.control-center > .card { padding: 18px; }
.control-center > .admin-stats .admin-stat { padding: 14px 16px; }
.control-center > .access-panel { padding: 12px 16px; }

.dashboard-header {
  padding: 8px 4px 0;
}

.dashboard-header h1 {
  letter-spacing: -0.03em;
}

.server-status,
.muted-label,
.section-kicker,
.input-hint,
.limit-note {
  color: var(--text-secondary);
  font-size: 0.76rem;
}

.server-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--admin-border);
  border-radius: 999px;
  padding: 9px 12px;
  white-space: nowrap;
}

.server-status .status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.server-status .status-dot.connected { background: var(--success-color); box-shadow: 0 0 12px rgba(16, 185, 129, 0.75); }
.server-status .status-dot.disconnected { background: var(--danger-color); }

.dashboard-nav {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding: 4px;
  border: 1px solid var(--admin-border);
  border-radius: 14px;
  background: rgba(16, 16, 18, 0.72);
  scrollbar-width: thin;
}

.dashboard-tab {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.86rem;
  white-space: nowrap;
}

.dashboard-tab:hover,
.dashboard-tab:focus-visible,
.dashboard-tab.is-active {
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.14);
  color: var(--text-primary);
}

.dashboard-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

/* The display declaration above would otherwise override the native hidden attribute. */
.dashboard-section[hidden] {
  display: none !important;
}

.section-title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 4px 0;
}

.section-title-row h2,
.section-title-row p,
.section-kicker {
  margin-top: 0;
}

.section-title-row h2 {
  margin-bottom: 3px;
  font-size: clamp(1.45rem, 2.6vw, 2rem);
  letter-spacing: -0.025em;
}

.section-kicker {
  margin-bottom: 5px;
  color: var(--primary-color);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.13em;
}

.section-title-row .text-small { margin-bottom: 0; }

.split-grid,
.maintenance-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  min-width: 0;
}

.admin-section,
.settings-card,
.report-summary,
.maintenance-card {
  background: var(--admin-surface);
  border-color: var(--admin-border);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.22);
}

.admin-section h3,
.settings-card h3,
.maintenance-card h3 {
  margin-bottom: 4px;
  font-size: 1.02rem;
}

.admin-section-heading,
.settings-card-heading {
  align-items: flex-start;
}

.settings-card-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.settings-card-heading p { margin: 0; }

.settings-icon {
  color: var(--primary-color);
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.form-grid,
.auth-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  text-align: left;
}

.form-grid label,
.auth-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-primary);
  font-size: 0.86rem;
  font-weight: 600;
}

.form-grid input,
.form-grid textarea,
.auth-grid input,
.filter-row select {
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--admin-border);
  border-radius: 10px;
  box-sizing: border-box;
  background: var(--bg-surface-2);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  letter-spacing: 0;
}

.form-grid textarea {
  min-height: 88px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.form-grid input:focus,
.form-grid textarea:focus,
.auth-grid input:focus,
.filter-row select:focus {
  border-color: var(--primary-color);
  outline: 3px solid rgba(59, 130, 246, 0.16);
}

.full-field { grid-column: 1 / -1; }

.input-hint {
  display: block;
  min-height: 1em;
  font-weight: 400;
  line-height: 1.25;
}

.switch-field {
  position: relative;
  display: grid !important;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px !important;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--admin-border);
  border-radius: 10px;
  background: var(--bg-surface-2);
}

.switch-field strong,
.switch-field small { display: block; }
.switch-field small { margin-top: 3px; color: var(--text-secondary); font-size: 0.73rem; font-weight: 400; line-height: 1.35; }
.switch-field input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-ui { width: 42px; height: 24px; border-radius: 999px; background: #4b4b51; transition: background 160ms ease; }
.switch-ui::after { display: block; width: 18px; height: 18px; margin: 3px; border-radius: 50%; background: #fff; content: ""; transition: transform 160ms ease; }
.switch-field input:checked + .switch-ui { background: var(--primary-color); }
.switch-field input:checked + .switch-ui::after { transform: translateX(18px); }
.switch-field input:focus-visible + .switch-ui { outline: 3px solid rgba(59, 130, 246, 0.4); outline-offset: 3px; }

.access-panel { text-align: left; }
.auth-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; }
.auth-grid .admin-action-btn { width: 100%; min-height: 42px; margin: 0; }
.auth-api-key { grid-column: span 1; }

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.form-actions .admin-action-btn { min-width: 120px; }
.inline-message { min-height: 1.2em; margin: 0; color: var(--success-color); font-size: 0.84rem; }
.inline-message.is-error { color: var(--danger-color); }

.limit-note {
  margin: 15px 0;
  padding: 10px 12px;
  border: 1px dashed rgba(59, 130, 246, 0.35);
  border-radius: 9px;
  background: rgba(59, 130, 246, 0.08);
  line-height: 1.45;
}

.report-summary { min-height: 190px; justify-content: flex-start; text-align: left; }
.report-summary > strong { margin: 12px 0 5px; font-family: var(--font-mono); font-size: 2.4rem; letter-spacing: 0.06em; }
.report-status.passed { color: var(--success-color); }
.report-status.failed { color: var(--danger-color); }
.report-status.running { color: var(--primary-color); font-size: clamp(1.55rem, 4vw, 2.4rem); letter-spacing: 0; }
.report-bar { width: 100%; height: 5px; margin: 18px 0; overflow: hidden; border-radius: 999px; background: var(--bg-surface-2); }
.report-bar span { display: block; width: 100%; height: 100%; background: var(--text-secondary); }
.report-bar span.is-pass { background: var(--success-color); }
.report-bar span.is-fail { background: var(--danger-color); }
.report-bar span.is-running { background: var(--primary-color); }

.filter-row { display: flex; align-items: center; gap: 8px; }
.filter-row select { min-height: 40px; color: var(--text-primary); }

.maintenance-card { display: flex; align-items: flex-start; gap: 16px; min-height: 180px; text-align: left; }
.maintenance-card p { margin: 0 0 14px; }
.warning-mark { display: grid; flex: 0 0 36px; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: rgba(239, 68, 68, 0.16); color: var(--danger-color); font-family: var(--font-mono); font-weight: 700; }
.danger-btn { border: 1px solid rgba(239, 68, 68, 0.38); border-radius: 10px; background: rgba(239, 68, 68, 0.12); color: #fca5a5; }
.danger-btn:hover { border-color: var(--danger-color); background: rgba(239, 68, 68, 0.2); color: #fff; }
.definition-list { margin: 18px 0; }
.definition-list div { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--admin-border); }
.definition-list dt { color: var(--text-secondary); }
.definition-list dd { margin: 0; color: var(--text-primary); font-family: var(--font-mono); font-size: 0.8rem; text-align: right; }

.kick-client-btn { padding: 6px 9px; font-size: 0.75rem; }
.compact-table { min-width: 520px; }
.data-table { min-width: 760px; }
.data-table td { max-width: 280px; }
.data-table td:last-child { white-space: nowrap; }

@media (max-width: 900px) {
  .auth-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-api-key { grid-column: 1 / 2; }
  .auth-grid .admin-action-btn { grid-column: 2 / 3; }
}

@media (max-width: 700px) {
  .control-center { gap: 12px !important; }
  .dashboard-header,
  .section-title-row { align-items: flex-start; flex-direction: column; }
  .dashboard-header .admin-actions { width: 100%; justify-content: flex-start; }
  .dashboard-header .admin-action-btn { flex: 1; }
  .admin-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-grid,
  .maintenance-grid,
  .form-grid,
  .auth-grid { grid-template-columns: 1fr; }
  .auth-api-key,
  .auth-grid .admin-action-btn { grid-column: auto; }
  .form-actions { align-items: stretch; flex-direction: column-reverse; }
  .form-actions .admin-action-btn { width: 100%; }
  .filter-row { width: 100%; }
  .filter-row select { flex: 1; }
  .section-title-row .muted-label { align-self: flex-start; }

  .data-table,
  .data-table thead,
  .data-table tbody,
  .data-table tr,
  .data-table td { display: block; }
  .data-table { min-width: 0; }
  .data-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .data-table tr { margin-bottom: 10px; padding: 8px; border: 1px solid var(--admin-border); border-radius: 11px; background: rgba(33, 33, 36, 0.45); }
  .data-table tr:last-child { margin-bottom: 0; }
  .data-table td { display: grid; grid-template-columns: minmax(76px, 0.42fr) 1fr; gap: 10px; max-width: none; padding: 7px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
  .data-table td::before { color: var(--text-secondary); content: attr(data-label); font-size: 0.72rem; font-weight: 600; text-transform: uppercase; }
  .data-table td:last-child { border-bottom: 0; white-space: normal; }
  .data-table td[colspan] { display: block; border: 0; text-align: center; }
  .data-table td[colspan]::before { content: none; }
}

@media (max-width: 420px) {
  .admin-stats { grid-template-columns: 1fr 1fr; gap: 6px; }
  .admin-stat { min-height: 72px; padding: 12px; }
  .admin-stat strong { font-size: 1.45rem; }
  .dashboard-tab { padding-inline: 12px; }
  .admin-section,
  .settings-card,
  .report-summary,
  .maintenance-card { padding: 13px; }
}

/* Contact List Styles */
.contacts-card {
  height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.contact-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 4px;
  /* Space for scrollbar */
}

.contact-item {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  padding: 12px;
  border-radius: 12px;
  transition: background 0.2s;
}

.contact-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.avatar {
  width: 48px;
  height: 48px;
  background: var(--primary-color);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  margin-right: 16px;
  color: white;
  font-size: 1.1rem;
}

.contact-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.contact-name {
  font-size: 1.1rem;
  font-weight: 500;
}

.contact-status {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.5);
}

.control-btn.small-btn {
  width: 40px;
  height: 40px;
  padding: 8px;
}

.control-btn.small-btn svg {
  width: 20px;
  height: 20px;
}

/* Resident directory and mobile-first QR call flow */
#app.resident-app {
  width: min(100%, 640px);
  max-width: 640px;
  min-height: 100vh;
  height: auto;
  justify-content: flex-start;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.resident-page {
  align-items: flex-start;
  overflow: auto;
}

.resident-page [hidden] {
  display: none !important;
}

.resident-directory-card,
.calling-card {
  width: 100%;
  box-sizing: border-box;
  gap: 12px;
  text-align: left;
}

.resident-directory-card {
  justify-content: flex-start;
}

.section-kicker {
  margin: 0;
  color: var(--primary-color);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.resident-directory-card h1,
.calling-card h1 {
  margin-bottom: 0;
}

.resident-directory-card .text-small,
.calling-card .text-small {
  margin: 0;
}

.resident-status {
  margin: 4px 0 2px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.resident-status.is-loading {
  color: var(--primary-color);
}

.resident-status.is-error {
  color: #fca5a5;
}

.resident-status.is-empty {
  color: var(--text-secondary);
}

.resident-list {
  display: grid;
  gap: 10px;
  width: 100%;
  margin: 4px 0;
}

.resident-card {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 76px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--text-primary);
  text-align: left;
}

.resident-card:hover,
.resident-card:focus-visible {
  border-color: rgba(59, 130, 246, 0.75);
  background: rgba(59, 130, 246, 0.12);
}

.resident-card:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.35);
  outline-offset: 2px;
}

.resident-avatar {
  display: grid;
  flex: 0 0 44px;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: 12px;
  border-radius: 14px;
  background: rgba(59, 130, 246, 0.18);
  color: #bfdbfe;
  font-size: 1.15rem;
  font-weight: 700;
}

.resident-card-content {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 3px;
}

.resident-card-content strong,
.resident-card-content span,
.resident-card-content small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resident-card-content strong {
  font-size: 1rem;
}

.resident-card-content span,
.resident-card-content small {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.resident-card-content small {
  color: #737373;
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.resident-arrow {
  flex: 0 0 auto;
  margin-left: 10px;
  color: var(--primary-color);
  font-size: 1.7rem;
  line-height: 1;
}

.calling-card {
  justify-content: center;
  min-height: min(560px, calc(100vh - 48px));
  text-align: center;
}

.calling-card .guest-url-panel {
  margin-top: 8px;
}

.calling-card .guest-url-panel label {
  text-align: left;
}

.calling-resident {
  margin: 0;
  color: var(--text-primary);
  font-size: 1.05rem;
  font-weight: 700;
}

.calling-card .guest-url-row {
  text-align: left;
}

.calling-card .guest-url-row input {
  min-height: 48px;
}

.calling-card .copy-btn {
  min-height: 48px;
}

.call-ended-screen {
  width: 100%;
  box-sizing: border-box;
}

body.call-ended {
  display: block;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: auto;
}

body.call-ended > :not(#call-ended-screen) {
  display: none !important;
}

body.call-ended > #call-ended-screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
  align-items: center;
  justify-content: center;
  text-align: center;
}

body.call-ended #call-ended-title {
  margin: 0;
  font-size: clamp(1.75rem, 6vw, 2.5rem);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

@media (max-width: 420px) {
  #app.resident-app {
    padding-inline: 12px;
  }

  .resident-directory-card,
  .calling-card {
    padding: 18px 14px;
    border-radius: 20px;
  }
}

.notification-modal-card {
  width: 92%;
  max-width: 460px;
  text-align: left;
  box-sizing: border-box;
}

.notification-modal-card h2 {
  font-size: 1.25rem;
  margin-top: 0;
  margin-bottom: 4px;
}

.notification-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.notification-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.notification-form input {
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: var(--bg-surface-2);
  color: var(--text-primary);
  font-size: 0.9rem;
  letter-spacing: 0;
  text-align: left;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.modal-actions button {
  flex: 1;
}

.debug-panel {
  width: 100%;
  margin-top: 15px;
  text-align: left;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 10px 12px;
  box-sizing: border-box;
  font-size: 0.75rem;
}

.debug-panel summary {
  cursor: pointer;
  color: #94a3b8;
  font-weight: 600;
  user-select: none;
}

.debug-log-output {
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
  margin-top: 8px;
  color: #34d399;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.35;
  word-break: break-all;
}
