/* responsive.css — Mobile-friendly overrides for ShowCast Admin
   Loaded AFTER all other stylesheets.
   Breakpoints: 768px (tablet), 480px (phone) */

/* ============================================================
   Touch & Global
   ============================================================ */
html {
  -webkit-text-size-adjust: 100%;
}

button, a, .nav-item, .eb-cell, .tab-btn, .us-item, .cast-pill {
  touch-action: manipulation;
}

/* ============================================================
   Hamburger Button (hidden on desktop, shown on mobile)
   ============================================================ */
.mobile-topbar--hidden {
  display: none !important;
}

.mobile-topbar {
  display: none;                      /* hidden on desktop */
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 90;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
}

.mobile-hamburger {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  cursor: pointer;
  padding: 8px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

.mobile-topbar .nav-brand {
  font-size: 15px;
}

.mobile-topbar .nav-brand img {
  width: 24px;
  height: 24px;
}

/* Sidebar overlay backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}
.sidebar-backdrop.open {
  display: block;
}

/* ============================================================
   EntityBrowser Mobile: detail pane overlay + back button
   ============================================================ */
.eb-back-btn {
  display: none;                       /* hidden on desktop */
}

/* ============================================================
   Tablet Breakpoint (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {

  /* ---- Mobile top bar ---- */
  .mobile-topbar {
    display: flex;
  }

  /* ---- Sidebar → slide-out drawer ---- */
  #main-nav {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 100;
    width: 240px;
    height: 100vh;
    height: 100dvh;
  }
  #main-nav.drawer-open {
    transform: translateX(0);
  }
  .nav-topbar {
    width: 240px;
  }
  .nav-sidebar {
    width: 240px;
    overflow-y: auto;
  }
  .nav-sidebar-links {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ---- Main app reset ---- */
  body {
    height: 100vh;
    height: 100dvh;
  }

  #app {
    margin-left: 0 !important;
    padding-top: 48px;                /* room for mobile topbar */
    height: 100vh !important;
    height: 100dvh !important;
  }

  /* ---- EntityBrowser: stacked layout ---- */
  .eb-layout {
    grid-template-columns: 1fr !important;
  }

  .eb-detail-pane {
    display: none;                     /* hidden until item selected */
    position: fixed;
    left: 0;
    right: 0;
    top: 48px;                        /* below mobile topbar */
    bottom: 0;
    z-index: 80;
    background: var(--bg-primary);
    padding: 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .eb-detail-pane.mobile-visible {
    display: block;
  }

  .eb-list-pane {
    border-right: none;
    height: calc(100vh - 48px);
    height: calc(100dvh - 48px);
  }

  .eb-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: var(--font-sans);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 12px;
    -webkit-tap-highlight-color: transparent;
  }

  .eb-back-btn:hover {
    color: var(--text-primary);
    border-color: var(--accent);
  }

  /* ---- Eval split-pane ---- */
  .eval-layout {
    grid-template-columns: 1fr !important;
  }

  .eval-layout > .eval-main {
    display: none;
    position: fixed;
    inset: 0;
    top: 48px;
    z-index: 80;
    background: var(--bg-primary);
    overflow-y: auto;
  }

  .eval-layout > .eval-main.mobile-visible {
    display: block;
  }

  /* ---- Evaluator split-pane ---- */
  .evaluator-layout {
    grid-template-columns: 1fr !important;
  }

  /* ---- Command Center ---- */
  .cc-grid {
    grid-template-columns: 1fr !important;
  }

  /* ---- Dashboard ---- */
  .dashboard-grid-2,
  .dashboard-grid-3 {
    grid-template-columns: 1fr !important;
  }

  .dashboard-hero {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .dashboard-layout {
    padding: 12px;
    gap: 14px;
  }

  /* ---- Live Activity ---- */
  .live-grid {
    grid-template-columns: 1fr !important;
  }

  /* ---- Settings ---- */
  .setting-row,
  .object-header,
  .nested-row {
    grid-template-columns: 1fr !important;
    gap: 6px;
  }

  .setting-row label,
  .nested-row label {
    font-weight: 600;
  }

  /* ---- Formats ---- */
  .fmt-cat-editor-body,
  .fmt-add-grid {
    grid-template-columns: 1fr !important;
  }

  /* ---- Topics ---- */
  .topic-counters {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .topic-cards {
    grid-template-columns: 1fr !important;
  }

  /* ---- Admin / Users ---- */
  .dashboard-counters {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ---- Charts grid ---- */
  .charts-grid {
    grid-template-columns: 1fr !important;
  }

  /* ---- Pool status counters ---- */
  .pool-status-counters {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ---- Eval framework ---- */
  .ef-run-list {
    grid-template-columns: 1fr !important;
  }

  .ef-just-columns,
  .ef-dim-row-main {
    grid-template-columns: 1fr !important;
  }

  /* ---- Admin detail info ---- */
  .admin-detail-info {
    grid-template-columns: 1fr !important;
  }

  /* ---- Featured counters ---- */
  .featured-counters {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ---- Experiment meta ---- */
  .experiment-meta {
    grid-template-columns: 1fr !important;
  }

  /* ---- Activity cards ---- */
  .activity-cards-grid {
    grid-template-columns: 1fr !important;
  }

  /* ---- Release form ---- */
  .release-grid {
    grid-template-columns: 1fr !important;
  }

  /* ---- Tabs: horizontal scroll ---- */
  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar {
    display: none;
  }
  .tab-btn {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ---- View headers ---- */
  .view-header {
    padding: 12px 14px 10px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .view-header h2 {
    font-size: 15px;
  }

  /* ---- Panels ---- */
  .panel {
    border-radius: var(--radius);
    padding: 12px;
  }

  /* ---- User selector dropdown ---- */
  .us-dropdown {
    width: calc(100vw - 24px);
    max-width: 360px;
  }

  /* ---- Buttons: larger touch targets ---- */
  .nav-item {
    padding: 10px 16px 10px 24px;
    font-size: 14px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .primary-btn, .secondary-btn, .danger-btn {
    padding: 10px 20px;
    min-height: 40px;
  }

  /* ---- Tables: horizontal scroll ---- */
  .table-scroll-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Wrap any wide grid table in a scrollable container */
  .job-row {
    min-width: 600px;      /* prevent squishing — allow scroll instead */
  }

  /* ---- Login card ---- */
  .login-card {
    width: min(340px, calc(100vw - 32px));
  }

  /* ---- Pool cards ---- */
  .pool-items-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }

  /* ---- Code blocks ---- */
  pre.code-block {
    font-size: 11px;
    padding: 10px;
  }

  /* ---- Hosts tile grid ---- */
  #view-hosts .eb-list-items {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)) !important;
  }

  /* ---- Bug reports detail ---- */
  .br-detail {
    max-width: 100%;
  }

  /* ---- Episode detail: unstack actions on mobile ---- */
  .episode-header {
    position: static;
  }

  .episode-detail-actions {
    position: static !important;
    margin-bottom: 10px;
    justify-content: flex-start;
  }

  .episode-title {
    font-size: 18px;
  }

  .episode-eyebrow {
    flex-wrap: wrap;
  }

  .episode-meta-line {
    flex-wrap: wrap;
  }

  .episode-tab-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ---- Host/Cast profile: stack portrait on mobile ---- */
  .host-profile-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .host-profile-header-portrait {
    width: 160px !important;
    height: 160px !important;
  }

  .host-profile-header-info {
    width: 100%;
  }

  .host-profile-header-name input {
    font-size: 18px;
    text-align: center;
  }

  .host-profile-header-meta {
    flex-wrap: wrap;
    justify-content: center;
    font-size: 11px;
  }

  .host-profile {
    overflow-x: hidden;
  }
}

/* ============================================================
   Phone Breakpoint (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {

  /* Even tighter spacing */
  .view-header {
    padding: 10px 10px 8px;
  }

  .panel {
    padding: 10px;
    border-radius: var(--radius-sm);
  }

  /* Dashboard hero → single column */
  .dashboard-hero {
    grid-template-columns: 1fr !important;
  }

  /* Topic counters → single column */
  .topic-counters {
    grid-template-columns: 1fr !important;
  }

  /* Admin/dashboard counters → single column */
  .dashboard-counters {
    grid-template-columns: 1fr !important;
  }

  /* Pool counters → single column */
  .pool-status-counters {
    grid-template-columns: 1fr !important;
  }

  /* Font scale-down for density */
  .eb-search {
    font-size: 14px;        /* iOS zoom prevention: ≥16px or use transform */
  }

  input[type="text"],
  textarea,
  select {
    font-size: 16px;         /* prevents iOS auto-zoom on focus */
  }

  /* Smaller nav brand */
  .mobile-topbar .nav-brand {
    font-size: 14px;
  }

  /* Pool cards → single column */
  .pool-items-grid {
    grid-template-columns: 1fr;
  }

  /* Paginator stacks */
  .paginator {
    flex-direction: column;
    gap: 6px;
    text-align: center;
  }

  /* Command center cards */
  .cc-status-grid {
    flex-direction: column !important;
  }

  /* User selector: full width overlay */
  .us-dropdown {
    position: fixed;
    top: 48px;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 0;
    max-height: calc(100vh - 48px);
  }

  .us-list {
    max-height: calc(100vh - 140px);
  }

  /* Safe area insets for notched phones */
  .mobile-topbar {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  #main-nav {
    padding-bottom: env(safe-area-inset-bottom);
  }
}
