/* Mobile / tablet layer for Clubhouse Admin. Desktop (>860px) is untouched. */

html { -webkit-text-size-adjust: 100%; }
.ch-back { display: none; }
.ch-detail-bar { display: none; }

/* Keep tall photos inside the round avatar instead of stretching it into an oval */
.avatar { position: relative; overflow: hidden; }
.avatar img { position: absolute; inset: 0; }

/* "CH API" markers inside result rows (.user-cell span would otherwise recolor them) */
.user-cell b .badge { margin-left: 6px; padding: 1px 8px; font-size: 10.5px; vertical-align: middle; }
.user-cell b .badge.b-green { color: #1f6a26; }
.user-cell b .badge.b-gray { color: var(--ink-soft); }

/* Collapsible section header (Photos) */
.sec-toggle {
  width: 100%;
  padding: 8px 0;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
}
.sec-toggle:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; border-radius: 8px; }
.sec-chevron {
  width: 8px;
  height: 8px;
  margin: -3px 6px 0 auto;
  border-right: 2.5px solid var(--ink-faint);
  border-bottom: 2.5px solid var(--ink-faint);
  transform: rotate(45deg);
  transition: transform .2s;
}
.sec-toggle[aria-expanded="true"] .sec-chevron { transform: rotate(-135deg); margin-top: 3px; }

@media (max-width: 1100px) {
  .login-card::before {
    content: "";
    display: block;
    height: 44px;
    margin-bottom: 22px;
    background: url(/clubhouse-logo.svg) no-repeat left center / contain;
  }
}

@media (max-width: 860px) {
  :root { --header-h: calc(56px + env(safe-area-inset-top, 0px)); --radius: 14px; }
  * { -webkit-tap-highlight-color: transparent; }
  body { overscroll-behavior: none; }

  /* Shell: single column, sidebar becomes an off-canvas drawer */
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--header-h) minmax(0, 1fr);
    height: 100%;
    height: 100dvh;
  }

  .sidebar {
    grid-row: auto;
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 86vw);
    z-index: 40;
    padding: 0 12px calc(16px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform .26s cubic-bezier(.22, 1, .36, 1), visibility 0s linear .26s;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .shell.collapsed .sidebar {
    transform: none;
    visibility: visible;
    transition: transform .26s cubic-bezier(.22, 1, .36, 1), visibility 0s;
    box-shadow: 14px 0 40px rgba(0, 0, 0, .35);
  }
  .shell::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(31, 31, 26, .55);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
  }
  .shell.collapsed::before { opacity: 1; pointer-events: auto; }

  .sidebar .brand { padding: env(safe-area-inset-top, 0px) 8px 0; }

  /* Undo the desktop "icon rail" behaviour inside the drawer */
  .shell.collapsed .nav-link span,
  .shell.collapsed .nav-title,
  .shell.collapsed .brand .word,
  .shell.collapsed .brand .tag,
  .shell.collapsed .nav-link .badge-count,
  .shell.collapsed .nav-link .new,
  .shell.collapsed .side-foot { display: revert; }
  .shell.collapsed .nav-link { justify-content: flex-start; }
  .nav-link { padding: 12px 14px; font-size: 15px; margin-bottom: 3px; }
  .nav-title { padding-bottom: 6px; }

  /* Header */
  .header {
    padding: env(safe-area-inset-top, 0px) 12px 0;
    gap: 6px;
  }
  .header .icon-btn { width: 42px; height: 42px; flex-shrink: 0; }
  .header .icon-btn[aria-label="Docs"],
  .header .spacer,
  .hdr-search kbd { display: none; }
  .hdr-search { flex: 1; min-width: 0; max-width: none; }
  .hdr-search input { height: 40px; font-size: 16px; padding-left: 38px; padding-right: 12px; text-overflow: ellipsis; }
  .hdr-search svg { top: 11px; left: 13px; }
  .dot { top: 10px; right: 11px; }
  .me-btn { padding: 2px; flex-shrink: 0; }
  .me-btn .who { display: none; }
  .avatar { width: 34px; height: 34px; }

  .menu {
    top: calc(100% + 6px);
    right: 12px;
    min-width: 0;
    width: min(280px, calc(100vw - 24px));
    max-height: calc(100dvh - var(--header-h) - 24px);
    overflow-y: auto;
  }
  .notif { width: min(360px, calc(100vw - 24px)); right: 12px; }
  .menu .item { padding: 12px; }

  /* Content */
  .main {
    min-width: 0;
    padding: 16px 14px calc(40px + env(safe-area-inset-bottom, 0px));
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }
  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 16px;
  }
  .page-head h1 { font-size: 24px; }
  .page-head p { font-size: 13.5px; }
  .page-head .actions { margin-left: 0; flex-wrap: wrap; }
  .page-head .actions > .btn { flex: 1 1 0; min-width: max-content; }
  .page-head .actions > .tabs { width: 100%; margin-bottom: 0; }
  .banner { margin-bottom: 16px; }

  .btn { height: 44px; padding: 0 18px; font-size: 14px; }
  .btn.sm { height: 36px; padding: 0 14px; }
  .btn.block { height: 48px; }
  .input { font-size: 16px; height: 48px; }
  .field { margin-bottom: 14px; }

  .tabs { display: flex; max-width: 100%; overflow-x: auto; scrollbar-width: none; margin-bottom: 14px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 1 0 auto; padding: 9px 16px; white-space: nowrap; }

  .grid { gap: 14px; }
  .grid > *, .split > * { min-width: 0; }
  .card { padding: 16px; }
  .card-head { flex-wrap: wrap; gap: 6px 10px; margin-bottom: 14px; }
  .card.flush .card-head { padding: 16px 16px 0; }
  .kpi { padding: 14px; }
  .kpi .value { font-size: 22px; }
  .kpi .foot { flex-wrap: wrap; gap: 4px 8px; }

  /* Charts: keep them legible by scrolling horizontally inside the card */
  .card:has(> svg.chart[width="100%"]) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card:has(> svg.chart[width="100%"]) > .card-head { position: sticky; left: 0; }
  svg.chart[width="100%"] { min-width: 520px; }
  svg.chart[viewBox^="0 0 760"] { min-width: 600px; }
  svg.chart[width="100%"] text { font-size: 13px; }

  /* Tables: horizontal scroll with edge shadows */
  .table-wrap {
    -webkit-overflow-scrolling: touch;
    background:
      linear-gradient(to right, var(--surface) 30%, #fffefa00),
      linear-gradient(to left, var(--surface) 30%, #fffefa00) right,
      radial-gradient(farthest-side at 0 50%, rgba(31, 31, 26, .16), #0000),
      radial-gradient(farthest-side at 100% 50%, rgba(31, 31, 26, .16), #0000) right;
    background-repeat: no-repeat;
    background-size: 36px 100%, 36px 100%, 14px 100%, 14px 100%;
    background-attachment: local, local, scroll, scroll;
  }
  table.t { font-size: 13px; }
  table.t th { padding: 10px 12px; background: transparent; }
  table.t td { padding: 11px 12px; }
  table.t:has(th:nth-child(4)) { min-width: 640px; }

  /* Master / detail: detail panel flows below the list */
  .detail { position: static; max-height: none; overflow: visible; scroll-margin-top: 12px; }
  .detail-top { gap: 12px; }
  .detail-top .avatar { width: 56px; height: 56px; font-size: 20px; }
  .detail-top h3 { font-size: 18px; }
  .kv { grid-template-columns: 96px minmax(0, 1fr); gap: 8px 12px; }
  .photos { grid-template-columns: repeat(3, 1fr); }
  pre.json { max-height: 320px; }
  .composer { grid-template-columns: 1fr; }

  .search-hero { padding: 20px 16px; border-radius: 16px; margin-bottom: 16px; }
  .search-hero h2 { font-size: 18px; }
  .search-hero .big-logo { display: none; }
  .search-hero .input { height: 48px; padding-left: 16px; min-width: 0; }
  .search-hero .btn { height: 48px; padding: 0 18px; }
  .search-hero form { max-width: none; }

  .empty { padding: 40px 16px; }

  .toast {
    left: 14px;
    right: 14px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  /* "Back to results" pill, driven by /mobile.js */
  .ch-back {
    position: fixed;
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 25;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 40px;
    padding: 0 16px;
    border: none;
    border-radius: 999px;
    background: var(--ink);
    color: var(--yellow);
    font-size: 13px;
    font-weight: 800;
    box-shadow: 0 8px 24px rgba(31, 31, 26, .35);
  }
  .ch-back[hidden] { display: none; }

  /* Global Search: results as cards, list/detail swap (driven by /mobile.js) */
  html[data-route="/search"] .ch-back { display: none; }
  html[data-route="/search"] .main:has(.split[data-view="detail"]) > .page-head,
  html[data-route="/search"] .main:has(.split[data-view="detail"]) > .search-hero,
  html[data-route="/search"] .main:has(.split[data-view="detail"]) > .error { display: none; }
  html[data-route="/search"] .split[data-view="detail"] > .ch-detail-bar { display: block; }
  html[data-route="/search"] .split[data-view="detail"] > .card,
  html[data-route="/search"] .split[data-view="list"] > .detail { display: none; }
  .ch-detail-bar-top {
    position: sticky;
    top: 0;
    z-index: 5;
    margin: -16px -14px 0;
    padding: 10px 14px;
    background: var(--cream);
    border-bottom: 1px solid var(--line);
  }

  html[data-route="/search"] .table-wrap { background: none; overflow: visible; }
  html[data-route="/search"] table.t,
  html[data-route="/search"] table.t tbody { display: block; min-width: 0 !important; }
  html[data-route="/search"] table.t thead { display: none; }
  html[data-route="/search"] table.t tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 12px;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
  }
  html[data-route="/search"] table.t tbody tr:last-child { border-bottom: none; }
  html[data-route="/search"] table.t tbody tr:active { background: var(--cream); }
  html[data-route="/search"] table.t tbody tr.sel { background: transparent; }
  html[data-route="/search"] table.t td { display: block; padding: 0; border: none; min-width: 0; }
  html[data-route="/search"] table.t td:nth-child(1) { grid-area: 1 / 1; }
  html[data-route="/search"] table.t td:nth-child(5) { grid-area: 1 / 2; align-self: start; text-align: right; font-size: 12px; }
  html[data-route="/search"] table.t td:nth-child(2) { grid-area: 2 / 1; font-size: 12px; }
  html[data-route="/search"] table.t td:nth-child(2)::before { content: "ID "; color: var(--ink-faint); font-family: Nunito, sans-serif; font-weight: 800; }
  html[data-route="/search"] table.t td:nth-child(4) { grid-area: 2 / 2; text-align: right; font-size: 12px; }
  html[data-route="/search"] table.t td:nth-child(3) { grid-area: 3 / 1 / 4 / 3; }
  html[data-route="/search"] .user-cell { min-width: 0; }
  html[data-route="/search"] .user-cell > div { min-width: 0; overflow-wrap: anywhere; }
}

/* Two-up KPI tiles on phones, single column for everything else */
@media (max-width: 720px) {
  .g-6, .g-4, .g-3, .g-2, .g-21 { grid-template-columns: minmax(0, 1fr); }
  .grid:has(> .kpi) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid:has(> .kpi) > .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  .env-pill { font-size: 0; gap: 0; padding: 8px; }
  .login-panel { padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px)); align-items: start; }
  .login-card { padding-top: 8px; }
  .login-card h2 { font-size: 26px; }
  .code-row input { letter-spacing: 8px; }
  .photos { grid-template-columns: repeat(2, 1fr); }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dt { padding-top: 10px; }
  .kv dd { padding-bottom: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .shell::before { transition: none !important; }
}
