/* Phones and small tablets. Loaded last so it wins over the page styles. */
.tabbar, .more { display:none; }
.atlas { position:relative; z-index:0; }   /* keeps the map's number stamps underneath the map sheet */

@media (max-width:820px) {
  :root { --tab:calc(60px + env(safe-area-inset-bottom)); }
  html, body { height:100%; height:100dvh; }
  body { grid-template-rows:38dvh 1fr; overflow:hidden; padding-bottom:var(--tab); -webkit-text-size-adjust:100%; }
  .atlas, #map { height:38dvh; }

  /* The bar along the bottom replaces the row of section links. */
  .tabbar { position:fixed; left:0; right:0; bottom:0; z-index:6; display:grid; grid-template-columns:repeat(5,1fr); height:var(--tab); padding-bottom:env(safe-area-inset-bottom); border-top:2px solid var(--ink); background:var(--card); }
  .tabbar a, .tabbar button { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px; min-width:0; padding:4px 2px; border:0; border-right:1px solid var(--rule); background:transparent; color:var(--ink); font:700 13px/1.1 var(--text); text-align:center; text-decoration:none; cursor:pointer; }
  .tabbar > :last-child { border-right:0; }
  .tabbar svg { width:22px; height:22px; fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; }
  .tabbar .on { background:var(--ink); color:var(--card); }
  .tabbar .badge-n { position:absolute; margin:-30px 0 0 26px; min-width:18px; padding:0 4px; border-radius:9px; background:var(--overdue); color:#fff; font:700 12px/18px var(--text); }
  .more { position:fixed; inset:0 0 var(--tab) 0; z-index:5; display:flex; flex-direction:column; justify-content:flex-end; background:rgba(34,41,31,.45); }
  .more[hidden] { display:none; }
  .more-list { display:grid; grid-template-columns:1fr 1fr; gap:8px; max-height:100%; overflow-y:auto; padding:14px 14px 16px; border-top:2px solid var(--ink); background:var(--paper); }
  .more-list a, .more-list button { display:flex; align-items:center; min-height:52px; padding:8px 14px; border:1.5px solid var(--ink); border-radius:2px; background:var(--card); color:var(--ink); font:700 16px var(--text); text-align:left; text-decoration:none; cursor:pointer; }
  .more-list a.on { background:var(--ink); color:var(--card); }
  .more-list .wide { grid-column:1 / -1; }

  /* Maps: the map stays put, everything under it scrolls as one list with the search box held at the top. */
  .ledger { grid-row:2; height:auto; min-height:0; overflow-y:auto; overscroll-behavior:contain; border-right:0; border-top:2px solid var(--ink); }
  .masthead { display:flex; flex-wrap:wrap; align-items:baseline; gap:2px 12px; padding:10px 14px 8px; border-bottom:1px solid var(--rule); }
  .masthead .eyebrow, .masthead .nav { display:none; }
  .masthead h1 { margin:0; font-size:22px; }
  .tally { font-size:14px; }
  .tools { display:contents; } .ledger > *, .tools > * { flex:none; }
  .search { position:sticky; top:0; z-index:2; display:block; padding:8px 12px; border-bottom:1px solid var(--rule); background:var(--paper); }
  .filters { flex-wrap:nowrap; overflow-x:auto; margin:0; padding:8px 12px; scrollbar-width:none; }
  .filters::-webkit-scrollbar { display:none; }
  .chip { flex:none; min-height:40px; padding:6px 12px; font-size:15px; }
  .colourby { margin:0; padding:0 12px 8px; } .colourby select { min-height:44px; font-size:16px; }
  .legend { margin:0; padding:0 12px 8px; }
  .rows { flex:none; overflow:visible; border-top:1px solid var(--rule); }
  .row-link { padding:12px 14px 12px 10px; }

  /* A map's sheet takes the place of the list, so the map above it stays in view and can still be moved about. */
  .sheet { inset:38dvh 0 var(--tab) 0; width:auto; border:0; border-top:2px solid var(--ink); box-shadow:none; z-index:4; animation:none; overscroll-behavior:contain; }
  .sheet-head { position:sticky; top:0; z-index:2; gap:12px; padding:12px 56px 12px 14px; background:var(--card); }
  .numeral { font-size:44px; } .sheet-head { border-top-width:6px; }
  .close { top:6px; right:6px; width:48px; height:48px; font-size:32px; }
  .status, .sheet-links, .mapnote { padding-left:14px; padding-right:14px; }
  .actions { padding:14px; } .sheet section { padding:14px 14px 2px; }
  .sheet-links { gap:0 18px; } .sheet-links a, .links a, .sheet-add { display:inline-flex; align-items:center; min-height:44px; margin:0; }
  .linkish { min-height:44px; }
  .dnc .line1 { flex-wrap:wrap; } .dnc li { padding:8px 0; }
  .warn { max-width:none; min-height:40px; padding:4px 6px; font-size:16px; }
  .history li { padding:10px 0 10px 12px; }

  /* Section pages. */
  .desk { inset:0 0 var(--tab) 0; padding:16px 14px 48px; overscroll-behavior:contain; }
  .desk h2, .desk-head h2 { font-size:30px; }
  .desk-head { gap:10px; padding-bottom:12px; }
  .head-actions { justify-content:flex-start; }
  .panel, .person { padding:14px; }
  .primary, .quiet, .tabs a, input, select { min-height:46px; }
  .quiet, .primary { padding:10px 14px; }
  .small { min-height:40px; padding:6px 12px; }
  input[type=checkbox], input[type=radio] { min-height:0; width:22px; height:22px; flex:none; accent-color:var(--ink); }
  .tabs { flex-wrap:nowrap; overflow-x:auto; margin-right:-14px; padding-right:14px; scrollbar-width:none; } .tabs::-webkit-scrollbar { display:none; } .tabs a { flex:none; display:flex; align-items:center; }
  .desk .row, .sheet .row { grid-template-columns:1fr; }
  .action .row { grid-template-columns:1fr 1fr; }
  .desk .check, .card-set .check { white-space:normal; align-items:flex-start; min-height:40px; }
  .contact { flex-wrap:wrap; max-width:none; }
  .buttons > * { flex:1 1 auto; text-align:center; }
  .desk-head p a, .desk > p > a, .close-desk, .panel > p > a, .plain > li > a:not(.dnc-item) { display:inline-block; padding:6px 0; }

  /* Tables scroll sideways inside their own box instead of pushing the page wide. */
  .grid { display:block; max-width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
  .grid th, .grid td { padding:8px; }
  .grid thead th { white-space:nowrap; }
  .grid tbody th { position:sticky; left:0; background:var(--card); min-width:110px; max-width:150px; box-shadow:1px 0 0 var(--rule); }

  /* People as a list of cards. */
  .people-grid, .people-grid tbody { display:block; overflow:visible; border:0; background:transparent; }
  .people-grid thead { display:none; }
  .people-grid tr { display:grid; grid-template-columns:1fr auto; gap:2px 12px; margin:0 0 8px; padding:10px 12px; border:1.5px solid var(--ink); background:var(--card); }
  .people-grid th, .people-grid td, .people-grid td.num { display:block; min-width:0; max-width:none; padding:0; border:0; position:static; background:transparent; box-shadow:none; text-align:left; }
  .people-grid tbody th { grid-column:1 / -1; min-width:0; max-width:none; background:transparent; box-shadow:none; font:700 19px var(--slab); }
  .people-grid td::before { content:attr(data-label) ": "; color:var(--soft); }
  .people-grid td:empty { display:none; }

  .tiles { grid-template-columns:1fr 1fr; gap:8px; } .tile { padding:10px 12px; } .tile-n { font-size:34px; }
  .today-cols, .queue-cols { grid-template-columns:1fr; }
  .queue-list { max-height:none; } .queue-list li { padding:10px; }
  .next-line { flex-wrap:wrap; }
  .linkside { min-width:0; } .linkpanel { gap:12px; }
  .cols { columns:1; }
  .campaign-maps { gap:6px; } .dot { min-width:40px; min-height:36px; display:inline-flex; align-items:center; justify-content:center; }
  .card-reprints .dot { display:inline-flex; align-items:center; justify-content:center; min-width:42px; min-height:40px; padding:0 6px; }
  .s13 { font-size:13px; }
  .dnc-layout.editing .dnc-list { display:none; }
  .dnc-list { max-height:none; } .dnc-item { padding:12px; } .dnc-map { height:52dvh; }

  /* Cards: the picture first, then its settings. */
  .card-studio { display:flex; flex-direction:column; } .card-main { order:-1; width:100%; }
  .card-controls { order:0; }
  .card-preview { padding:8px; } .card-stage svg { width:100%; }
  .card-set .check { min-height:44px; align-items:center; }

  /* Boundaries: tools in one strip along the top, details in a drawer at the bottom. */
  .bd { display:flex; flex-direction:column; }
  .bd-map { position:relative; inset:auto; flex:1 1 0; min-height:36%; }
  .bd-bar { position:static; order:-1; flex:none; max-width:none; flex-wrap:nowrap; overflow-x:auto; gap:6px 10px; padding:6px 10px; border-width:0 0 2px; box-shadow:none; scrollbar-width:none; }
  .bd-bar::-webkit-scrollbar { display:none; }
  .bd-bar > * { flex:none; } .bd .check { white-space:nowrap; }
  .bd-panel { position:static; flex:0 1 auto; width:auto; max-height:54%; padding:0 14px 20px; border-width:2px 0 0; box-shadow:none; }
  .bd-head { margin:0 -14px; padding:10px 52px 10px 14px; } .bd-head .numeral { font-size:40px; }
  .bd-panel h2 { font-size:24px; }
  .bd-map { isolation:isolate; }
  .bd-stamp { min-width:32px; height:32px; line-height:26px; }
  .stamp { min-width:30px; height:30px; line-height:25px; }

  body.signin { padding-bottom:0; }
}
@media (max-width:820px) and (max-height:520px) { body { grid-template-rows:46dvh 1fr; } .atlas, #map { height:46dvh; } .sheet { top:46dvh; } }
@media (max-width:380px) { .tabbar a, .tabbar button { font-size:12px; } .more-list { grid-template-columns:1fr; } }
