/* Global layout + mobile friendliness */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: sans-serif;
  margin: 0;
  /* safe-area aware padding for iPhones with notches */
  padding: 14px;
  padding-top: max(14px, env(safe-area-inset-top));
  padding-right: max(14px, env(safe-area-inset-right));
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  padding-left: max(14px, env(safe-area-inset-left));
  background: #f3f4f6;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0d0d0d;
  color: #fff;
  padding: 3px 14px;
  border-radius: 8px;
  margin-bottom: 12px;
  min-height: 46px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.brand strong {
  color: #2EB9ED;
}
.brand img {
  height: 1em;
  width: auto;
  display: block;
}
.brand img.logo-rosscom {
  height: 1.2em;
  transform: scaleY(1.4);
  transform-origin: center;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-menu-root {
  position: relative;
}
.header-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 260px;
  background: #141414;
  border: 1px solid #303030;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 1200;
}
.header-menu-panel .btn {
  width: 100%;
  text-align: left;
}
.header-menu-panel .menu-primary-action {
  background: #1f1f1f;
  border-color: #444;
  color: #fff;
}
.header-menu-panel .menu-primary-action:hover {
  background: #2a2a2a;
  border-color: #666;
  color: #fff;
}
.header-menu-panel a.btn {
  display: block;
  text-decoration: none;
}
.header-username {
  font-size: 14px;
  color: #ddd;
}
.status-badge {
  font-size: 12px;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 999px;
  background: #3a3a3a;
  color: #eee;
  border: 1px solid rgba(255,255,255,0.1);
}
.status-badge.connected {
  background: #1b5e20;
  color: #e8f5e9;
  border-color: #2e7d32;
}
.status-badge.disconnected {
  background: #5a5a5a;
  color: #eee;
}
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  background: #1f1f1f;
  color: #fff;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}
.btn:active { transform: translateY(0.5px); }
.btn:disabled,
.btn.disabled { opacity: 0.55; cursor: not-allowed; }
.btn:hover {
  background: #2a2a2a;
}
.btn-primary {
  background: #e60012;
  border-color: #c40010;
}
.btn-primary:hover {
  background: #9a040e;
}
.btn-ghost {
  background: transparent;
  border-color: #444;
  color: #f80303;
}
.btn-ghost:hover {
  border-color: #666;
  color: #fff;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
}

.hidden {
  display: none;
}

#login-section,
#intercom-section {
  border: 1px solid #ccc;
  padding: 1rem;
  margin-bottom: 1rem;
  border-radius: 8px;
  background: #fff;
}

label {
  display: block;
  margin-bottom: 0.5rem;
}

label input,
label select {
  width: 100%;
  max-width: 520px;
}

input, select, button {
  font: inherit;
}

#buses {
  margin-top: 1rem;
}

.bus {
  margin-bottom: 0.5rem;
}

.bus .label {
  display: inline-block;
  width: 80px;
}

.talk-btn {
  position: relative;
  padding: 16px 16px 36px; /* extra bottom padding for meters */
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.2px;
  border-radius: 6px;
  border: 1px solid #ddd;
  background: #fafafa;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
  flex: 1 1 180px; /* equal width responsive */
  height: 100px; /* taller buttons */
  display: flex;
  align-items: center; /* center title vertically */
  justify-content: center; /* center title horizontally */
  overflow: hidden;
  touch-action: none; /* important for press/hold on touch screens */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.talk-btn:hover { background: #f3f3f3; }
.talk-btn.talking { background: #ffe5e7; border-color: #e60012; }
.talk-btn:active { background: #eee; }

/* Ensure title sits above meters */
.talk-btn .title {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 0 8px;
  pointer-events: none;
}

/* Inner meters for channel buttons */
.btn-meter {
  position: absolute;
  left: 28px; /* leave room for icon */
  right: 8px;
  bottom: 8px;
  height: 8px;
  background: #eee;
  border-radius: 4px;
  overflow: hidden;
  z-index: 1;
}
.btn-meter .fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2ecc71, #f1c40f, #e74c3c);
  transition: width 80ms linear;
}
.btn-meter.recv {
  bottom: 22px;
  background: #e9f3ff;
}
.btn-meter.recv .fill {
  background: linear-gradient(90deg, #3498db, #9b59b6);
}
.btn-no-mic {
  position: absolute;
  right: 8px;
  top: 8px;
  font-size: 14px;
  color: #777;
}

/* Icon badges next to the meters */
.btn-meter-icon {
  position: absolute;
  left: 8px;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  font-size: 14px;
  z-index: 2;
  color: #888; /* slightly lighter so icons are less prominent */
  user-select: none;
  pointer-events: none;
}
.btn-meter-icon svg {
  width: 16px;
  height: 16px;
  display: block;
}
.btn-meter-icon.recv { bottom: 20px; } /* align with recv bar */
.btn-meter-icon.send { bottom: 6px; }  /* align with send bar */
.btn-meter-icon .overlay {
  position: absolute;
  right: -3px;
  top: -6px;
  width: 14px;
  height: 14px;
}
.btn-meter-icon .overlay svg {
  width: 14px;
  height: 14px;
  display: block;
}

/* Press tooltip for permission guidance */
.talk-tooltip {
  position: fixed;
  background: #111;
  color: #fff;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  z-index: 3000;
  pointer-events: none;
  max-width: 260px;
}
.bus-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin: 10px 0 6px;
}

#log {
  background: #111;
  color: #0f0;
  padding: 0.5rem;
  height: 200px;
  overflow: auto;
  font-size: 0.8rem;
  border-radius: 6px;
}

#devices {
  margin: 1rem 0;
}

.meter-row {
  display: flex;
  align-items: center;
  margin: 0.4rem 0;
}

.meter-label {
  display: inline-block;
  width: 60px;
}

.meter {
  position: relative;
  flex: 1;
  height: 10px;
  background: #eee;
  border-radius: 3px;
  overflow: hidden;
}

.meter-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, #2ecc71, #f1c40f, #e74c3c);
}

/* Inline message area for UX guidance */
#ux-message {
  margin: 8px 0;
  padding: 8px 10px;
  background: #fff8e1;
  color: #8a6d3b;
  border: 1px solid #ffe0a3;
  border-radius: 4px;
}

.ux-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 10px 0 6px;
}

/* Ensure hidden always overrides layout classes declared later */
.hidden {
  display: none !important;
}

/* Context bar: title on left, actions (leave buttons) on right */
.context-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.context-title h2 {
  margin: 0;
  font-size: 18px; /* slightly smaller than default */
}
.context-title #context-role {
  font-size: 15px; /* bigger than before, still smaller than prod */
  color: #666;
}
.context-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
/* Fullscreen mode for channel buttons */
.fullscreen .app-header,
.fullscreen .context-bar,
.fullscreen #selectors,
.fullscreen #production-buttons,
.fullscreen #role-buttons,
.fullscreen #ux-message,
.fullscreen #log {
  display: none !important;
}
.fullscreen #channels-row {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  bottom: 12px;
  margin: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  grid-auto-rows: minmax(160px, 1fr); /* expand vertically to fill available height */
  align-items: stretch;      /* override .bus-row center alignment */
  justify-items: stretch;
  align-content: stretch;
  gap: 16px;
}
.fullscreen .talk-btn {
  width: 100%;
  height: 100%;             /* fill the grid track height */
  min-height: 160px;
  font-size: 18px;
}
.fullscreen #exit-fullscreen {
  display: inline-flex !important;
  width: 26px;
  height: 26px;
  font-size: 14px;
  line-height: 1;
  align-items: center;
  justify-content: center;
}

/* Remove intercom-section border in fullscreen */
.fullscreen #intercom-section {
  border: none;
}
/* Modal (Setup) */
#setup-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  z-index: 3000; /* ensure above meters/titles and headers */
}
#setup-modal.open {
  display: flex;
}
.modal-panel {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  margin: auto 0;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: #0d0d0d;
  color: #fff;
  flex-shrink: 0;
}
.modal-body {
  padding: 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-footer {
  padding: 12px 14px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid #eee;
  flex-shrink: 0;
}

/* Reusable modal overlay for custom alerts/confirms/prompts */
.rc-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 2000;
}
.rc-modal.open {
  display: flex;
}

/* Connection overlay for WS down */
.conn-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; /* default to flex; hidden class will turn it off */
  align-items: center;
  justify-content: center;
  z-index: 2500;
  padding: 16px;
}
.conn-overlay .conn-panel {
  background: #0d0d0d;
  color: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  width: 100%;
  max-width: 420px;
  padding: 16px 18px;
  text-align: center;
}
.conn-overlay .conn-title {
  font-weight: 700;
  margin-bottom: 6px;
}
.conn-overlay .conn-body {
  font-size: 14px;
  color: #ddd;
}

/* Responsive tweaks for phones */
@media (max-width: 640px) {
  body { padding: 10px; padding-top: max(10px, env(safe-area-inset-top)); padding-right: max(10px, env(safe-area-inset-right)); padding-bottom: max(10px, env(safe-area-inset-bottom)); padding-left: max(10px, env(safe-area-inset-left)); }
  .app-header { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .brand { font-size: 16px; gap: 8px; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
  .header-menu-panel { width: min(280px, calc(100vw - 28px)); }
  .context-bar { flex-wrap: wrap; align-items: flex-start; }
  .context-actions { flex-wrap: wrap; justify-content: flex-start; }
  .btn { min-height: 44px; padding: 10px 12px; }
  .icon-btn { width: 44px; height: 44px; }
  /* prevent iOS zoom-on-focus for inputs */
  input, select { font-size: 16px; }
  #login-section, #intercom-section { padding: 12px; }
  .talk-btn { flex: 1 1 150px; height: 92px; }
  .btn-meter { left: 26px; }
  .fullscreen #channels-row { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
}
