/* ============================================================
   layout.css — app shell, nav, panels, insight bar
   ============================================================ */

/* ---------- Nav ---------- */

.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1.5px solid var(--border);
  box-shadow: var(--shadow);
  transition: background .25s, border-color .25s;
}

.nav-logo {
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: -.02em;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.nav-logo span { color: var(--text); }

/* Mobile settings toggle */
.nav-settings-btn {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--card);
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.nav-settings-btn:hover { border-color: var(--accent); }
.nav-settings-btn.open  { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--card)); }

/* Controls group — desktop: flex row inline; mobile: fixed dropdown */
.nav-controls-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

/* Section label — hidden on desktop, visible in mobile drawer */
.nav-section-label {
  display: none;
}

/* Sections are transparent on desktop (just pass children through) */
.nav-section {
  display: contents;
}

/* Spacer inside group pushes theme-picker to the right */
.nav-group-spacer {
  flex: 1;
}

/* Profile pill */
.profile-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.profile-pill:hover { border-color: var(--accent); }

.profile-pill .profile-icon { font-size: 1rem; }

/* Mode toggle */
.mode-toggle {
  display: flex;
  gap: 3px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 3px;
  flex-shrink: 0;
}

.mode-btn {
  padding: 4px 14px;
  border-radius: 16px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.mode-btn.active {
  background: var(--accent);
  color: var(--accent-text);
}

/* Theme picker */
.theme-picker {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

.theme-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, border-color .15s;
  background: var(--card);
}

.theme-btn:hover    { transform: scale(1.15); }
.theme-btn.active   { border-color: var(--accent); }

/* Nav search */
.nav-search {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: .875rem;
  width: 160px;
  outline: none;
  transition: border-color .15s, width .2s;
  flex-shrink: 0;
}

.nav-search:focus {
  border-color: var(--accent);
  width: 220px;
}

.nav-search::placeholder { color: var(--text-muted); }

/* Discovery toggle (mobile) */
.discovery-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--card);
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

/* ---------- App shell ---------- */

.app-shell {
  display: flex;
  flex-direction: row;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* ---------- Applet panel (left) ---------- */

.applet-panel {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px 100px;
  min-width: 0;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-muted);
  gap: 8px;
  padding-bottom: 80px;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 8px;
  opacity: .7;
}

.empty-state h2 {
  color: var(--text);
  font-size: 1.5rem;
}

.empty-state p {
  font-size: 1rem;
  max-width: 280px;
}

/* Applet frame */
.applet-frame {
  max-width: 560px;
}

/* ---------- Discovery panel (right) ---------- */

.discovery-panel {
  width: 340px;
  flex-shrink: 0;
  border-left: 1.5px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
  transition: background .25s, border-color .25s;
}

.discovery-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.discovery-header span {
  font-size: .875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  flex: 1;
}

.discovery-header input {
  padding: 5px 10px;
  border-radius: 16px;
  border: 1.5px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: .8125rem;
  width: 120px;
  outline: none;
  transition: border-color .15s;
}

.discovery-header input:focus {
  border-color: var(--accent);
}

/* Family filter pills */
.family-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.family-filter-btn {
  padding: 4px 10px;
  border-radius: 14px;
  font-size: .75rem;
  font-weight: 600;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.family-filter-btn:hover { color: var(--text); }

.family-filter-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

/* Tile list */
.tile-list {
  flex: 1;
  padding: 8px 0 16px;
}

.tile-search-empty {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: .9rem;
}

/* ---------- Insight bar ---------- */

.insight-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 340px;
  z-index: 50;
  overflow: hidden;
  max-height: 0;
  transition: max-height .3s ease, padding .3s ease;
  background: var(--card);
  border-top: 1.5px solid var(--border);
  box-shadow: 0 -2px 16px rgba(0,0,0,.08);
}

.insight-bar.show {
  max-height: 72px;
  padding: 10px 20px;
}

.insight-chips {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  align-items: center;
}

.insight-chips::-webkit-scrollbar { display: none; }

.insight-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: .8125rem;
  white-space: nowrap;
  color: var(--text);
  flex-shrink: 0;
  transition: border-color .15s;
}

.insight-chip:hover { border-color: var(--accent); }

.insight-chip .chip-icon { font-size: 1rem; }

/* Profile dropdown */
.profile-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 200;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 200px;
  overflow: hidden;
}

.profile-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background .12s;
}

.profile-option:hover { background: var(--surface); }
.profile-option.active { color: var(--accent); font-weight: 600; }

.profile-option-icon { font-size: 1.2rem; }

.profile-option-text { flex: 1; }
.profile-option-label { font-size: .9rem; font-weight: 600; }
.profile-option-desc  { font-size: .75rem; color: var(--text-muted); }

/* Loading spinner */
.applet-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  gap: 10px;
  color: var(--text-muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

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

/* ---------- Ad slots ---------- */

/* Below applet result */
.ad-applet {
  display: none;         /* shown by JS when applet-frame is visible */
  max-width: 560px;
  margin-top: 24px;
  padding: 12px 0 4px;
  border-top: 1px solid var(--border);
}

.ad-applet.show { display: block; }

/* Discovery panel ad (between filters and tile list) */
.ad-discovery {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

/* Scrollable body inside discovery panel (ad + tiles + promos) */
.discovery-scroll-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Mobile sticky bottom banner */
.ad-mobile-sticky {
  display: none;          /* only shown on mobile */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 45;
  background: var(--surface);
  border-top: 1px solid var(--border);
  min-height: 60px;
  max-height: 100px;
  overflow: hidden;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .discovery-panel {
    width: 280px;
  }
  .applet-panel {
    padding: 20px;
  }
  .insight-bar {
    right: 280px;
  }
}

@media (max-width: 768px) {
  .nav-search { display: none; }

  /* Show mobile buttons */
  .nav-settings-btn { display: flex; margin-left: auto; }
  .discovery-toggle { display: flex; }

  /* Controls group becomes a fixed dropdown panel */
  .nav-controls-group {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--card);
    border-bottom: 1.5px solid var(--border);
    box-shadow: 0 4px 24px rgba(0,0,0,.14);
    z-index: 90;
    padding: 4px 0 8px;
    gap: 0;
  }

  .nav-controls-group.open {
    display: flex;
  }

  /* Sections become labeled rows */
  .nav-section {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
  }

  .nav-section:last-child {
    border-bottom: none;
  }

  .nav-section-label {
    display: block;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-muted);
    width: 72px;
    flex-shrink: 0;
  }

  .nav-group-spacer { display: none; }

  /* Mode toggle in drawer */
  .mode-toggle { margin: 0; }

  /* Show all theme buttons in drawer */
  .theme-btn { display: flex !important; }

  /* App shell — use dvh so iOS browser chrome doesn't clip content */
  .app-shell {
    position: relative;
    overflow: visible;
    height: calc(100dvh - 56px);
  }

  .applet-panel {
    width: 100%;
    padding: 16px;
    padding-bottom: 80px;
    -webkit-overflow-scrolling: touch;
  }

  .discovery-panel {
    position: fixed;
    top: 56px;
    right: 0;
    bottom: 0;
    width: 85vw;
    max-width: 340px;
    transform: translateX(100%);
    transition: transform .25s ease;
    z-index: 80;
    box-shadow: -4px 0 20px rgba(0,0,0,.15);
  }

  .discovery-panel.open {
    transform: translateX(0);
  }

  .insight-bar { right: 0; bottom: 60px; }

  /* Show mobile sticky banner */
  .ad-mobile-sticky { display: block; }

  /* Tile-list needs bottom padding to clear sticky banner */
  .tile-list { padding-bottom: 80px; }
}
