/* =============================================================================
   Birdcam Motion Lab — Experimental page styles
   Inherits font stack and design language from the main app.
============================================================================= */

:root {
  --sky:       #7dd3fc;
  --leaf:      #4ade80;
  --cream:     #fefce8;
  --white:     #fff;
  --text:      #1c1917;
  --text-soft: #57534e;
  --shadow:    rgba(0, 0, 0, 0.12);
  --radius:    16px;
  --radius-sm: 10px;

  /* Experimental palette extras */
  --exp:       #a78bfa;   /* purple accent for experimental badge */
  --exp-dark:  #7c3aed;
  --motion:    #f97316;   /* orange for motion alert */
  --card-bg:   rgba(255, 255, 255, 0.75);
  --border:    rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Nunito', sans-serif;
  background: linear-gradient(160deg, var(--sky) 0%, #bae6fd 40%, var(--cream) 100%);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------------------------
   App shell
--------------------------------------------------------------------------- */
.app {
  max-width: 1400px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------------------
   Header
--------------------------------------------------------------------------- */
.header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  flex-shrink: 0;
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.back-link {
  font-size: 1.3rem;
  color: var(--text-soft);
  text-decoration: none;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
  transition: background 0.15s;
}
.back-link:hover { background: rgba(0,0,0,0.06); }

.logo {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.logo-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.exp-badge {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--exp);
  color: #fff;
  padding: 0.2em 0.55em;
  border-radius: 20px;
  align-self: center;
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.back-home {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-soft);
  text-decoration: none;
}
.back-home:hover { color: var(--text); }

/* Status pill */
.status-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.25em 0.75em;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  flex-shrink: 0;
}

.status-dot.connected  { background: var(--leaf); box-shadow: 0 0 0 3px rgba(74,222,128,0.25); }
.status-dot.connecting { background: #facc15; animation: pulse-dot 1s infinite; }
.status-dot.warming   { background: #facc15; animation: pulse-dot 1s infinite; }
.status-dot.disconnected,
.status-dot.offline    { background: #f87171; }

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

/* ---------------------------------------------------------------------------
   Main layout
--------------------------------------------------------------------------- */
.main {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1rem;
  padding: 1rem;
  flex: 1;
  min-height: 0;
}

/* ---------------------------------------------------------------------------
   Video column
--------------------------------------------------------------------------- */
.video-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

/* Motion banner */
.motion-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--motion);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity 0.2s;
}

.motion-banner.hidden { display: none; }
.motion-banner.active { opacity: 1; }

.motion-icon { font-size: 1.1rem; }

/* Video stack */
.video-stack {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: #111;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 24px var(--shadow);
}

.video-stack video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.video-stack canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.video-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
  color: #fff;
  gap: 0.75rem;
}

.video-loading.hidden { display: none; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Clips section */
.clips-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
  margin-top: 0.75rem;
}

#clips-list {
  max-height: 280px;
  overflow-y: auto;
}

.clip-item {
  border-bottom: 1px solid var(--border);
  padding: 0.3rem 0.5rem;
}
.clip-item:last-child { border-bottom: none; }

.clip-play-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  text-align: left;
  transition: background 0.15s;
}
.clip-play-btn:hover { background: rgba(0,0,0,0.04); }

.clip-play-icon {
  font-size: 0.75rem;
  color: var(--motion);
  flex-shrink: 0;
  width: 1rem;
  text-align: center;
}

.clip-meta {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.clip-time {
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 0.78rem;
  color: var(--text-soft);
}

.clip-info {
  font-size: 0.75rem;
  color: var(--text-soft);
  opacity: 0.75;
}

.clip-player.hidden { display: none; }
.clip-player { padding: 0 0.5rem 0.5rem; }

/* Visit activity chart */
.visits-chart-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
  margin-bottom: 0.75rem;
}

.visits-chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}

.visits-chart-body {
  padding: 0.75rem 1rem;
  height: 180px;
  position: relative;
}

.timeline-toggle {
  display: flex;
  gap: 0.25rem;
}

.tl-btn {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-soft);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tl-btn:hover { background: rgba(0,0,0,0.05); }
.tl-btn-active {
  background: var(--motion);
  color: #000;
  border-color: var(--motion);
}

/* Event log */
.event-log-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  backdrop-filter: blur(6px);
  flex-shrink: 0;
}

.event-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}

.event-log-title {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.btn-sm {
  font-size: 0.75rem;
  font-weight: 600;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2em 0.6em;
  cursor: pointer;
  color: var(--text-soft);
  transition: background 0.15s;
}
.btn-sm:hover { background: rgba(0,0,0,0.05); }

.event-log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 120px;
  overflow-y: auto;
}

.event-empty {
  padding: 0.75rem 1rem;
  color: var(--text-soft);
  font-size: 0.85rem;
  font-style: italic;
}

.event-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  transition: background 0.3s;
}

.event-item.new {
  background: rgba(249, 115, 22, 0.1);
}

.event-time {
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 0.78rem;
  color: var(--text-soft);
  flex-shrink: 0;
}

.event-desc {
  font-weight: 600;
  color: var(--motion);
}

.event-active {
  margin-left: auto;
  font-size: 0.6rem;
  color: var(--motion);
  animation: pulse-dot 1s ease-in-out infinite;
}

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

/* ---------------------------------------------------------------------------
   Controls sidebar
--------------------------------------------------------------------------- */
.controls-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  min-width: 0;
}

/* Card */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  backdrop-filter: blur(6px);
}

.card-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: var(--text);
}

.card-desc {
  font-size: 0.82rem;
  color: var(--text-soft);
  margin: 0 0 0.75rem;
  line-height: 1.5;
}

/* Push button */
.btn {
  display: inline-block;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.55em 1.1em;
  font-family: 'Nunito', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
.btn:hover  { filter: brightness(1.08); }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--exp);
  color: #fff;
  width: 100%;
}

.push-status {
  font-size: 0.78rem;
  color: var(--text-soft);
  margin: 0.4rem 0 0;
  min-height: 1em;
}

/* Range controls */
.ctrl-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.ctrl-value {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--exp-dark);
  background: rgba(124,58,237,0.08);
  padding: 0.1em 0.5em;
  border-radius: 6px;
}

.ctrl-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--exp) 0%, var(--exp) calc(var(--pct, 50%) * 1%), #d1d5db calc(var(--pct, 50%) * 1%), #d1d5db 100%);
  outline: none;
  cursor: pointer;
}

.ctrl-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--exp-dark);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px var(--shadow);
}

.ctrl-range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--exp-dark);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px var(--shadow);
}

.range-hints {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-soft);
  margin-top: 0.2rem;
}

/* Toggle rows */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

.toggle-row:last-of-type { border-bottom: none; }

.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  -webkit-appearance: none;
  appearance: none;
  background: #d1d5db;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle:checked { background: var(--exp); }

.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px var(--shadow);
  transition: left 0.2s;
}

.toggle:checked::after { left: 18px; }

/* Color swatches */
.color-swatches {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  padding: 0;
}

.swatch:hover  { transform: scale(1.15); }
.swatch.active { border-color: var(--text); transform: scale(1.1); }

/* Stats card */
.card-stats { }

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.stat-box {
  background: rgba(0,0,0,0.04);
  border-radius: var(--radius-sm);
  padding: 0.6rem;
  text-align: center;
}

.stat-num {
  display: block;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--exp-dark);
  line-height: 1;
}

.stat-lbl {
  display: block;
  font-size: 0.72rem;
  color: var(--text-soft);
  margin-top: 0.2rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------------------------------------------------------------------------
   Experimental link in main app header (style.css addition injected inline)
--------------------------------------------------------------------------- */
.experimental-link {
  font-size: 0.78rem;
  font-weight: 700;
  color: #7c3aed;
  text-decoration: none;
  background: rgba(167,139,250,0.15);
  padding: 0.15em 0.55em;
  border-radius: 20px;
  border: 1px solid rgba(124,58,237,0.25);
  transition: background 0.15s;
}

.experimental-link:hover {
  background: rgba(167,139,250,0.3);
}

/* ---------------------------------------------------------------------------
   Responsive
--------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
  }

  .controls-col {
    overflow-y: visible;
  }
}

@media (max-width: 600px) {
  .header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
  }

  .exp-badge { display: none; }
}
