/*
 * iOS-style components, shared by the desktop and the phone (behaviour in static/js/ios.js).
 *
 *   .ios-seg         a segmented control: tabs that are one choice
 *   action sheet     VigilIOS.sheet({...}) — grouped choices over a dimmed page, Cancel apart
 *   HUD              VigilIOS.hud('Snoozed for 4 h') — the brief confirmation that fades by itself
 *   .swipe           a list row that slides left to reveal its actions (touch), with a full swipe for the first
 *   .ios-list        a grouped, inset list: rounded card, hairline separators inset past the icon
 *
 * Colours come from each shell's tokens (--surface, --text, --accent…), so light and dark both hold; the system tints
 * (orange, indigo, green, red) are Apple's, used only where iOS uses them — on swipe actions and destructive choices.
 */
:root { --ios-orange: #FF9500; --ios-indigo: #5856D6; --ios-green: #34C759; --ios-red: #FF3B30; --ios-blue: #007AFF; --ios-spring: cubic-bezier(.32, .72, 0, 1); }

/* ── segmented control ───────────────────────────────────────────────────────────────────────────────────────── */
.ios-seg { display: inline-flex; max-width: 100%; overflow-x: auto; scrollbar-width: none; padding: 2px; border-radius: 10px; gap: 1px;
  background: color-mix(in srgb, var(--text) 8%, transparent); -webkit-overflow-scrolling: touch; }
.ios-seg::-webkit-scrollbar { display: none; }
.ios-seg > a, .ios-seg > button { flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px; padding: 6px 13px; border-radius: 8px; border: 0; background: none;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--text); text-decoration: none; white-space: nowrap; cursor: pointer; transition: background .2s, box-shadow .2s; }
.ios-seg > a:hover, .ios-seg > button:hover { background: color-mix(in srgb, var(--surface) 45%, transparent); }
.ios-seg > .on { background: var(--surface); box-shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 1px 1px rgba(0, 0, 0, .05); display: inline-flex; width: auto; height: auto; border-radius: 8px; opacity: 1; }
.ios-seg .n { font-size: 11.5px; font-weight: 650; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ios-seg .n.hot { color: #fff; background: var(--ios-red); border-radius: 999px; padding: 0 6px; min-width: 18px; text-align: center; line-height: 17px; }

/* ── action sheet ────────────────────────────────────────────────────────────────────────────────────────────── */
.ios-backdrop { position: fixed; inset: 0; z-index: 12000; background: rgba(0, 0, 0, .34); opacity: 0; transition: opacity .28s ease; }
.ios-backdrop.in { opacity: 1; }
.ios-sheet { position: fixed; left: 50%; bottom: 0; z-index: 12001; width: min(calc(100vw - 16px), 420px); padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 110%); transition: transform .45s var(--ios-spring); font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", sans-serif; }
.ios-sheet.in { transform: translate(-50%, 0); }
@media (min-width: 769px) { .ios-sheet { bottom: 28px; padding-bottom: 0; } }
.ios-group { border-radius: 14px; overflow: hidden; margin-bottom: 8px; box-shadow: 0 12px 40px rgba(0, 0, 0, .28);
  background: color-mix(in srgb, var(--surface) 86%, transparent); -webkit-backdrop-filter: blur(28px) saturate(1.8); backdrop-filter: blur(28px) saturate(1.8); }
.ios-head { padding: 14px 18px 13px; text-align: center; }
.ios-head b { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); }
.ios-head p { font-size: 12.5px; color: var(--text-3); margin: 3px 0 0; line-height: 1.4; }
.ios-group button { display: block; width: 100%; padding: 15px 16px; border: 0; background: none; cursor: pointer; font: inherit; font-size: 17px; color: var(--accent);
  border-top: .5px solid color-mix(in srgb, var(--text) 16%, transparent); transition: background .12s; }
.ios-group > button:first-child { border-top: 0; }
.ios-group button:hover, .ios-group button:active { background: color-mix(in srgb, var(--text) 8%, transparent); }
.ios-group button small { display: block; margin-top: 2px; font-size: 12px; color: var(--text-3); }
.ios-group button.destructive { color: var(--ios-red); }
.ios-group button.cancel { font-weight: 600; }

/* ── HUD ─────────────────────────────────────────────────────────────────────────────────────────────────────── */
.ios-hud { position: fixed; left: 50%; top: 50%; z-index: 12002; min-width: 150px; max-width: 260px; padding: 18px 20px 16px; border-radius: 16px; text-align: center;
  color: var(--text); font-size: 14px; font-weight: 600; transform: translate(-50%, -50%) scale(.9); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .35s var(--ios-spring); background: color-mix(in srgb, var(--surface) 80%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(1.8); backdrop-filter: blur(24px) saturate(1.8); box-shadow: 0 10px 34px rgba(0, 0, 0, .22); }
.ios-hud.in { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.ios-hud svg { display: block; width: 34px; height: 34px; margin: 0 auto 8px; color: var(--ios-green); }

/* ── swipe actions ───────────────────────────────────────────────────────────────────────────────────────────── */
.swipe { position: relative; overflow: hidden; touch-action: pan-y; }
.swipe-actions { position: absolute; top: 0; right: 0; bottom: 0; display: flex; }
.swipe-actions button { width: 78px; border: 0; color: #fff; cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.swipe-actions button svg { width: 20px; height: 20px; }
.swipe-actions .ack { background: var(--ios-orange); } .swipe-actions .snooze { background: var(--ios-indigo); }
.swipe-actions .resolve { background: var(--ios-green); } .swipe-actions .read { background: var(--ios-blue); } .swipe-actions .ignore { background: #8E8E93; }
.swipe-content { position: relative; z-index: 1; background: var(--surface); transition: transform .4s var(--ios-spring); will-change: transform; }
.swipe.dragging .swipe-content { transition: none; }

/* ── grouped inset list ──────────────────────────────────────────────────────────────────────────────────────── */
.ios-list { background: var(--surface); border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.ios-list > * + * { box-shadow: inset 16px .5px 0 var(--surface), inset 0 .5px 0 var(--border); }
.ios-caption { font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); margin: 18px 16px 6px; font-weight: 500; }
.ios-footnote { font-size: 12.5px; color: var(--text-3); margin: 6px 16px 14px; line-height: 1.4; }

@media (prefers-reduced-motion: reduce) { .ios-sheet, .ios-hud, .swipe-content { transition-duration: .01s; } }

/* ── searchable picker (VigilIOS.picker): a popover on the desktop, a bottom sheet on the phone ────────────────── */
.ios-picker { position: fixed; z-index: 12001; width: 380px; max-width: calc(100vw - 16px); display: flex; flex-direction: column; overflow: hidden;
  border-radius: 14px; border: 1px solid var(--border); box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
  background: color-mix(in srgb, var(--surface) 90%, transparent); -webkit-backdrop-filter: blur(28px) saturate(1.8); backdrop-filter: blur(28px) saturate(1.8);
  opacity: 0; transform: translateY(-6px) scale(.98); transform-origin: top left; transition: opacity .18s, transform .3s var(--ios-spring); }
.ios-picker.in { opacity: 1; transform: none; }
.ios-picker .pk-search { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: .5px solid var(--border); }
.ios-picker .pk-search svg { width: 16px; height: 16px; color: var(--text-3); flex-shrink: 0; }
.ios-picker .pk-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); font: inherit; font-size: 15px; padding: 4px 0; }
.ios-picker .pk-list { overflow-y: auto; max-height: min(60vh, 460px); padding: 6px; overscroll-behavior: contain; }
.ios-picker .pk-cap { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 8px 10px 4px; }
.ios-picker .pk-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 9px; border: 0; background: none; cursor: pointer;
  text-align: left; font: inherit; color: var(--text); }
.ios-picker .pk-row.hi { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.ios-picker .pk-row .t { flex: 1; min-width: 0; }
.ios-picker .pk-row b { display: block; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ios-picker .pk-row small { display: block; font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ios-picker .pk-row mark { background: none; color: var(--accent); font-weight: 750; }
.ios-picker .pk-row .bd { font-size: 11px; font-weight: 700; color: #fff; background: var(--ios-red); border-radius: 999px; padding: 1px 7px; }
.ios-picker .pk-row .ck { width: 16px; height: 16px; color: var(--accent); flex-shrink: 0; }
.ios-picker .pk-empty { padding: 22px 12px; text-align: center; color: var(--text-3); font-size: 13.5px; }
.ios-picker .pk-foot { font-size: 11.5px; color: var(--text-3); padding: 7px 12px; border-top: .5px solid var(--border); display: flex; gap: 12px; }
.ios-picker .pk-foot kbd { font: inherit; font-size: 10.5px; padding: 0 5px; border: 1px solid var(--border); border-radius: 4px; }
@media (max-width: 768px) {
  .ios-picker { left: 0 !important; right: 0; top: auto !important; bottom: 0; width: 100%; max-width: none; height: 82dvh; border-radius: 16px 16px 0 0;
    transform: translateY(100%); padding-bottom: env(safe-area-inset-bottom, 0px); }
  .ios-picker.in { transform: none; }
  .ios-picker .pk-list { max-height: none; flex: 1; }
  .ios-picker .pk-search { padding: 14px 16px 10px; } .ios-picker .pk-search input { font-size: 17px; }
  .ios-picker .pk-grab { width: 38px; height: 5px; border-radius: 3px; background: var(--border-2, var(--border)); margin: 8px auto 0; }
  .ios-picker .pk-row { padding: 12px; } .ios-picker .pk-row b { font-size: 16px; }
  .ios-picker .pk-foot { display: none; }
}
@media (min-width: 769px) { .ios-picker .pk-grab { display: none; } }

/* ── the scope chip in the ribbon ─────────────────────────────────────────────────────────────────────────────── */
.scope-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 260px; height: 30px; padding: 0 6px 0 10px; border-radius: 999px; border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 70%, transparent); color: var(--text-2); font: inherit; font-size: 12.5px; font-weight: 650; cursor: pointer; flex-shrink: 1; min-width: 0; }
.scope-chip:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.scope-chip svg { width: 14px; height: 14px; flex-shrink: 0; }
.scope-chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scope-chip.on { color: var(--text); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.scope-chip .x { display: inline-flex; width: 18px; height: 18px; border-radius: 50%; align-items: center; justify-content: center; color: var(--text-3); }
.scope-chip .x:hover { background: color-mix(in srgb, var(--text) 12%, transparent); color: var(--text); }

/* ── the page header: a large title that hands over to the ribbon as the page scrolls (iOS large titles) ─────────
   {% pagehead %} writes .page-head; the older .page-header markup gets the same look, so every page matches. */
.page-head, .page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 2px 0 20px; }
.page-head .ph-t, .page-header > div:first-child { min-width: 0; flex: 1 1 360px; }
.page-head h1, .page-header h1 { font-size: 30px; line-height: 1.12; font-weight: 780; letter-spacing: -.025em; margin: 0; color: var(--text);
  transition: opacity .25s ease, transform .35s var(--ios-spring); transform-origin: left bottom; }
.page-head .ph-sub, .page-header h1 + p { margin: 6px 0 0; font-size: 14px; line-height: 1.5; color: var(--text-2); max-width: 860px; }
.page-head .ph-acts { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
html.vg-titled .page-head h1, html.vg-titled .page-header h1 { opacity: 0; transform: scale(.96) translateY(-4px); }
.topbar-breadcrumb .current { transition: font-weight .2s, color .2s; }
html.vg-titled .topbar-breadcrumb .current { font-weight: 750; color: var(--text); }
@media (max-width: 900px) { .page-head h1, .page-header h1 { font-size: 24px; } }

/* the phone: the page's title large under the header, handing over to the header's own as it scrolls */
.m-large { font-size: 30px; font-weight: 800; letter-spacing: -.025em; line-height: 1.1; margin: 2px 0 12px; color: var(--text);
  transition: opacity .25s ease, transform .35s var(--ios-spring); transform-origin: left bottom; }
html.vg-titled .m-large { opacity: 0; transform: scale(.96); }
.top .t { transition: opacity .25s ease; }
html.m-has-large:not(.vg-titled) .top .t { opacity: 0; }

/* ── the iOS switch: <input type="checkbox" class="switch"> ───────────────────────────────────────────────────── */
input[type=checkbox].switch { -webkit-appearance: none; appearance: none; width: 51px !important; min-width: 51px; height: 31px; margin: 0; padding: 0; border: 0;
  border-radius: 16px; background: rgba(120, 120, 128, .32); position: relative; cursor: pointer; flex-shrink: 0; transition: background .25s ease; }
input[type=checkbox].switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 1px 1px rgba(0, 0, 0, .16); transition: transform .32s var(--ios-spring); }
input[type=checkbox].switch:checked { background: var(--ios-green); }
input[type=checkbox].switch:checked::after { transform: translateX(20px); }
input[type=checkbox].switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=checkbox].switch:disabled { opacity: .5; cursor: default; }
/* the compact one, for toolbars */
input[type=checkbox].switch.sm { width: 38px !important; min-width: 38px; height: 23px; }
input[type=checkbox].switch.sm::after { width: 19px; height: 19px; }
input[type=checkbox].switch.sm:checked::after { transform: translateX(15px); }
/* a switch in a label sits level with its words */
label:has(> input[type=checkbox].switch) { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
label:has(> input[type=checkbox].switch.sm) { gap: 7px; }
