/* SES Access Monitor: shared styles (parent page + admin) */
:root {
  --open: #17914a;
  --closed: #d4342a;
  --ink: #16202a;
  --muted: #5d6973;
  --line: #e3e7ea;
  --bg: #f4f6f7;
  --card: #fff;
  --brand: #123a5c;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --page-max: 1600px;
  --gutter: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
button, input, textarea, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }
.err { color: var(--closed); font-weight: 600; min-height: 1.2em; margin: 8px 0 0; font-size: 0.9rem; }
.row { display: flex; gap: 10px; margin-top: 16px; }
.row .btn { flex: 1; }

/* ---------- Header ---------- */
.top { background: var(--brand); color: #fff; }
.top-in {
  display: flex; align-items: center; gap: 14px;
  max-width: var(--page-max); margin: 0 auto;
  padding: calc(14px + var(--safe-t)) var(--gutter) 14px;
}
.top-icon { flex: none; border-radius: 11px; box-shadow: 0 1px 4px rgba(0,0,0,0.3); }
.brand { flex: 1; min-width: 0; }
.brand h1 { margin: 0; font-size: 1.35rem; letter-spacing: 0.2px; }
.brand p { margin: 3px 0 0; font-size: 0.82rem; opacity: 0.85; line-height: 1.35; }
.brand a { color: #fff; }
.updated { flex: none; font-size: 0.75rem; opacity: 0.85; white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 14px; min-height: 44px;
  font-weight: 600; cursor: pointer; touch-action: manipulation;
}
.btn.small { min-height: 38px; padding: 7px 10px; font-size: 0.88rem; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; min-height: 54px; font-size: 1.05rem; border-radius: 14px; }
.btn:disabled { opacity: 0.55; }
.btn.confirm-closed { background: var(--closed); border-color: var(--closed); color: #fff; }
.btn.confirm-open { background: var(--open); border-color: var(--open); color: #fff; }

/* Segmented control (admin tabs) */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 10px 12px; padding: 4px; background: #e3e8ec; border-radius: 12px; }
.seg button { border: 0; background: transparent; padding: 10px 6px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; min-height: 44px; }
.seg button[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.15); }

/* ---------- Map (shared) ---------- */
.leaflet-tile-pane { filter: grayscale(1) contrast(0.9) brightness(1.05); }
.leaflet-container { background: #eceeef; font: inherit; }
.gate-icon {
  background: var(--brand); color: #fff; border: 2px solid #fff; border-radius: 8px;
  font-size: 11px; font-weight: 700; display: grid; place-items: center; box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}
.hide-gates .gate-icon { display: none; }
.leaflet-container .school-logo img {
  width: var(--logo-w, 84px) !important; height: auto !important; display: block;
  transform: translate(-50%, -50%); filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3)); pointer-events: none;
}
/* Route tags drawn on the map (IN 1, OUT 2 …) */
.route-pill {
  --c: var(--open);
  display: inline-flex !important; align-items: center; justify-content: center; white-space: nowrap;
  width: auto !important; height: auto !important; padding: 2px 7px; border-radius: 999px;
  background: #fff; color: var(--c); border: 2px solid var(--c); font-size: 11px; font-weight: 800; letter-spacing: 0.3px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3); cursor: pointer;
}
.leaflet-marker-icon.route-pill { margin-left: -22px !important; margin-top: -11px !important; transition: opacity 0.12s; }
.route-pill.on { background: var(--c); color: #fff; z-index: 1000 !important; }
.route-pill.faded { opacity: 0.5; }

/* ---------- Parent page: one screen, no scrolling ---------- */
body.parent { height: 100vh; height: 100svh; display: flex; flex-direction: column; overflow: hidden; }
.app {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  width: 100%; max-width: var(--page-max); margin: 0 auto; padding: 10px var(--gutter) 0;
}
.map-box { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; border-radius: var(--radius); border: 1px solid var(--line); z-index: 0; }
.below { flex: none; padding: 8px 76px calc(10px + var(--safe-b)) 4px; }   /* right padding leaves room for the chat button */
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 18px; height: 5px; border-radius: 3px; }
.sw.open { background: var(--open); } .sw.closed { background: var(--closed); }
.sw.dashed { background: repeating-linear-gradient(90deg, #8b9298 0 5px, transparent 5px 8px); }
.drive-line { margin: 5px 0 0; font-weight: 700; font-size: 0.88rem; }

/* Zoom buttons: middle of the left edge, clear of the bubble strips */
.leaflet-top.leaflet-left { top: 50%; transform: translateY(-50%); }
.leaflet-control-attribution { font-size: 9px; }

/* Bubble strips over the map */
.strip { position: absolute; left: 10px; right: 10px; z-index: 900; pointer-events: none; max-width: 900px; margin: 0 auto; }
.strip-in { top: 8px; }
.strip-out { bottom: 18px; }
.strip-title { display: flex; align-items: center; justify-content: space-between; margin: 0 0 5px; }
.dir-badge { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; font-size: 0.85rem; padding: 4px 12px; border-radius: 999px; box-shadow: 0 1px 4px rgba(0,0,0,0.25); }
.dir-badge.in { background: var(--brand); color: #fff; }
.dir-badge.out { background: #fff; color: var(--brand); border: 2px solid var(--brand); }
.strip-hint { font-size: 0.7rem; font-weight: 700; color: #3c4650; background: rgba(255,255,255,0.9); padding: 2px 9px; border-radius: 999px; }
.bubbles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; pointer-events: auto; }

.bubble {
  position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  min-height: 72px; padding: 7px 9px; border: 0; border-radius: 14px; color: #fff; text-align: left; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.28);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none;
  transition: transform 0.12s, box-shadow 0.12s;
}
.bubble.open { background: var(--open); }
.bubble.closed { background: var(--closed); }
.bubble.selected { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--brand), 0 4px 12px rgba(0,0,0,0.3); }
.bubble.holding { transform: scale(0.97); }
.bubble:focus-visible { outline: 3px solid #7fb0dd; outline-offset: 2px; }
.bubble > span { position: relative; z-index: 1; }
.b-top { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 4px; }
.b-tag { font-size: 0.72rem; font-weight: 800; background: rgba(255,255,255,0.22); padding: 1px 6px; border-radius: 999px; white-space: nowrap; }
.b-status { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; }
.b-name { font-size: 0.74rem; font-weight: 600; line-height: 1.15; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.b-hold { margin-top: auto; font-size: 0.64rem; font-weight: 700; opacity: 0.85; white-space: nowrap; }
.bubble.holding .b-hold::after { content: " …"; }
/* The fill sweeps across the button while it is held. */
.b-fill { position: absolute !important; inset: 0; z-index: 0 !important; background: rgba(255,255,255,0.38); transform: scaleX(0); transform-origin: left; }
.bubble.holding .b-fill { transform: scaleX(1); transition: transform var(--hold-ms, 2500ms) linear; }
.bubble.done .b-fill { transform: scaleX(1); background: rgba(255,255,255,0.55); }

/* Holding a bubble: the header turns amber, says what will happen, and fills along the bottom */
.top { position: relative; transition: background 0.15s, color 0.15s; }
.top-in { position: relative; }
.hold-msg { position: absolute; inset: var(--safe-t) var(--gutter) 0; display: flex; align-items: center; justify-content: center; text-align: center; margin: 0; font-weight: 800; font-size: 1.05rem; opacity: 0; pointer-events: none; }
.hold-bar { position: absolute; left: 0; bottom: 0; height: 4px; width: 100%; background: var(--ink); transform: scaleX(0); transform-origin: left; }
body.is-holding .top { background: #ffc629; color: var(--ink); }
body.is-holding .top-in > :not(.hold-msg) { visibility: hidden; }
body.is-holding .hold-msg { opacity: 1; }
body.is-holding .hold-bar { transform: scaleX(1); transition: transform var(--hold-ms, 2500ms) linear; }

/* Moving dots inside each route line (direction of travel) */
.leaflet-container path.flow { animation: flow 0.9s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -16; } }
@media (prefers-reduced-motion: reduce) { .leaflet-container path.flow { animation: none; } }

/* Reset view button (under the zoom buttons; on its own on phones) */
.reset-view { display: grid; place-items: center; width: 34px; height: 34px; background: #fff; color: var(--ink); cursor: pointer; padding: 0; border-radius: 8px; }
.reset-view:hover { background: #f1f4f6; }

/* ---------- Chat (comments & suggestions) ---------- */
.chat-fab {
  position: fixed; right: 16px; bottom: calc(14px + var(--safe-b)); z-index: 1500;
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--brand); color: #fff;
  display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,0.3); cursor: pointer;
}
.chat-fab[aria-expanded="true"] { background: #2a4d6e; }
.chat {
  position: fixed; z-index: 1600; right: 16px; bottom: calc(82px + var(--safe-b));
  width: min(360px, calc(100vw - 24px)); height: min(500px, calc(100svh - 120px));
  display: flex; flex-direction: column; background: #fff; border-radius: 18px; overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}
.chat[hidden] { display: none; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 14px; background: var(--brand); color: #fff; }
.chat-head img { border-radius: 9px; }
.chat-head div { flex: 1; display: flex; flex-direction: column; }
.chat-head small { opacity: 0.8; font-size: 0.75rem; }
.chat-x { background: transparent; border: 0; color: #fff; font-size: 1.8rem; line-height: 1; width: 40px; height: 40px; cursor: pointer; }
.chat-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #f1f3f5; }
.msg { max-width: 82%; padding: 9px 12px; border-radius: 18px; font-size: 0.92rem; line-height: 1.35; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.them { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 6px; }
.msg-meta { font-size: 0.7rem; color: var(--muted); align-self: flex-end; margin-top: -4px; }
.chat-input { display: flex; align-items: flex-end; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: #fff; }
.chat-input textarea {
  flex: 1; resize: none; border: 1px solid #cfd5da; border-radius: 20px; padding: 10px 14px; font-size: 16px;
  max-height: 110px; line-height: 1.3;
}
.chat-input button { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; display: grid; place-items: center; cursor: pointer; }
.chat-input button:disabled { opacity: 0.5; }

/* ---------- Dialogs & toast ---------- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; background: #fff; color: var(--ink); box-shadow: 0 -8px 30px rgba(0,0,0,0.2);
}
dialog.sheet::backdrop, dialog.confirm::backdrop { background: rgba(10, 20, 30, 0.45); }
.sheet-body { padding: 8px 16px calc(16px + var(--safe-b)); }
.grab { width: 40px; height: 5px; border-radius: 3px; background: #d6dadd; margin: 2px auto 10px; }
.sheet h2 { margin: 0 0 6px; font-size: 1.2rem; }
#classInput { width: 100%; border: 1px solid #cfd5da; border-radius: 12px; padding: 12px; min-height: 48px; font-size: 1.4rem; text-align: center; letter-spacing: 2px; text-transform: uppercase; margin-top: 6px; }
dialog.confirm { border: 0; border-radius: 18px; padding: 22px; width: min(420px, 92vw); box-shadow: 0 20px 50px rgba(0,0,0,0.3); }
dialog.confirm h2 { margin: 0 0 6px; font-size: 1.25rem; }
dialog.confirm p { margin: 0; }

.toast {
  position: fixed; left: 50%; top: 46%; text-align: center; transform: translate(-50%, 10px);
  display: flex; align-items: center; gap: 12px; white-space: nowrap;
  background: #16202a; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 0.92rem;
  opacity: 0; pointer-events: none; transition: 0.2s; z-index: 2000; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.has-action { pointer-events: auto; }
.toast-btn { background: transparent; border: 0; color: #8fd3ff; font-weight: 800; padding: 6px 4px; cursor: pointer; }

/* ---------- Phones ---------- */
@media (max-width: 699px) {
  :root { --gutter: 8px; }
  .top-in { padding-top: calc(10px + var(--safe-t)); padding-bottom: 10px; gap: 10px; }
  .top-icon { width: 36px; height: 36px; border-radius: 9px; }
  .brand h1 { font-size: 1.1rem; }
  .brand p { font-size: 0.72rem; }
  .updated { display: none; }
  .app { padding-top: 8px; }
  .strip { left: 6px; right: 6px; }
  .strip-out { bottom: 16px; }
  .bubbles { gap: 6px; }
  .bubble { min-height: 68px; padding: 6px 8px; }
  .below { padding-right: 70px; }
  .legend { font-size: 0.74rem; gap: 2px 10px; }
  .drive-line { font-size: 0.82rem; }
  .chat-fab { width: 52px; height: 52px; right: 10px; bottom: calc(10px + var(--safe-b)); }
  /* The chat opens as a sheet from the bottom on phones. */
  .chat { left: 0; right: 0; bottom: 0; width: 100%; height: 75svh; border-radius: 18px 18px 0 0; }
  .chat-input { padding-bottom: calc(10px + var(--safe-b)); }
  .leaflet-control-zoom { display: none; }   /* pinch to zoom */
  .reset-view { width: 40px; height: 40px; }
  .leaflet-top.leaflet-left .leaflet-control { margin-left: 8px; }
  /* No page zoom or scroll from the header or the legend */
  .top, .below { touch-action: none; }
}

/* Desktop header: a little taller */
@media (min-width: 700px) {
  .top-in { padding-top: calc(18px + var(--safe-t)); padding-bottom: 18px; }
  .top-icon { width: 50px; height: 50px; }
  .brand h1 { font-size: 1.55rem; }
  .brand p { font-size: 0.9rem; }
}
