:root {
      --bg: #0b1220;
      --panel: #111827;
      --text: #f9fafb;
      --muted: #9ca3af;
      --border: #334155;
    }

    * { box-sizing: border-box; }

    html, body {
      margin: 0;
      width: 100%;
      height: 100%;
      overflow: hidden;
      font-family: Arial, Helvetica, sans-serif;
      background: var(--bg);
      color: var(--text);
    }

    body {
      display: grid;
      place-items: center;
      padding: 20px;
    }

    .card {
      width: min(440px, 100%);
      background: var(--panel);
      border: 1px solid var(--border);
      border-radius: 20px;
      padding: 28px;
      box-shadow: 0 10px 30px rgba(0,0,0,0.35);
    }

    h1 {
      margin: 0 0 10px;
      font-size: 32px;
      line-height: 1.05;
    }

    p {
      margin: 0 0 20px;
      color: var(--muted);
      font-size: 15px;
      line-height: 1.45;
    }

    label {
      display: block;
      font-size: 13px;
      margin-bottom: 8px;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 0.08em;
    }

    input {
      width: 100%;
      padding: 14px 16px;
      border-radius: 14px;
      border: 1px solid var(--border);
      background: #0f172a;
      color: var(--text);
      font-size: 16px;
      outline: none;
    }

    button {
      width: 100%;
      margin-top: 16px;
      padding: 14px 16px;
      border: 0;
      border-radius: 14px;
      background: #2563eb;
      color: white;
      font-size: 16px;
      font-weight: 700;
      cursor: pointer;
    }

    .error {
      margin-top: 14px;
      color: #fecaca;
      background: rgba(220, 38, 38, 0.15);
      border: 1px solid rgba(220, 38, 38, 0.3);
      border-radius: 12px;
      padding: 12px 14px;
      font-size: 14px;
    }
  
  .progress-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
  }
  .times-card .time-box {
    min-height: 92px;
    padding: 14px;
  }
  .times-card .time-label {
    font-size: 12px;
  }
  .times-card .time-value {
    font-size: 19px;
    line-height: 1.25;
  }
  .staffing-card {
    margin-top: 14px;
  }
  .staffing-role-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 12px;
  }
  .staffing-role-card {
    background: var(--panel3);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 14px;
    min-height: 96px;
  }
  .staffing-role-label, .staffing-schedule-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
    margin-bottom: 8px;
  }
  .staffing-role-name {
    font-size: 20px;
    font-weight: 800;
    line-height: 1.15;
    margin-bottom: 6px;
  }
  .staffing-role-shift, .staffing-schedule-time {
    font-size: 14px;
    color: var(--textSoft);
    line-height: 1.35;
  }
  .staffing-schedule-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }
  .staffing-schedule-card {
    background: var(--panel3);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 14px;
    min-height: 150px;
  }
  .staffing-schedule-item + .staffing-schedule-item {
    border-top: 1px solid rgba(255,255,255,0.07);
    margin-top: 10px;
    padding-top: 10px;
  }
  .staffing-schedule-name {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
  }
  @media (max-width: 1500px) {
    .progress-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }
  @media (max-width: 1200px) {
    .staffing-role-grid,
    .staffing-schedule-grid {
      grid-template-columns: 1fr;
    }
  }


  /* iPad mounted/kiosk landscape layout v2.
     This is more aggressive than the general tablet rules because the mounted iPad
     has limited vertical space once Safari chrome is visible. */
  @media (pointer: coarse) and (orientation: landscape) and (min-width: 900px) and (max-width: 1200px) and (max-height: 900px) {
    html, body {
      height: 100%;
      width: 100%;
      overflow: hidden;
      -webkit-text-size-adjust: 100%;
    }

    body {
      padding: 6px;
    }

    .board {
      height: calc(100dvh - 12px);
      min-height: calc(100dvh - 12px);
      grid-template-rows: auto 1fr;
      gap: 6px;
      overflow: hidden;
    }

    .topbar {
      padding: 7px 9px;
      border-radius: 16px;
      min-height: 52px;
      grid-template-columns: minmax(0, 1fr) auto;
      gap: 8px;
    }

    .topbar-left,
    .brand {
      gap: 8px;
    }

    .menu-button {
      width: 38px;
      height: 38px;
      border-radius: 12px;
    }

    .logo-mark {
      width: 38px;
      height: 38px;
      border-radius: 12px;
    }

    .title {
      font-size: 22px;
      max-width: 290px;
    }

    .subtitle {
      font-size: 10px;
      margin-top: 1px;
    }

    .topbar-right {
      gap: 5px;
      flex-wrap: nowrap;
      min-width: 0;
    }

    .pill,
    .logout-button {
      padding: 7px 9px;
      font-size: 11px;
      border-radius: 14px;
      min-height: 32px;
    }

    #badgeRunNumber,
    #badgeUnitsOnCall {
      max-width: 170px;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .helper-bar {
      display: none;
    }

    .main {
      height: 100%;
      min-height: 0;
      overflow: hidden;
      display: grid;
      grid-template-columns: minmax(0, 1.12fr) minmax(340px, 0.88fr);
      grid-template-rows: minmax(0, 1fr);
      gap: 6px;
    }

    .panel {
      border-radius: 16px;
    }

    .map-panel {
      height: 100%;
      min-height: 0;
      display: grid;
      grid-template-rows: auto minmax(0, 1fr);
      overflow: hidden;
    }

    .section-header {
      padding: 7px 9px 0;
      font-size: 14px;
    }

    .map-wrap {
      height: 100%;
      min-height: 0;
      padding: 7px 9px 9px;
      grid-template-rows: auto minmax(0, 1fr);
      gap: 6px;
    }

    .route-header {
      grid-template-columns: 1fr 1fr;
      gap: 6px;
    }

    .route-box {
      padding: 7px 8px;
      border-radius: 13px;
      min-height: 58px;
    }

    .route-box .small {
      font-size: 9px;
      margin-bottom: 3px;
    }

    .route-box .big {
      font-size: 13px;
      line-height: 1.1;
    }

    .route-box .coords {
      font-size: 10px;
      line-height: 1.1;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .map-frame-wrap {
      height: 100%;
      min-height: 315px;
      border-radius: 14px;
    }

    #mapFrame,
    #leafletRouteMap {
      height: 100% !important;
      min-height: 315px;
    }

    .info-stack {
      min-height: 0;
      /* Phase 4: scroll instead of clip so duty staffing isn't cut off
         on iPad mounted view. The grid was using height:100% +
         overflow:hidden which fit the legacy 8-box layout but cuts the
         taller per-unit checklist. */
      overflow-y: auto;
      display: grid;
      grid-template-rows: auto auto auto;
      gap: 6px;
      align-content: start;
    }
    .info-stack::-webkit-scrollbar {
      width: 5px;
    }
    .info-stack::-webkit-scrollbar-thumb {
      background: var(--border);
      border-radius: 3px;
    }

    .call-card {
      padding: 10px;
      min-height: 118px;
      overflow: hidden;
    }

    .call-tags,
    .excerpt-box,
    .staffing-card {
      display: none !important;
    }

    .call-nature {
      font-size: clamp(28px, 3.2vw, 36px);
      line-height: 0.96;
      max-height: 72px;
      overflow: hidden;
    }

    .call-location {
      margin-top: 7px;
      font-size: 14px;
      line-height: 1.1;
    }

    .call-address {
      display: none;
    }

    .times-card {
      min-height: 0;
      /* Phase 3/4: dropping the height:100% clamp because the per-unit
         checklist content is taller than the legacy 8 boxes and the height
         clamp + overflow:auto combo was what clipped the duty staffing
         panel below. Let the panel size to its content; .unit-rows-scroll
         handles internal scroll for multi-unit cases. */
      overflow: hidden;
      display: grid;
      grid-template-rows: auto minmax(0, 1fr);
    }

    .times-wrap {
      padding: 0 9px 9px;
      min-height: 0;
      overflow: hidden;
    }

    .times-grid {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      grid-auto-rows: minmax(56px, 1fr);
      gap: 6px;
    }

    .time-box {
      min-height: 0;
      padding: 8px;
      border-radius: 13px;
      overflow: hidden;
    }

    .time-label {
      font-size: 8px;
      letter-spacing: 0.08em;
      margin-bottom: 4px;
      line-height: 1.05;
    }

    .time-value {
      font-size: 12px;
      line-height: 1.05;
      overflow-wrap: anywhere;
      word-break: break-word;
    }
  }

  /* Slightly larger mounted tablets or Safari with the toolbar hidden. */
  @media (pointer: coarse) and (orientation: landscape) and (min-width: 900px) and (max-width: 1200px) and (min-height: 901px) {
    .main {
      grid-template-columns: minmax(0, 1.18fr) minmax(360px, 0.82fr);
    }
    .map-frame-wrap,
    #mapFrame,
    #leafletRouteMap {
      min-height: 430px;
    }
    .staffing-card {
      display: none !important;
    }
  }


  /* Mounted iPad: increase only the visible map area while keeping the current call-times/staffing layout. */
  @media (min-width: 740px) and (max-width: 1180px) and (orientation: landscape) {
    .map-frame-wrap {
      height: 330px !important;
      min-height: 330px !important;
    }

    #mapFrame,
    #leafletRouteMap {
      height: 330px !important;
      min-height: 330px !important;
    }
  }


  /* Desktop board stabilization: keep the live board centered on wide screens
     while leaving mobile/tablet fallbacks intact. iPads should use the native app. */
  @media (min-width: 901px) {
    .board {
      max-width: 1920px;
      margin-left: auto;
      margin-right: auto;
    }
    .main {
      grid-template-columns: minmax(520px, 1.05fr) minmax(430px, 0.95fr);
      align-items: stretch;
    }
    .info-stack,
    .map-panel {
      min-width: 0;
    }
  }
