/* ============================================================
   App shell styles (Phase 0)
   Extracted from inline <style> blocks in views.php:
   floating live-audio panel + sidebar live-activity feed.
   ============================================================ */

/* ===== Floating live audio panel ===== */
#live-audio-panel {
  position: fixed;
  inset: 0;
  z-index: 999999;
  pointer-events: none;
}

.live-audio-trigger {
  position: relative;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  padding: 0;
  background: #f1f3f8;
  border: 1px solid #dce1eb;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font: inherit;
  color: #5b55c7;
  user-select: none;
  pointer-events: auto;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.live-audio-trigger::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid rgba(98, 85, 250, 0.5);
  border-radius: inherit;
  opacity: 0;
  pointer-events: none;
}

.live-audio-trigger:focus-visible,
.live-audio-trigger[aria-expanded="true"],
.live-audio-trigger.is-playing {
  background: linear-gradient(135deg, #6255fa 0%, #5135ed 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 14px rgba(79, 70, 229, 0.3), 0 2px 5px rgba(49, 46, 129, 0.2);
}

.live-audio-trigger.is-playing::after {
  animation: live-audio-playing-pulse 2.2s ease-out infinite;
}

@keyframes live-audio-playing-pulse {
  0% {
    opacity: 0.52;
    transform: scale(0.96);
  }
  70%,
  100% {
    opacity: 0;
    transform: scale(1.5);
  }
}

@media (hover: hover) and (pointer: fine) {
  .live-audio-trigger:hover {
    background: linear-gradient(135deg, #6255fa 0%, #5135ed 100%);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 6px 14px rgba(79, 70, 229, 0.3), 0 2px 5px rgba(49, 46, 129, 0.2);
    transform: translateY(-1px);
  }
}

.live-audio-trigger:focus-visible {
  outline: 2px solid rgba(79, 70, 229, 0.35);
  outline-offset: 2px;
}

/* Some hardware media keys make Chromium expose :focus-visible on the last
   clicked control. During playback the animated halo already supplies a clear
   state indicator, so do not let that static outline cover the animation. */
.live-audio-trigger.is-playing:focus-visible {
  outline: none;
}

.live-audio-trigger:active {
  transform: translateY(0);
}

.live-audio-mic {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  stroke-width: 2;
}

.live-audio-trigger-mobile {
  display: none;
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.sidebar-header-actions .sidebar-toggle {
  width: 24px;
  height: 34px;
  padding: 0;
}

.sidebar.collapsed .sidebar-header {
  flex-direction: column;
  gap: 8px;
}

.sidebar.collapsed .sidebar-header-actions {
  gap: 2px;
}

.sidebar.collapsed .live-audio-trigger-desktop {
  width: 30px;
  height: 30px;
  flex-basis: 30px;
}

.sidebar.collapsed .live-audio-trigger-desktop .live-audio-mic {
  width: 14px;
  height: 14px;
  flex-basis: 14px;
}

.sidebar.collapsed .sidebar-header-actions .sidebar-toggle {
  width: 18px;
  height: 30px;
}

.live-audio-status-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border-radius: 50%;
  background: #36c45b;
  box-shadow: 0 0 0 3px rgba(54, 196, 91, 0.12);
}

#live-audio-content {
  position: fixed;
  top: 14px;
  left: 292px;
  right: auto;
  width: 470px;
  max-width: calc(100vw - 36px);
  box-sizing: border-box;
  background: var(--bg-card, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 22px;
  box-shadow: 0 22px 48px rgba(15, 23, 42, 0.14), 0 5px 14px rgba(15, 23, 42, 0.08);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  visibility: hidden;
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  transform-origin: top left;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

#live-audio-panel.open #live-audio-content {
  visibility: visible;
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

#live-audio-panel.collapsed-anchor #live-audio-content {
  left: 82px;
}

#live-audio-panel.mobile-anchor #live-audio-content {
  top: 68px;
  right: 12px;
  left: auto;
  transform-origin: top right;
}

.live-audio-heading,
.live-audio-title-wrap {
  display: flex;
  align-items: center;
}

.live-audio-heading {
  width: 100%;
  justify-content: space-between;
}

.live-audio-title-wrap {
  gap: 12px;
  color: var(--text-primary, #0f172a);
  font-size: 1.08rem;
}

.live-audio-title-wrap .live-audio-status-dot {
  width: 11px;
  height: 11px;
  flex-basis: 11px;
  box-shadow: none;
}

#live-audio-close {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary, #64748b);
  background: transparent;
  cursor: pointer;
}

#live-audio-close:hover {
  color: var(--text-primary, #0f172a);
  background: var(--bg-secondary, #f1f5f9);
}

#live-audio-close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.live-audio-player-wrap {
  width: 100%;
  padding: 5px 8px;
  box-sizing: border-box;
  border-radius: 999px;
  background: var(--bg-secondary, #f1f5f9);
}

#live-audio-player {
  display: block;
  width: 100%;
  height: 54px;
  outline: none;
}

#live-audio-player::-webkit-media-controls-panel {
  background: var(--bg-secondary, #f1f5f9);
}

.live-audio-listening {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #4f46e5;
  font-size: 0.95rem;
  font-weight: 500;
}

.live-audio-listening svg {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

[data-theme="dark"] #live-audio-content {
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.42), 0 5px 14px rgba(0, 0, 0, 0.28);
}

[data-theme="dark"] .live-audio-trigger {
  background: #262c3b;
  border-color: #3b4355;
  color: #aaa5ff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.24);
}

[data-theme="dark"] .live-audio-trigger:focus-visible,
[data-theme="dark"] .live-audio-trigger[aria-expanded="true"],
[data-theme="dark"] .live-audio-trigger.is-playing {
  background: linear-gradient(135deg, #6255fa 0%, #5135ed 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.32);
}

@media (hover: hover) and (pointer: fine) {
  [data-theme="dark"] .live-audio-trigger:hover {
    background: linear-gradient(135deg, #6255fa 0%, #5135ed 100%);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.32);
  }
}

[data-theme="dark"] .live-audio-listening {
  color: #8b83ff;
}

@media (max-width: 1000px) {
  .live-audio-trigger-desktop {
    display: none;
  }

  .live-audio-trigger-mobile {
    display: inline-flex;
    margin-right: 10px;
  }
}

@media (max-width: 480px) {
  #live-audio-content {
    width: calc(100vw - 24px);
    padding: 18px;
    gap: 16px;
    border-radius: 18px;
  }

  .live-audio-listening {
    font-size: 0.88rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .live-audio-trigger.is-playing::after {
    animation: none;
  }
}

/* ===== Theme toggle (CSS-driven, no load flash) =====
   Both states exist in the markup; data-theme (set in <head> before paint)
   decides which is visible, so the correct icon shows from the first frame. */
.theme-toggle-option {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

[data-theme="dark"] .theme-when-light {
  display: none !important;
}

html:not([data-theme="dark"]) .theme-when-dark {
  display: none !important;
}

/* In the collapsed sidebar, keep the emoji visible but hide the label
   (the generic collapsed rule hides all button spans, wrappers included) */
.sidebar.collapsed .sidebar-nav button span.theme-toggle-option {
  display: inline-flex;
}

.sidebar.collapsed .sidebar-nav button .theme-toggle-option span {
  display: none;
}

/* ===== Palette launch buttons ===== */
.palette-launch {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 16px 0;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-secondary, #f1f5f9);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.8em;
  cursor: pointer;
  text-align: left;
}

.palette-launch:hover {
  background: var(--bg-button-hover, #e2e8f0);
  color: var(--text-primary);
}

.palette-launch span {
  flex: 1;
}

.palette-launch kbd {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 0.85em;
  font-family: inherit;
  color: var(--text-muted);
}

.palette-launch .nav-icon {
  width: 14px;
  height: 14px;
}

.sidebar.collapsed .palette-launch span,
.sidebar.collapsed .palette-launch kbd {
  display: none;
}

.sidebar.collapsed .palette-launch {
  justify-content: center;
  margin: 8px 10px 0;
  padding: 7px 0;
}

/* Sits beside the hamburger (margin-left:auto absorbs the header's
   space-between gap) and reads as a real button */
.palette-launch-mobile {
  margin-left: auto;
  margin-right: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-secondary, #f1f5f9);
  color: var(--text-primary);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.palette-launch-mobile:hover {
  background: var(--bg-button-hover, #e2e8f0);
}

.palette-launch-mobile .nav-icon {
  width: 19px;
  height: 19px;
}

/* ===== Command palette (Ctrl+K) ===== */
.palette-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 1000000;
  padding: 12vh 16px 0;
  justify-content: center;
  align-items: flex-start;
}

.palette-overlay.open {
  display: flex;
}

.palette-box {
  width: 100%;
  max-width: 540px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 16px);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.palette-box input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  font: inherit;
  font-size: 1rem;
  background: var(--bg-card);
  color: var(--text-primary);
  outline: none;
}

.palette-box ul {
  list-style: none;
  margin: 0;
  padding: 6px;
  max-height: 320px;
  overflow-y: auto;
}

.palette-box li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary);
}

.palette-box li:hover {
  background: var(--bg-button-hover);
}

.palette-box li.selected {
  background: var(--accent-subtle, rgba(79, 70, 229, 0.08));
  color: var(--accent);
}

.palette-kind {
  width: 22px;
  text-align: center;
  flex-shrink: 0;
  color: var(--text-muted);
}

.palette-label em {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85em;
}

.palette-empty {
  color: var(--text-secondary);
  cursor: default;
}

.palette-hint {
  border-top: 1px solid var(--border-light);
  padding: 7px 12px;
  font-size: 0.7rem;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  align-items: center;
}

.palette-hint kbd {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
}

/* ===== Bottom mobile tab bar ===== */
.bottom-nav {
  display: none;
}

@media (max-width: 1000px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
    z-index: 998;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .bottom-nav a,
  .bottom-nav button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 0 6px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 0.65rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    min-height: 44px;
  }

  .bottom-nav a:hover,
  .bottom-nav button:hover {
    color: var(--text-primary);
    font-weight: 600;
  }

  .bottom-nav a.active {
    color: var(--accent);
  }

  .bottom-nav .nav-icon {
    width: 20px;
    height: 20px;
  }

  /* keep page content clear of the bar */
  .views {
    padding-bottom: 76px;
  }
}

/* ===== Sidebar live activity feed ===== */
.sidebar-feed {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  padding: 15px 20px;
  overflow: hidden;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

/* On shorter desktop screens, let the secondary live feed yield space before
   the primary navigation. The nav keeps its existing scrollbar for genuinely
   short viewports or an expanded Insights menu. */
@media (min-width: 1001px) {
  .sidebar-nav {
    min-height: 0;
  }

  .sidebar-feed {
    flex: 1 1 0;
    min-height: clamp(6rem, 18vh, 10rem);
  }
}

.sidebar-feed h3 {
  margin: 0 0 10px 0;
  font-size: 0.9em;
  color: var(--text-heading);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-feed h3 .live-dot {
  width: 8px;
  height: 8px;
  background: var(--live-dot, #22c55e);
  border-radius: 50%;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.feed-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex-grow: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.feed-list::-webkit-scrollbar {
  width: 4px;
}

.feed-list::-webkit-scrollbar-thumb {
  background-color: var(--border);
  border-radius: 4px;
}

.feed-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-light, #f1f5f9);
  font-size: 0.8em;
}

.feed-item:last-child {
  border-bottom: none;
}

.feed-species {
  font-weight: 600;
  color: var(--text-primary, #1f2937);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.feed-badge {
  display: inline-block;
  padding: 2px 5px;
  border-radius: 8px;
  font-size: 0.7em;
  font-weight: 700;
  margin: 0 6px;
  min-width: 32px;
  text-align: center;
}

.feed-badge.high {
  background: var(--conf-high-bg);
  color: var(--conf-high-text);
}

.feed-badge.med {
  background: var(--conf-med-bg);
  color: var(--conf-med-text);
}

.feed-badge.low {
  background: var(--conf-low-bg);
  color: var(--conf-low-text);
}

.feed-time {
  font-size: 0.75em;
  color: var(--text-secondary, #6b7280);
  white-space: nowrap;
}

.feed-count {
  color: var(--text-secondary, #6b7280);
  font-weight: 400;
  font-size: 0.75em;
  flex-shrink: 0; /* the count survives even when a long name truncates */
  margin-left: 2px;
}

.feed-now {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--success, #10b981);
  font-weight: 700;
  font-size: 0.95em;
}

.feed-now .live-dot {
  width: 6px;
  height: 6px;
  background: var(--success, #10b981);
  border-radius: 50%;
  animation: pulse-dot 2s infinite;
}

.feed-item.feed-active .feed-species {
  color: var(--text-heading);
}

/* Optional station label under the sidebar logo (Settings > Display & Units) */
.sidebar-logo {
  flex-wrap: wrap;
}

.sidebar-site-name {
  flex-basis: 100%;
  font-size: 0.85em;
  font-weight: 600;
  color: var(--text-secondary, #6b7280);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar.collapsed .sidebar-site-name {
  display: none;
}

/* Owner-authored info box at the top of the Today page */
.custom-info-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: 16px 20px;
  margin-bottom: 20px;
  color: var(--text-primary);
  overflow-wrap: break-word;
}

.custom-info-box img {
  max-width: 100%;
}
