/* Lead Radar on phones and tablets. Loaded after styles.css and events.css, so the design
   system stays in styles.css (in step with the PM Dashboard) and the screen-size layer is here.

   Three sizes, from the sidebar's own breakpoint:
     wide     1024px and up   sidebar (styles.css)
     tablet   641 to 1023px   top bar with the screens and Menu; Menu opens the sidebar as a drawer
     phone    640px and under top bar with Menu; the screens are a tab bar at the bottom
   Plus two inputs that are not widths: touch screens (pointer: coarse) get 16px text in fields,
   so iOS does not zoom in on them, and bigger tap targets; devices without hover do not keep
   hover effects stuck after a tap. Safe-area insets keep bars clear of notches and the home bar. */

:root { --topbar-h: 56px; --tabbar-h: 58px; --gutter: 24px; }

/* ───────── top bar, drawer and tab bar (below 1024px) ───────── */
.menu-btn { display: none; }
.drawer-close { display: none; }
.scrim[hidden] { display: none; }

@media (max-width: 1023px) {
  .topbar { overflow: visible; gap: 8px; padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); height: calc(var(--topbar-h) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); }
  .topnav { display: flex; align-items: center; gap: 2px; min-width: 0; }
  .topnav a.nav { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px; font-size: 13px; }
  .topnav a.nav svg { display: none; }
  .menu-btn { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; flex-shrink: 0; height: 40px; padding: 0 12px; border: 0; border-radius: var(--radius-inner); background: var(--chrome-hover); color: var(--on-dark-1); font-size: 13px; font-weight: 600; cursor: pointer; }
  .menu-btn:hover { background: rgb(255 255 255 / 0.12); }

  /* The sidebar as a drawer from the left, over everything but the one-sheet's own bar. */
  .sidebar { display: flex; z-index: 70; width: min(300px, 86vw); padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) env(safe-area-inset-left); transform: translateX(-100%); visibility: hidden; transition: transform var(--dur-base) var(--ease-out), visibility 0s linear var(--dur-base); }
  .sidebar[data-open] { transform: none; visibility: visible; box-shadow: var(--shadow-overlay); transition: transform var(--dur-base) var(--ease-out); }
  .sidebar .brand-row { justify-content: space-between; }
  .drawer-close { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; margin-right: -8px; }
  .sidebar nav a { height: 48px; font-size: 15px; }
  .sidebar .foot { padding-bottom: 12px; }
  .sidebar .foot .t-caption { font-size: 13.5px; line-height: 20px; }
  .sidebar .foot .t-caption a { display: inline-block; padding: 6px 0; }
  .theme-seg button { height: 36px; }
  #collapseBtn { display: none; }
  .scrim { position: fixed; inset: 0; z-index: 65; background: rgb(8 15 17 / 0.45); animation: scrim-in var(--dur-base) var(--ease-out); }
  @keyframes scrim-in { from { opacity: 0; } }
  body.drawer-open { overflow: hidden; }

  /* Sticky bars stick under the top bar, not behind it. */
  .filter-bar { top: calc(var(--topbar-h) + env(safe-area-inset-top)); }
  .page { padding-left: max(var(--gutter), env(safe-area-inset-left)); padding-right: max(var(--gutter), env(safe-area-inset-right)); }
}

@media (max-width: 640px) {
  :root { --gutter: 16px; }
  /* The screens move to a tab bar at the bottom; Admin stays in the drawer. */
  .topnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; gap: 0; padding: 4px max(4px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left)); background: var(--bg-dark); border-top: 1px solid var(--chrome-line); }
  .topnav a.nav { flex: 1 1 0; min-width: 0; height: var(--tabbar-h); padding: 6px 2px 4px; flex-direction: column; justify-content: center; gap: 4px; font-size: 10.5px; line-height: 12px; font-weight: 600; text-align: center; white-space: normal; }
  .topnav a.nav svg { display: block; flex-shrink: 0; }
  .topnav a.nav[aria-current="page"] { background: transparent; }
  .topnav a.nav[aria-current="page"] svg { color: var(--brand-accent); }
  .topnav a[data-team-nav] { display: none; }
  main { padding-bottom: calc(var(--tabbar-h) + 8px + env(safe-area-inset-bottom)); }
  /* Typing on a phone: the tab bar would ride up on the keyboard, so it steps aside. */
  body:has(.page input:focus, .page textarea:focus, .page select:focus) .topnav { display: none; }

  .page { padding-top: 16px; padding-bottom: 16px; }
  .filter-bar { margin: 0 calc(-1 * var(--gutter)) 16px; padding: 10px var(--gutter); }
  .page-head { margin-bottom: 16px; gap: 12px; }
  .t-pagetitle { font-size: 26px; line-height: 32px; }

  /* Overview hero. */
  .hero { padding: 20px; margin-bottom: 16px; }
  .hero .hero-top { flex-wrap: wrap; gap: 4px 16px; }
  .hero .t-display { font-size: 34px; line-height: 38px; }
  .hero .aside .big { font-size: 40px; line-height: 42px; }
  .grid { gap: 12px; }
  .grid + .grid { margin-top: 12px; }
  .widget > header { padding: 16px 16px 0; flex-wrap: wrap; }
  .widget > header .actions { flex-shrink: 1; flex-wrap: wrap; min-width: 0; }
  .widget > .body { padding: 14px 16px 16px; }
  .lead-grid { gap: 12px; }
  .lead-card { padding: 16px; }

  /* Filters: two to a row, full width, and the bar scrolls away with the page: stuck, even
     Contacts' (search, view, A to Z) would cover a quarter of a phone screen. */
  .filter-bar { position: static; }
  .filter-bar .pill-select { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .filter-bar .pill-select select { width: 100%; min-width: 0; text-overflow: ellipsis; }
  .filter-bar .pill-search { flex: 1 1 100%; }
  .filter-bar .pill-search input, #relationships .filter-bar .pill-search input { width: 100%; }
  #evOrg, #evWho { max-width: none; }
  #evView { flex: 1 1 100%; }
  #evView button { flex: 1; }
  .ev-toolbar { flex: 1 1 100%; justify-content: space-between; }
  .ev-toolbar .month-label { flex: 1; min-width: 0; }

  /* Contacts A to Z: one row that scrolls sideways, letters big enough to tap. */
  .org-az { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter); scroll-padding: 0 var(--gutter); }
  .org-az::-webkit-scrollbar { display: none; }
  .org-az button { flex-shrink: 0; min-width: 34px; height: 34px; line-height: 34px; }

  /* One-sheet: Back and the actions share one row that scrolls sideways. */
  .sheet-bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); justify-content: flex-start; }
  .sheet-bar::-webkit-scrollbar { display: none; }
  .sheet-bar > .btn, .sheet-bar-actions > * { flex-shrink: 0; }
  .sheet-bar-actions { flex-wrap: nowrap; margin-left: auto; }
  .sheet-inner { padding-bottom: calc(48px + env(safe-area-inset-bottom)); }
  .sheet-head .t-pagetitle { font-size: 24px; line-height: 30px; }

  /* Tables that are lists (accounts, integrations, usage, groups, import): each row a block,
     the first cell on its own line and the rest labeled from data-label. */
  table.stack, table.stack tbody, table.stack tr, table.stack td, table.stack th { display: block; }
  table.stack thead { display: none; }
  table.stack tr { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 12px 0; border-bottom: 1px solid var(--hairline); }
  table.stack tr[hidden] { display: none; }
  table.stack tbody tr:last-child { border-bottom: 0; }
  table.stack td, table.stack th { padding: 0; border: 0; min-width: 0; text-align: left; }
  table.stack td:first-child { flex: 1 1 100%; min-width: 0; }
  table.stack td.wide, table.stack td[colspan], table.stack th[colspan] { flex-basis: 100%; }
  table.stack td[data-label]::before { content: attr(data-label) ": "; color: var(--ink-3); font-weight: 600; }
  table.stack td.num { font-size: 12.5px; }
  table.stack .team-actions { justify-content: flex-start; }
  table.stack .int-group th { padding-top: 14px; }
  .int-table.stack td:first-child { flex: 1 1 auto; min-width: 0; }
  .table-scroll:has(> table.stack) { overflow-x: visible; }

  /* Events month: marks in the grid, the events listed by day under it. */
  .cal-head span { padding: 10px 0 6px; text-align: center; }
  .cal-day { min-height: 52px; padding: 4px 2px 6px; align-items: center; gap: 2px; }
  .cal-day.has-ev { cursor: pointer; }
  .cal-num { align-self: center; }
  .cal-ev { width: 70%; height: 5px; padding: 0; border: 0; border-radius: 3px; font-size: 0; pointer-events: none; background: var(--ink-4); }
  .cal-ev > * { display: none; }
  .cal-ev.going, .cal-ev.mine { background: var(--moss); }
  .cal-ev.open { background: var(--signal); }
  .cal-ev.off { background: var(--ink-4); opacity: 0.5; }
  .cal-more { display: none; }
  .cal-agenda { display: flex; flex-direction: column; gap: 16px; margin-top: 16px; }
  .cal-ag-day { display: flex; flex-direction: column; gap: 8px; scroll-margin-top: 16px; }
  .cal-ag-day.past .wk-ev { opacity: 0.62; }
  .cal-ag-head { margin: 0; color: var(--ink-3); }
  .cal-agenda .wk-ev { padding: 12px 14px; font-size: 13.5px; line-height: 19px; }
  .ev-legend { gap: 6px 14px; }

  .bid-part { grid-template-columns: 96px minmax(0, 1fr) 48px; }
  .notes-card > .body { padding: 16px; }
}
.cal-agenda { display: none; }
@media (max-width: 640px) { .cal-agenda { display: flex; } }

/* Very small phones (320 to 360px): the filters go one to a row. */
@media (max-width: 360px) {
  .filter-bar .pill-select { flex-basis: 100%; }
  .topnav a.nav { font-size: 10px; }
  .facts { grid-template-columns: 1fr; }
}

/* Phones on their side: little height, so nothing sticks but the top bar. */
@media (max-height: 500px) and (max-width: 1023px) {
  .filter-bar { position: static; }
  .sheet-bar { position: static; }
}

/* ───────── touch ───────── */
@media (pointer: coarse) {
  /* iOS zooms in on any field under 16px; these stay at 16 so the page holds still. */
  :root input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), :root select:not([multiple]), :root textarea { font-size: 16px; }
  .pill-select select, .pill-search input { height: 40px; }
  .btn { min-height: 40px; }
  .btn.sm { min-height: 36px; }
  /* The card star keeps its size; its tap area reaches past it. */
  .star-btn:not(.big)::before { content: ""; position: absolute; inset: -6px; }
  .star-btn.big { height: 40px; }
  .seg button { height: 36px; }
  .sheet-more > summary, .admin-errors summary { min-height: 36px; }
  .note-tools .link-btn, .doc-list .link-btn, .ev-going-tools .link-btn, .ev-unmatched .link-btn { padding: 8px 4px; }
  .note-tools { gap: 4px; }
  .org-row > summary { min-height: 56px; }
  .link-list { gap: 0; }
  .link-list a { display: inline-block; padding: 6px 0; }
  .mini-field select, .mini-field input, .note-who input { height: 36px; }
}
@media (hover: none) {
  .lead-card:hover, a.kpi-link:hover { transform: none; }
  .widget:hover::after { opacity: 0; }
  .note-tools { opacity: 1; }
}

@media print {
  .topbar, .topnav, .scrim, .menu-btn { display: none !important; }
  main { padding-bottom: 0 !important; }
}
